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 | 68f12ae | 2008-04-26 01:02:30 -0300 | [diff] [blame] | 24 | #define TPACPI_VERSION "0.20" |
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" |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 143 | #define TPACPI_WORKQUEUE_NAME "ktpacpid" |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 144 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 145 | #define TPACPI_MAX_ACPI_ARGS 3 |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 146 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 147 | /* Debugging */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 148 | #define TPACPI_LOG TPACPI_FILE ": " |
| 149 | #define TPACPI_ERR KERN_ERR TPACPI_LOG |
| 150 | #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG |
| 151 | #define TPACPI_INFO KERN_INFO TPACPI_LOG |
| 152 | #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 153 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 154 | #define TPACPI_DBG_ALL 0xffff |
| 155 | #define TPACPI_DBG_ALL 0xffff |
| 156 | #define TPACPI_DBG_INIT 0x0001 |
| 157 | #define TPACPI_DBG_EXIT 0x0002 |
| 158 | #define dbg_printk(a_dbg_level, format, arg...) \ |
| 159 | do { if (dbg_level & a_dbg_level) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 160 | printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \ |
| 161 | } while (0) |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 162 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
| 163 | #define vdbg_printk(a_dbg_level, format, arg...) \ |
| 164 | dbg_printk(a_dbg_level, format, ## arg) |
| 165 | static const char *str_supported(int is_supported); |
| 166 | #else |
| 167 | #define vdbg_printk(a_dbg_level, format, arg...) |
| 168 | #endif |
| 169 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 170 | #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off") |
| 171 | #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") |
| 172 | #define strlencmp(a, b) (strncmp((a), (b), strlen(b))) |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 173 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 174 | |
| 175 | /**************************************************************************** |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 176 | * Driver-wide structs and misc. variables |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 177 | */ |
| 178 | |
| 179 | struct ibm_struct; |
| 180 | |
| 181 | struct tp_acpi_drv_struct { |
| 182 | const struct acpi_device_id *hid; |
| 183 | struct acpi_driver *driver; |
| 184 | |
| 185 | void (*notify) (struct ibm_struct *, u32); |
| 186 | acpi_handle *handle; |
| 187 | u32 type; |
| 188 | struct acpi_device *device; |
| 189 | }; |
| 190 | |
| 191 | struct ibm_struct { |
| 192 | char *name; |
| 193 | |
| 194 | int (*read) (char *); |
| 195 | int (*write) (char *); |
| 196 | void (*exit) (void); |
| 197 | void (*resume) (void); |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 198 | void (*suspend) (pm_message_t state); |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 199 | |
| 200 | struct list_head all_drivers; |
| 201 | |
| 202 | struct tp_acpi_drv_struct *acpi; |
| 203 | |
| 204 | struct { |
| 205 | u8 acpi_driver_registered:1; |
| 206 | u8 acpi_notify_installed:1; |
| 207 | u8 proc_created:1; |
| 208 | u8 init_called:1; |
| 209 | u8 experimental:1; |
| 210 | } flags; |
| 211 | }; |
| 212 | |
| 213 | struct ibm_init_struct { |
| 214 | char param[32]; |
| 215 | |
| 216 | int (*init) (struct ibm_init_struct *); |
| 217 | struct ibm_struct *data; |
| 218 | }; |
| 219 | |
| 220 | static struct { |
| 221 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
| 222 | u32 bay_status:1; |
| 223 | u32 bay_eject:1; |
| 224 | u32 bay_status2:1; |
| 225 | u32 bay_eject2:1; |
| 226 | #endif |
| 227 | u32 bluetooth:1; |
| 228 | u32 hotkey:1; |
| 229 | u32 hotkey_mask:1; |
| 230 | u32 hotkey_wlsw:1; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 231 | u32 hotkey_tablet:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 232 | u32 light:1; |
| 233 | u32 light_status:1; |
| 234 | u32 bright_16levels:1; |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 235 | u32 bright_acpimode:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 236 | u32 wan:1; |
| 237 | u32 fan_ctrl_status_undef:1; |
| 238 | u32 input_device_registered:1; |
| 239 | u32 platform_drv_registered:1; |
| 240 | u32 platform_drv_attrs_registered:1; |
| 241 | u32 sensors_pdrv_registered:1; |
| 242 | u32 sensors_pdrv_attrs_registered:1; |
| 243 | u32 sensors_pdev_attrs_registered:1; |
| 244 | u32 hotkey_poll_active:1; |
| 245 | } tp_features; |
| 246 | |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 247 | static struct { |
| 248 | u16 hotkey_mask_ff:1; |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 249 | u16 bright_cmos_ec_unsync:1; |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 250 | } tp_warned; |
| 251 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 252 | struct thinkpad_id_data { |
| 253 | unsigned int vendor; /* ThinkPad vendor: |
| 254 | * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */ |
| 255 | |
| 256 | char *bios_version_str; /* Something like 1ZET51WW (1.03z) */ |
| 257 | char *ec_version_str; /* Something like 1ZHT51WW-1.04a */ |
| 258 | |
| 259 | u16 bios_model; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */ |
| 260 | u16 ec_model; |
| 261 | |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 262 | char *model_str; /* ThinkPad T43 */ |
| 263 | char *nummodel_str; /* 9384A9C for a 9384-A9C model */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 264 | }; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 265 | static struct thinkpad_id_data thinkpad_id; |
| 266 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 267 | static enum { |
| 268 | TPACPI_LIFE_INIT = 0, |
| 269 | TPACPI_LIFE_RUNNING, |
| 270 | TPACPI_LIFE_EXITING, |
| 271 | } tpacpi_lifecycle; |
| 272 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 273 | static int experimental; |
| 274 | static u32 dbg_level; |
| 275 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 276 | static struct workqueue_struct *tpacpi_wq; |
| 277 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 278 | /* Special LED class that can defer work */ |
| 279 | struct tpacpi_led_classdev { |
| 280 | struct led_classdev led_classdev; |
| 281 | struct work_struct work; |
| 282 | enum led_brightness new_brightness; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 283 | unsigned int led; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 284 | }; |
| 285 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 286 | /**************************************************************************** |
| 287 | **************************************************************************** |
| 288 | * |
| 289 | * ACPI Helpers and device model |
| 290 | * |
| 291 | **************************************************************************** |
| 292 | ****************************************************************************/ |
| 293 | |
| 294 | /************************************************************************* |
| 295 | * ACPI basic handles |
| 296 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 298 | static acpi_handle root_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 300 | #define TPACPI_HANDLE(object, parent, paths...) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | static acpi_handle object##_handle; \ |
| 302 | static acpi_handle *object##_parent = &parent##_handle; \ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 303 | static char *object##_path; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | static char *object##_paths[] = { paths } |
| 305 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 306 | TPACPI_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 307 | "\\_SB.PCI.ISA.EC", /* 570 */ |
| 308 | "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ |
| 309 | "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */ |
| 310 | "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */ |
| 311 | "\\_SB.PCI0.ICH3.EC0", /* R31 */ |
| 312 | "\\_SB.PCI0.LPC.EC", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 313 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 315 | TPACPI_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
| 316 | TPACPI_HANDLE(ecwr, ec, "ECWR"); /* 570 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 318 | TPACPI_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, */ |
| 319 | /* T4x, X31, X40 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 320 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ |
| 321 | "\\CMS", /* R40, R40e */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 322 | ); /* all others */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 323 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 324 | TPACPI_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 325 | "^HKEY", /* R30, R31 */ |
| 326 | "HKEY", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 327 | ); /* 570 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 328 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 329 | TPACPI_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */ |
| 330 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ |
| 331 | "\\_SB.PCI0.VID0", /* 770e */ |
| 332 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ |
| 333 | "\\_SB.PCI0.AGP.VID", /* all others */ |
| 334 | ); /* R30, R31 */ |
| 335 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 336 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 337 | /************************************************************************* |
| 338 | * ACPI helpers |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 339 | */ |
| 340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | static int acpi_evalf(acpi_handle handle, |
| 342 | void *res, char *method, char *fmt, ...) |
| 343 | { |
| 344 | char *fmt0 = fmt; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 345 | struct acpi_object_list params; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 346 | union acpi_object in_objs[TPACPI_MAX_ACPI_ARGS]; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 347 | struct acpi_buffer result, *resultp; |
| 348 | union acpi_object out_obj; |
| 349 | acpi_status status; |
| 350 | va_list ap; |
| 351 | char res_type; |
| 352 | int success; |
| 353 | int quiet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
| 355 | if (!*fmt) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 356 | printk(TPACPI_ERR "acpi_evalf() called with empty format\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | return 0; |
| 358 | } |
| 359 | |
| 360 | if (*fmt == 'q') { |
| 361 | quiet = 1; |
| 362 | fmt++; |
| 363 | } else |
| 364 | quiet = 0; |
| 365 | |
| 366 | res_type = *(fmt++); |
| 367 | |
| 368 | params.count = 0; |
| 369 | params.pointer = &in_objs[0]; |
| 370 | |
| 371 | va_start(ap, fmt); |
| 372 | while (*fmt) { |
| 373 | char c = *(fmt++); |
| 374 | switch (c) { |
| 375 | case 'd': /* int */ |
| 376 | in_objs[params.count].integer.value = va_arg(ap, int); |
| 377 | in_objs[params.count++].type = ACPI_TYPE_INTEGER; |
| 378 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 379 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | default: |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 381 | printk(TPACPI_ERR "acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | "with invalid format character '%c'\n", c); |
| 383 | return 0; |
| 384 | } |
| 385 | } |
| 386 | va_end(ap); |
| 387 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 388 | if (res_type != 'v') { |
| 389 | result.length = sizeof(out_obj); |
| 390 | result.pointer = &out_obj; |
| 391 | resultp = &result; |
| 392 | } else |
| 393 | resultp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 395 | status = acpi_evaluate_object(handle, method, ¶ms, resultp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
| 397 | switch (res_type) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 398 | case 'd': /* int */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | if (res) |
| 400 | *(int *)res = out_obj.integer.value; |
| 401 | success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER; |
| 402 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 403 | case 'v': /* void */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | success = status == AE_OK; |
| 405 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 406 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | default: |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 408 | printk(TPACPI_ERR "acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | "with invalid format character '%c'\n", res_type); |
| 410 | return 0; |
| 411 | } |
| 412 | |
| 413 | if (!success && !quiet) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 414 | printk(TPACPI_ERR "acpi_evalf(%s, %s, ...) failed: %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | method, fmt0, status); |
| 416 | |
| 417 | return success; |
| 418 | } |
| 419 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 420 | static int acpi_ec_read(int i, u8 *p) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 421 | { |
| 422 | int v; |
| 423 | |
| 424 | if (ecrd_handle) { |
| 425 | if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) |
| 426 | return 0; |
| 427 | *p = v; |
| 428 | } else { |
| 429 | if (ec_read(i, p) < 0) |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | return 1; |
| 434 | } |
| 435 | |
| 436 | static int acpi_ec_write(int i, u8 v) |
| 437 | { |
| 438 | if (ecwr_handle) { |
| 439 | if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) |
| 440 | return 0; |
| 441 | } else { |
| 442 | if (ec_write(i, v) < 0) |
| 443 | return 0; |
| 444 | } |
| 445 | |
| 446 | return 1; |
| 447 | } |
| 448 | |
Henrique de Moraes Holschuh | 013c40e | 2008-01-08 13:02:54 -0200 | [diff] [blame] | 449 | #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] | 450 | static int _sta(acpi_handle handle) |
| 451 | { |
| 452 | int status; |
| 453 | |
| 454 | if (!handle || !acpi_evalf(handle, &status, "_STA", "d")) |
| 455 | status = 0; |
| 456 | |
| 457 | return status; |
| 458 | } |
Henrique de Moraes Holschuh | 013c40e | 2008-01-08 13:02:54 -0200 | [diff] [blame] | 459 | #endif |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 460 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 461 | static int issue_thinkpad_cmos_command(int cmos_cmd) |
| 462 | { |
| 463 | if (!cmos_handle) |
| 464 | return -ENXIO; |
| 465 | |
| 466 | if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd)) |
| 467 | return -EIO; |
| 468 | |
| 469 | return 0; |
| 470 | } |
| 471 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 472 | /************************************************************************* |
| 473 | * ACPI device model |
| 474 | */ |
| 475 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 476 | #define TPACPI_ACPIHANDLE_INIT(object) \ |
| 477 | drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 478 | object##_paths, ARRAY_SIZE(object##_paths), &object##_path) |
| 479 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 480 | static void drv_acpi_handle_init(char *name, |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 481 | acpi_handle *handle, acpi_handle parent, |
| 482 | char **paths, int num_paths, char **path) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 483 | { |
| 484 | int i; |
| 485 | acpi_status status; |
| 486 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 487 | vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n", |
| 488 | name); |
| 489 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 490 | for (i = 0; i < num_paths; i++) { |
| 491 | status = acpi_get_handle(parent, paths[i], handle); |
| 492 | if (ACPI_SUCCESS(status)) { |
| 493 | *path = paths[i]; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 494 | dbg_printk(TPACPI_DBG_INIT, |
| 495 | "Found ACPI handle %s for %s\n", |
| 496 | *path, name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 497 | return; |
| 498 | } |
| 499 | } |
| 500 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 501 | vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n", |
| 502 | name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 503 | *handle = NULL; |
| 504 | } |
| 505 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 506 | 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] | 507 | { |
| 508 | struct ibm_struct *ibm = data; |
| 509 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 510 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 511 | return; |
| 512 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 513 | if (!ibm || !ibm->acpi || !ibm->acpi->notify) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 514 | return; |
| 515 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 516 | ibm->acpi->notify(ibm, event); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 517 | } |
| 518 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 519 | static int __init setup_acpi_notify(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 520 | { |
| 521 | acpi_status status; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 522 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 523 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 524 | BUG_ON(!ibm->acpi); |
| 525 | |
| 526 | if (!*ibm->acpi->handle) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 527 | return 0; |
| 528 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 529 | vdbg_printk(TPACPI_DBG_INIT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 530 | "setting up ACPI notify for %s\n", ibm->name); |
| 531 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 532 | rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device); |
| 533 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 534 | 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] | 535 | ibm->name, rc); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 536 | return -ENODEV; |
| 537 | } |
| 538 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 539 | acpi_driver_data(ibm->acpi->device) = ibm; |
| 540 | sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 541 | TPACPI_ACPI_EVENT_PREFIX, |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 542 | ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 543 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 544 | status = acpi_install_notify_handler(*ibm->acpi->handle, |
| 545 | ibm->acpi->type, dispatch_acpi_notify, ibm); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 546 | if (ACPI_FAILURE(status)) { |
| 547 | if (status == AE_ALREADY_EXISTS) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 548 | printk(TPACPI_NOTICE |
| 549 | "another device driver is already " |
| 550 | "handling %s events\n", ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 551 | } else { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 552 | printk(TPACPI_ERR |
| 553 | "acpi_install_notify_handler(%s) failed: %d\n", |
| 554 | ibm->name, status); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 555 | } |
| 556 | return -ENODEV; |
| 557 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 558 | ibm->flags.acpi_notify_installed = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 559 | return 0; |
| 560 | } |
| 561 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 562 | static int __init tpacpi_device_add(struct acpi_device *device) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 563 | { |
| 564 | return 0; |
| 565 | } |
| 566 | |
Henrique de Moraes Holschuh | 6700121 | 2007-04-21 11:08:25 -0300 | [diff] [blame] | 567 | static int __init register_tpacpi_subdriver(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 568 | { |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 569 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 570 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 571 | dbg_printk(TPACPI_DBG_INIT, |
| 572 | "registering %s as an ACPI driver\n", ibm->name); |
| 573 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 574 | BUG_ON(!ibm->acpi); |
| 575 | |
| 576 | ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); |
| 577 | if (!ibm->acpi->driver) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 578 | printk(TPACPI_ERR "kzalloc(ibm->driver) failed\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 579 | return -ENOMEM; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 580 | } |
| 581 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 582 | 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] | 583 | ibm->acpi->driver->ids = ibm->acpi->hid; |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 584 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 585 | ibm->acpi->driver->ops.add = &tpacpi_device_add; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 586 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 587 | rc = acpi_bus_register_driver(ibm->acpi->driver); |
| 588 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 589 | printk(TPACPI_ERR "acpi_bus_register_driver(%s) failed: %d\n", |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 590 | ibm->name, rc); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 591 | kfree(ibm->acpi->driver); |
| 592 | ibm->acpi->driver = NULL; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 593 | } else if (!rc) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 594 | ibm->flags.acpi_driver_registered = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 595 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 596 | return rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | |
| 600 | /**************************************************************************** |
| 601 | **************************************************************************** |
| 602 | * |
| 603 | * Procfs Helpers |
| 604 | * |
| 605 | **************************************************************************** |
| 606 | ****************************************************************************/ |
| 607 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 608 | static int dispatch_procfs_read(char *page, char **start, off_t off, |
| 609 | int count, int *eof, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 610 | { |
| 611 | struct ibm_struct *ibm = data; |
| 612 | int len; |
| 613 | |
| 614 | if (!ibm || !ibm->read) |
| 615 | return -EINVAL; |
| 616 | |
| 617 | len = ibm->read(page); |
| 618 | if (len < 0) |
| 619 | return len; |
| 620 | |
| 621 | if (len <= off + count) |
| 622 | *eof = 1; |
| 623 | *start = page + off; |
| 624 | len -= off; |
| 625 | if (len > count) |
| 626 | len = count; |
| 627 | if (len < 0) |
| 628 | len = 0; |
| 629 | |
| 630 | return len; |
| 631 | } |
| 632 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 633 | static int dispatch_procfs_write(struct file *file, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 634 | const char __user *userbuf, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 635 | unsigned long count, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 636 | { |
| 637 | struct ibm_struct *ibm = data; |
| 638 | char *kernbuf; |
| 639 | int ret; |
| 640 | |
| 641 | if (!ibm || !ibm->write) |
| 642 | return -EINVAL; |
| 643 | |
| 644 | kernbuf = kmalloc(count + 2, GFP_KERNEL); |
| 645 | if (!kernbuf) |
| 646 | return -ENOMEM; |
| 647 | |
| 648 | if (copy_from_user(kernbuf, userbuf, count)) { |
| 649 | kfree(kernbuf); |
| 650 | return -EFAULT; |
| 651 | } |
| 652 | |
| 653 | kernbuf[count] = 0; |
| 654 | strcat(kernbuf, ","); |
| 655 | ret = ibm->write(kernbuf); |
| 656 | if (ret == 0) |
| 657 | ret = count; |
| 658 | |
| 659 | kfree(kernbuf); |
| 660 | |
| 661 | return ret; |
| 662 | } |
| 663 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | static char *next_cmd(char **cmds) |
| 665 | { |
| 666 | char *start = *cmds; |
| 667 | char *end; |
| 668 | |
| 669 | while ((end = strchr(start, ',')) && end == start) |
| 670 | start = end + 1; |
| 671 | |
| 672 | if (!end) |
| 673 | return NULL; |
| 674 | |
| 675 | *end = 0; |
| 676 | *cmds = end + 1; |
| 677 | return start; |
| 678 | } |
| 679 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 680 | |
| 681 | /**************************************************************************** |
| 682 | **************************************************************************** |
| 683 | * |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 684 | * Device model: input, hwmon and platform |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 685 | * |
| 686 | **************************************************************************** |
| 687 | ****************************************************************************/ |
| 688 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 689 | static struct platform_device *tpacpi_pdev; |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 690 | static struct platform_device *tpacpi_sensors_pdev; |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 691 | static struct device *tpacpi_hwmon; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 692 | static struct input_dev *tpacpi_inputdev; |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 693 | static struct mutex tpacpi_inputdev_send_mutex; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 694 | static LIST_HEAD(tpacpi_all_drivers); |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 695 | |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 696 | static int tpacpi_suspend_handler(struct platform_device *pdev, |
| 697 | pm_message_t state) |
| 698 | { |
| 699 | struct ibm_struct *ibm, *itmp; |
| 700 | |
| 701 | list_for_each_entry_safe(ibm, itmp, |
| 702 | &tpacpi_all_drivers, |
| 703 | all_drivers) { |
| 704 | if (ibm->suspend) |
| 705 | (ibm->suspend)(state); |
| 706 | } |
| 707 | |
| 708 | return 0; |
| 709 | } |
| 710 | |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 711 | static int tpacpi_resume_handler(struct platform_device *pdev) |
| 712 | { |
| 713 | struct ibm_struct *ibm, *itmp; |
| 714 | |
| 715 | list_for_each_entry_safe(ibm, itmp, |
| 716 | &tpacpi_all_drivers, |
| 717 | all_drivers) { |
| 718 | if (ibm->resume) |
| 719 | (ibm->resume)(); |
| 720 | } |
| 721 | |
| 722 | return 0; |
| 723 | } |
| 724 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 725 | static struct platform_driver tpacpi_pdriver = { |
| 726 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 727 | .name = TPACPI_DRVR_NAME, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 728 | .owner = THIS_MODULE, |
| 729 | }, |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 730 | .suspend = tpacpi_suspend_handler, |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 731 | .resume = tpacpi_resume_handler, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 732 | }; |
| 733 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 734 | static struct platform_driver tpacpi_hwmon_pdriver = { |
| 735 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 736 | .name = TPACPI_HWMON_DRVR_NAME, |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 737 | .owner = THIS_MODULE, |
| 738 | }, |
| 739 | }; |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 740 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 741 | /************************************************************************* |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 742 | * sysfs support helpers |
| 743 | */ |
| 744 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 745 | struct attribute_set { |
| 746 | unsigned int members, max_members; |
| 747 | struct attribute_group group; |
| 748 | }; |
| 749 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 750 | struct attribute_set_obj { |
| 751 | struct attribute_set s; |
| 752 | struct attribute *a; |
| 753 | } __attribute__((packed)); |
| 754 | |
| 755 | 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] | 756 | const char *name) |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 757 | { |
| 758 | struct attribute_set_obj *sobj; |
| 759 | |
| 760 | if (max_members == 0) |
| 761 | return NULL; |
| 762 | |
| 763 | /* Allocates space for implicit NULL at the end too */ |
| 764 | sobj = kzalloc(sizeof(struct attribute_set_obj) + |
| 765 | max_members * sizeof(struct attribute *), |
| 766 | GFP_KERNEL); |
| 767 | if (!sobj) |
| 768 | return NULL; |
| 769 | sobj->s.max_members = max_members; |
| 770 | sobj->s.group.attrs = &sobj->a; |
| 771 | sobj->s.group.name = name; |
| 772 | |
| 773 | return &sobj->s; |
| 774 | } |
| 775 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 776 | #define destroy_attr_set(_set) \ |
| 777 | kfree(_set); |
| 778 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 779 | /* 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] | 780 | 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] | 781 | { |
| 782 | if (!s || !attr) |
| 783 | return -EINVAL; |
| 784 | |
| 785 | if (s->members >= s->max_members) |
| 786 | return -ENOMEM; |
| 787 | |
| 788 | s->group.attrs[s->members] = attr; |
| 789 | s->members++; |
| 790 | |
| 791 | return 0; |
| 792 | } |
| 793 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 794 | 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] | 795 | struct attribute **attr, |
| 796 | unsigned int count) |
| 797 | { |
| 798 | int i, res; |
| 799 | |
| 800 | for (i = 0; i < count; i++) { |
| 801 | res = add_to_attr_set(s, attr[i]); |
| 802 | if (res) |
| 803 | return res; |
| 804 | } |
| 805 | |
| 806 | return 0; |
| 807 | } |
| 808 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 809 | 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] | 810 | { |
| 811 | sysfs_remove_group(kobj, &s->group); |
| 812 | destroy_attr_set(s); |
| 813 | } |
| 814 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 815 | #define register_attr_set_with_sysfs(_attr_set, _kobj) \ |
| 816 | sysfs_create_group(_kobj, &_attr_set->group) |
| 817 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 818 | static int parse_strtoul(const char *buf, |
| 819 | unsigned long max, unsigned long *value) |
| 820 | { |
| 821 | char *endp; |
| 822 | |
Henrique de Moraes Holschuh | 32afbf0 | 2007-10-08 10:12:56 -0300 | [diff] [blame] | 823 | while (*buf && isspace(*buf)) |
| 824 | buf++; |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 825 | *value = simple_strtoul(buf, &endp, 0); |
| 826 | while (*endp && isspace(*endp)) |
| 827 | endp++; |
| 828 | if (*endp || *value > max) |
| 829 | return -EINVAL; |
| 830 | |
| 831 | return 0; |
| 832 | } |
| 833 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 834 | static int __init tpacpi_query_bcl_levels(acpi_handle handle) |
| 835 | { |
| 836 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 837 | union acpi_object *obj; |
| 838 | int rc; |
| 839 | |
| 840 | if (ACPI_SUCCESS(acpi_evaluate_object(handle, NULL, NULL, &buffer))) { |
| 841 | obj = (union acpi_object *)buffer.pointer; |
| 842 | if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { |
| 843 | printk(TPACPI_ERR "Unknown _BCL data, " |
| 844 | "please report this to %s\n", TPACPI_MAIL); |
| 845 | rc = 0; |
| 846 | } else { |
| 847 | rc = obj->package.count; |
| 848 | } |
| 849 | } else { |
| 850 | return 0; |
| 851 | } |
| 852 | |
| 853 | kfree(buffer.pointer); |
| 854 | return rc; |
| 855 | } |
| 856 | |
| 857 | static acpi_status __init tpacpi_acpi_walk_find_bcl(acpi_handle handle, |
| 858 | u32 lvl, void *context, void **rv) |
| 859 | { |
| 860 | char name[ACPI_PATH_SEGMENT_LENGTH]; |
| 861 | struct acpi_buffer buffer = { sizeof(name), &name }; |
| 862 | |
| 863 | if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer)) && |
| 864 | !strncmp("_BCL", name, sizeof(name) - 1)) { |
| 865 | BUG_ON(!rv || !*rv); |
| 866 | **(int **)rv = tpacpi_query_bcl_levels(handle); |
| 867 | return AE_CTRL_TERMINATE; |
| 868 | } else { |
| 869 | return AE_OK; |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | /* |
| 874 | * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map |
| 875 | */ |
| 876 | static int __init tpacpi_check_std_acpi_brightness_support(void) |
| 877 | { |
| 878 | int status; |
| 879 | int bcl_levels = 0; |
| 880 | void *bcl_ptr = &bcl_levels; |
| 881 | |
| 882 | if (!vid_handle) { |
| 883 | TPACPI_ACPIHANDLE_INIT(vid); |
| 884 | } |
| 885 | if (!vid_handle) |
| 886 | return 0; |
| 887 | |
| 888 | /* |
| 889 | * Search for a _BCL method, and execute it. This is safe on all |
| 890 | * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista |
| 891 | * BIOS in ACPI backlight control mode. We do NOT have to care |
| 892 | * about calling the _BCL method in an enabled video device, any |
| 893 | * will do for our purposes. |
| 894 | */ |
| 895 | |
| 896 | status = acpi_walk_namespace(ACPI_TYPE_METHOD, vid_handle, 3, |
| 897 | tpacpi_acpi_walk_find_bcl, NULL, |
| 898 | &bcl_ptr); |
| 899 | |
| 900 | if (ACPI_SUCCESS(status) && bcl_levels > 2) { |
| 901 | tp_features.bright_acpimode = 1; |
| 902 | return (bcl_levels - 2); |
| 903 | } |
| 904 | |
| 905 | return 0; |
| 906 | } |
| 907 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 908 | /************************************************************************* |
| 909 | * thinkpad-acpi driver attributes |
| 910 | */ |
| 911 | |
| 912 | /* interface_version --------------------------------------------------- */ |
| 913 | static ssize_t tpacpi_driver_interface_version_show( |
| 914 | struct device_driver *drv, |
| 915 | char *buf) |
| 916 | { |
| 917 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION); |
| 918 | } |
| 919 | |
| 920 | static DRIVER_ATTR(interface_version, S_IRUGO, |
| 921 | tpacpi_driver_interface_version_show, NULL); |
| 922 | |
| 923 | /* debug_level --------------------------------------------------------- */ |
| 924 | static ssize_t tpacpi_driver_debug_show(struct device_driver *drv, |
| 925 | char *buf) |
| 926 | { |
| 927 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level); |
| 928 | } |
| 929 | |
| 930 | static ssize_t tpacpi_driver_debug_store(struct device_driver *drv, |
| 931 | const char *buf, size_t count) |
| 932 | { |
| 933 | unsigned long t; |
| 934 | |
| 935 | if (parse_strtoul(buf, 0xffff, &t)) |
| 936 | return -EINVAL; |
| 937 | |
| 938 | dbg_level = t; |
| 939 | |
| 940 | return count; |
| 941 | } |
| 942 | |
| 943 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 944 | tpacpi_driver_debug_show, tpacpi_driver_debug_store); |
| 945 | |
| 946 | /* version ------------------------------------------------------------- */ |
| 947 | static ssize_t tpacpi_driver_version_show(struct device_driver *drv, |
| 948 | char *buf) |
| 949 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 950 | return snprintf(buf, PAGE_SIZE, "%s v%s\n", |
| 951 | TPACPI_DESC, TPACPI_VERSION); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | static DRIVER_ATTR(version, S_IRUGO, |
| 955 | tpacpi_driver_version_show, NULL); |
| 956 | |
| 957 | /* --------------------------------------------------------------------- */ |
| 958 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 959 | static struct driver_attribute *tpacpi_driver_attributes[] = { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 960 | &driver_attr_debug_level, &driver_attr_version, |
| 961 | &driver_attr_interface_version, |
| 962 | }; |
| 963 | |
| 964 | static int __init tpacpi_create_driver_attributes(struct device_driver *drv) |
| 965 | { |
| 966 | int i, res; |
| 967 | |
| 968 | i = 0; |
| 969 | res = 0; |
| 970 | while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) { |
| 971 | res = driver_create_file(drv, tpacpi_driver_attributes[i]); |
| 972 | i++; |
| 973 | } |
| 974 | |
| 975 | return res; |
| 976 | } |
| 977 | |
| 978 | static void tpacpi_remove_driver_attributes(struct device_driver *drv) |
| 979 | { |
| 980 | int i; |
| 981 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 982 | for (i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 983 | driver_remove_file(drv, tpacpi_driver_attributes[i]); |
| 984 | } |
| 985 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 986 | /**************************************************************************** |
| 987 | **************************************************************************** |
| 988 | * |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 989 | * Subdrivers |
| 990 | * |
| 991 | **************************************************************************** |
| 992 | ****************************************************************************/ |
| 993 | |
| 994 | /************************************************************************* |
Henrique de Moraes Holschuh | 142cfc9 | 2007-04-21 11:08:26 -0300 | [diff] [blame] | 995 | * thinkpad-acpi init subdriver |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 996 | */ |
| 997 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 998 | static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm) |
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 "%s v%s\n", TPACPI_DESC, TPACPI_VERSION); |
| 1001 | printk(TPACPI_INFO "%s\n", TPACPI_URL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1003 | printk(TPACPI_INFO "ThinkPad BIOS %s, EC %s\n", |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 1004 | (thinkpad_id.bios_version_str) ? |
| 1005 | thinkpad_id.bios_version_str : "unknown", |
| 1006 | (thinkpad_id.ec_version_str) ? |
| 1007 | thinkpad_id.ec_version_str : "unknown"); |
| 1008 | |
| 1009 | if (thinkpad_id.vendor && thinkpad_id.model_str) |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 1010 | printk(TPACPI_INFO "%s %s, model %s\n", |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 1011 | (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? |
| 1012 | "IBM" : ((thinkpad_id.vendor == |
| 1013 | PCI_VENDOR_ID_LENOVO) ? |
| 1014 | "Lenovo" : "Unknown vendor"), |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 1015 | thinkpad_id.model_str, |
| 1016 | (thinkpad_id.nummodel_str) ? |
| 1017 | thinkpad_id.nummodel_str : "unknown"); |
Henrique de Moraes Holschuh | 3945ac3 | 2007-02-06 19:13:44 -0200 | [diff] [blame] | 1018 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | return 0; |
| 1020 | } |
| 1021 | |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 1022 | static int thinkpad_acpi_driver_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | { |
| 1024 | int len = 0; |
| 1025 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1026 | len += sprintf(p + len, "driver:\t\t%s\n", TPACPI_DESC); |
| 1027 | len += sprintf(p + len, "version:\t%s\n", TPACPI_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | |
| 1029 | return len; |
| 1030 | } |
| 1031 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1032 | static struct ibm_struct thinkpad_acpi_driver_data = { |
| 1033 | .name = "driver", |
| 1034 | .read = thinkpad_acpi_driver_read, |
| 1035 | }; |
| 1036 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1037 | /************************************************************************* |
| 1038 | * Hotkey subdriver |
| 1039 | */ |
| 1040 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1041 | enum { /* hot key scan codes (derived from ACPI DSDT) */ |
| 1042 | TP_ACPI_HOTKEYSCAN_FNF1 = 0, |
| 1043 | TP_ACPI_HOTKEYSCAN_FNF2, |
| 1044 | TP_ACPI_HOTKEYSCAN_FNF3, |
| 1045 | TP_ACPI_HOTKEYSCAN_FNF4, |
| 1046 | TP_ACPI_HOTKEYSCAN_FNF5, |
| 1047 | TP_ACPI_HOTKEYSCAN_FNF6, |
| 1048 | TP_ACPI_HOTKEYSCAN_FNF7, |
| 1049 | TP_ACPI_HOTKEYSCAN_FNF8, |
| 1050 | TP_ACPI_HOTKEYSCAN_FNF9, |
| 1051 | TP_ACPI_HOTKEYSCAN_FNF10, |
| 1052 | TP_ACPI_HOTKEYSCAN_FNF11, |
| 1053 | TP_ACPI_HOTKEYSCAN_FNF12, |
| 1054 | TP_ACPI_HOTKEYSCAN_FNBACKSPACE, |
| 1055 | TP_ACPI_HOTKEYSCAN_FNINSERT, |
| 1056 | TP_ACPI_HOTKEYSCAN_FNDELETE, |
| 1057 | TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1058 | TP_ACPI_HOTKEYSCAN_FNEND, |
| 1059 | TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1060 | TP_ACPI_HOTKEYSCAN_FNPAGEDOWN, |
| 1061 | TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1062 | TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1063 | TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1064 | TP_ACPI_HOTKEYSCAN_MUTE, |
| 1065 | TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1066 | }; |
| 1067 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1068 | enum { /* Keys available through NVRAM polling */ |
| 1069 | TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U, |
| 1070 | TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U, |
| 1071 | }; |
| 1072 | |
| 1073 | enum { /* Positions of some of the keys in hotkey masks */ |
| 1074 | TP_ACPI_HKEY_DISPSWTCH_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF7, |
| 1075 | TP_ACPI_HKEY_DISPXPAND_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF8, |
| 1076 | TP_ACPI_HKEY_HIBERNATE_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF12, |
| 1077 | TP_ACPI_HKEY_BRGHTUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1078 | TP_ACPI_HKEY_BRGHTDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNEND, |
| 1079 | TP_ACPI_HKEY_THNKLGHT_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1080 | TP_ACPI_HKEY_ZOOM_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1081 | TP_ACPI_HKEY_VOLUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1082 | TP_ACPI_HKEY_VOLDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1083 | TP_ACPI_HKEY_MUTE_MASK = 1 << TP_ACPI_HOTKEYSCAN_MUTE, |
| 1084 | TP_ACPI_HKEY_THINKPAD_MASK = 1 << TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1085 | }; |
| 1086 | |
| 1087 | enum { /* NVRAM to ACPI HKEY group map */ |
| 1088 | TP_NVRAM_HKEY_GROUP_HK2 = TP_ACPI_HKEY_THINKPAD_MASK | |
| 1089 | TP_ACPI_HKEY_ZOOM_MASK | |
| 1090 | TP_ACPI_HKEY_DISPSWTCH_MASK | |
| 1091 | TP_ACPI_HKEY_HIBERNATE_MASK, |
| 1092 | TP_NVRAM_HKEY_GROUP_BRIGHTNESS = TP_ACPI_HKEY_BRGHTUP_MASK | |
| 1093 | TP_ACPI_HKEY_BRGHTDWN_MASK, |
| 1094 | TP_NVRAM_HKEY_GROUP_VOLUME = TP_ACPI_HKEY_VOLUP_MASK | |
| 1095 | TP_ACPI_HKEY_VOLDWN_MASK | |
| 1096 | TP_ACPI_HKEY_MUTE_MASK, |
| 1097 | }; |
| 1098 | |
| 1099 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1100 | struct tp_nvram_state { |
| 1101 | u16 thinkpad_toggle:1; |
| 1102 | u16 zoom_toggle:1; |
| 1103 | u16 display_toggle:1; |
| 1104 | u16 thinklight_toggle:1; |
| 1105 | u16 hibernate_toggle:1; |
| 1106 | u16 displayexp_toggle:1; |
| 1107 | u16 display_state:1; |
| 1108 | u16 brightness_toggle:1; |
| 1109 | u16 volume_toggle:1; |
| 1110 | u16 mute:1; |
| 1111 | |
| 1112 | u8 brightness_level; |
| 1113 | u8 volume_level; |
| 1114 | }; |
| 1115 | |
| 1116 | static struct task_struct *tpacpi_hotkey_task; |
| 1117 | static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */ |
| 1118 | static int hotkey_poll_freq = 10; /* Hz */ |
| 1119 | static struct mutex hotkey_thread_mutex; |
| 1120 | static struct mutex hotkey_thread_data_mutex; |
| 1121 | static unsigned int hotkey_config_change; |
| 1122 | |
| 1123 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1124 | |
| 1125 | #define hotkey_source_mask 0U |
| 1126 | |
| 1127 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1128 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1129 | static struct mutex hotkey_mutex; |
| 1130 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 1131 | static enum { /* Reasons for waking up */ |
| 1132 | TP_ACPI_WAKEUP_NONE = 0, /* None or unknown */ |
| 1133 | TP_ACPI_WAKEUP_BAYEJ, /* Bay ejection request */ |
| 1134 | TP_ACPI_WAKEUP_UNDOCK, /* Undock request */ |
| 1135 | } hotkey_wakeup_reason; |
| 1136 | |
| 1137 | static int hotkey_autosleep_ack; |
| 1138 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1139 | static int hotkey_orig_status; |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1140 | static u32 hotkey_orig_mask; |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1141 | static u32 hotkey_all_mask; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 1142 | static u32 hotkey_reserved_mask; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1143 | static u32 hotkey_mask; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 1144 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1145 | static unsigned int hotkey_report_mode; |
| 1146 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1147 | static u16 *hotkey_keycode_map; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1148 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 1149 | static struct attribute_set *hotkey_dev_attributes; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1150 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1151 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1152 | #define HOTKEY_CONFIG_CRITICAL_START \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1153 | do { \ |
| 1154 | mutex_lock(&hotkey_thread_data_mutex); \ |
| 1155 | hotkey_config_change++; \ |
| 1156 | } while (0); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1157 | #define HOTKEY_CONFIG_CRITICAL_END \ |
| 1158 | mutex_unlock(&hotkey_thread_data_mutex); |
| 1159 | #else |
| 1160 | #define HOTKEY_CONFIG_CRITICAL_START |
| 1161 | #define HOTKEY_CONFIG_CRITICAL_END |
| 1162 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1163 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1164 | /* HKEY.MHKG() return bits */ |
| 1165 | #define TP_HOTKEY_TABLET_MASK (1 << 3) |
| 1166 | |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 1167 | static int hotkey_get_wlsw(int *status) |
| 1168 | { |
| 1169 | if (!acpi_evalf(hkey_handle, status, "WLSW", "d")) |
| 1170 | return -EIO; |
| 1171 | return 0; |
| 1172 | } |
| 1173 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1174 | static int hotkey_get_tablet_mode(int *status) |
| 1175 | { |
| 1176 | int s; |
| 1177 | |
| 1178 | if (!acpi_evalf(hkey_handle, &s, "MHKG", "d")) |
| 1179 | return -EIO; |
| 1180 | |
Henrique de Moraes Holschuh | cee47f5 | 2008-03-04 14:29:21 -0800 | [diff] [blame] | 1181 | *status = ((s & TP_HOTKEY_TABLET_MASK) != 0); |
| 1182 | return 0; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1183 | } |
| 1184 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1185 | /* |
| 1186 | * Call with hotkey_mutex held |
| 1187 | */ |
| 1188 | static int hotkey_mask_get(void) |
| 1189 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1190 | u32 m = 0; |
| 1191 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1192 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1193 | if (!acpi_evalf(hkey_handle, &m, "DHKN", "d")) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1194 | return -EIO; |
| 1195 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1196 | hotkey_mask = m | (hotkey_source_mask & hotkey_mask); |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1197 | |
| 1198 | return 0; |
| 1199 | } |
| 1200 | |
| 1201 | /* |
| 1202 | * Call with hotkey_mutex held |
| 1203 | */ |
| 1204 | static int hotkey_mask_set(u32 mask) |
| 1205 | { |
| 1206 | int i; |
| 1207 | int rc = 0; |
| 1208 | |
| 1209 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 1210 | if (!tp_warned.hotkey_mask_ff && |
| 1211 | (mask == 0xffff || mask == 0xffffff || |
| 1212 | mask == 0xffffffff)) { |
| 1213 | tp_warned.hotkey_mask_ff = 1; |
| 1214 | printk(TPACPI_NOTICE |
| 1215 | "setting the hotkey mask to 0x%08x is likely " |
| 1216 | "not the best way to go about it\n", mask); |
| 1217 | printk(TPACPI_NOTICE |
| 1218 | "please consider using the driver defaults, " |
| 1219 | "and refer to up-to-date thinkpad-acpi " |
| 1220 | "documentation\n"); |
| 1221 | } |
| 1222 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1223 | HOTKEY_CONFIG_CRITICAL_START |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1224 | for (i = 0; i < 32; i++) { |
| 1225 | u32 m = 1 << i; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1226 | /* enable in firmware mask only keys not in NVRAM |
| 1227 | * mode, but enable the key in the cached hotkey_mask |
| 1228 | * regardless of mode, or the key will end up |
| 1229 | * disabled by hotkey_mask_get() */ |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1230 | if (!acpi_evalf(hkey_handle, |
| 1231 | NULL, "MHKM", "vdd", i + 1, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1232 | !!((mask & ~hotkey_source_mask) & m))) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1233 | rc = -EIO; |
| 1234 | break; |
| 1235 | } else { |
| 1236 | hotkey_mask = (hotkey_mask & ~m) | (mask & m); |
| 1237 | } |
| 1238 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1239 | HOTKEY_CONFIG_CRITICAL_END |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1240 | |
| 1241 | /* hotkey_mask_get must be called unconditionally below */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1242 | if (!hotkey_mask_get() && !rc && |
| 1243 | (hotkey_mask & ~hotkey_source_mask) != |
| 1244 | (mask & ~hotkey_source_mask)) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1245 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1246 | "requested hot key mask 0x%08x, but " |
| 1247 | "firmware forced it to 0x%08x\n", |
| 1248 | mask, hotkey_mask); |
| 1249 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1250 | } else { |
| 1251 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1252 | HOTKEY_CONFIG_CRITICAL_START |
| 1253 | hotkey_mask = mask & hotkey_source_mask; |
| 1254 | HOTKEY_CONFIG_CRITICAL_END |
| 1255 | hotkey_mask_get(); |
| 1256 | if (hotkey_mask != mask) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1257 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1258 | "requested hot key mask 0x%08x, " |
| 1259 | "forced to 0x%08x (NVRAM poll mask is " |
| 1260 | "0x%08x): no firmware mask support\n", |
| 1261 | mask, hotkey_mask, hotkey_source_mask); |
| 1262 | } |
| 1263 | #else |
| 1264 | hotkey_mask_get(); |
| 1265 | rc = -ENXIO; |
| 1266 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | return rc; |
| 1270 | } |
| 1271 | |
| 1272 | static int hotkey_status_get(int *status) |
| 1273 | { |
| 1274 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) |
| 1275 | return -EIO; |
| 1276 | |
| 1277 | return 0; |
| 1278 | } |
| 1279 | |
| 1280 | static int hotkey_status_set(int status) |
| 1281 | { |
| 1282 | if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status)) |
| 1283 | return -EIO; |
| 1284 | |
| 1285 | return 0; |
| 1286 | } |
| 1287 | |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1288 | static void tpacpi_input_send_radiosw(void) |
| 1289 | { |
| 1290 | int wlsw; |
| 1291 | |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1292 | if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&wlsw)) { |
Henrique de Moraes Holschuh | d147da7 | 2008-02-16 02:17:57 -0200 | [diff] [blame] | 1293 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 1294 | |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1295 | input_report_switch(tpacpi_inputdev, |
Henrique de Moraes Holschuh | 197a2cd | 2008-06-03 23:36:09 -0300 | [diff] [blame] | 1296 | SW_RFKILL_ALL, !!wlsw); |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1297 | input_sync(tpacpi_inputdev); |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1298 | |
Henrique de Moraes Holschuh | d147da7 | 2008-02-16 02:17:57 -0200 | [diff] [blame] | 1299 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 1300 | } |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1301 | } |
| 1302 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1303 | static void tpacpi_input_send_tabletsw(void) |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1304 | { |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1305 | int state; |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1306 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1307 | if (tp_features.hotkey_tablet && |
| 1308 | !hotkey_get_tablet_mode(&state)) { |
| 1309 | mutex_lock(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1310 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1311 | input_report_switch(tpacpi_inputdev, |
| 1312 | SW_TABLET_MODE, !!state); |
| 1313 | input_sync(tpacpi_inputdev); |
| 1314 | |
| 1315 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 1316 | } |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1317 | } |
| 1318 | |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1319 | static void tpacpi_input_send_key(unsigned int scancode) |
| 1320 | { |
| 1321 | unsigned int keycode; |
| 1322 | |
| 1323 | keycode = hotkey_keycode_map[scancode]; |
| 1324 | |
| 1325 | if (keycode != KEY_RESERVED) { |
| 1326 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 1327 | |
| 1328 | input_report_key(tpacpi_inputdev, keycode, 1); |
| 1329 | if (keycode == KEY_UNKNOWN) |
| 1330 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 1331 | scancode); |
| 1332 | input_sync(tpacpi_inputdev); |
| 1333 | |
| 1334 | input_report_key(tpacpi_inputdev, keycode, 0); |
| 1335 | if (keycode == KEY_UNKNOWN) |
| 1336 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 1337 | scancode); |
| 1338 | input_sync(tpacpi_inputdev); |
| 1339 | |
| 1340 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 1341 | } |
| 1342 | } |
| 1343 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1344 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1345 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver; |
| 1346 | |
| 1347 | static void tpacpi_hotkey_send_key(unsigned int scancode) |
| 1348 | { |
| 1349 | tpacpi_input_send_key(scancode); |
| 1350 | if (hotkey_report_mode < 2) { |
| 1351 | acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device, |
| 1352 | 0x80, 0x1001 + scancode); |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | static void hotkey_read_nvram(struct tp_nvram_state *n, u32 m) |
| 1357 | { |
| 1358 | u8 d; |
| 1359 | |
| 1360 | if (m & TP_NVRAM_HKEY_GROUP_HK2) { |
| 1361 | d = nvram_read_byte(TP_NVRAM_ADDR_HK2); |
| 1362 | n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD); |
| 1363 | n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM); |
| 1364 | n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY); |
| 1365 | n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE); |
| 1366 | } |
| 1367 | if (m & TP_ACPI_HKEY_THNKLGHT_MASK) { |
| 1368 | d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT); |
| 1369 | n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT); |
| 1370 | } |
| 1371 | if (m & TP_ACPI_HKEY_DISPXPAND_MASK) { |
| 1372 | d = nvram_read_byte(TP_NVRAM_ADDR_VIDEO); |
| 1373 | n->displayexp_toggle = |
| 1374 | !!(d & TP_NVRAM_MASK_HKT_DISPEXPND); |
| 1375 | } |
| 1376 | if (m & TP_NVRAM_HKEY_GROUP_BRIGHTNESS) { |
| 1377 | d = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 1378 | n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 1379 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 1380 | n->brightness_toggle = |
| 1381 | !!(d & TP_NVRAM_MASK_HKT_BRIGHTNESS); |
| 1382 | } |
| 1383 | if (m & TP_NVRAM_HKEY_GROUP_VOLUME) { |
| 1384 | d = nvram_read_byte(TP_NVRAM_ADDR_MIXER); |
| 1385 | n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME) |
| 1386 | >> TP_NVRAM_POS_LEVEL_VOLUME; |
| 1387 | n->mute = !!(d & TP_NVRAM_MASK_MUTE); |
| 1388 | n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME); |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | #define TPACPI_COMPARE_KEY(__scancode, __member) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1393 | do { \ |
| 1394 | if ((mask & (1 << __scancode)) && \ |
| 1395 | oldn->__member != newn->__member) \ |
| 1396 | tpacpi_hotkey_send_key(__scancode); \ |
| 1397 | } while (0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1398 | |
| 1399 | #define TPACPI_MAY_SEND_KEY(__scancode) \ |
| 1400 | do { if (mask & (1 << __scancode)) \ |
| 1401 | tpacpi_hotkey_send_key(__scancode); } while (0) |
| 1402 | |
| 1403 | 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] | 1404 | struct tp_nvram_state *newn, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1405 | u32 mask) |
| 1406 | { |
| 1407 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle); |
| 1408 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle); |
| 1409 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle); |
| 1410 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12, hibernate_toggle); |
| 1411 | |
| 1412 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP, thinklight_toggle); |
| 1413 | |
| 1414 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle); |
| 1415 | |
| 1416 | /* handle volume */ |
| 1417 | if (oldn->volume_toggle != newn->volume_toggle) { |
| 1418 | if (oldn->mute != newn->mute) { |
| 1419 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 1420 | } |
| 1421 | if (oldn->volume_level > newn->volume_level) { |
| 1422 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 1423 | } else if (oldn->volume_level < newn->volume_level) { |
| 1424 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 1425 | } else if (oldn->mute == newn->mute) { |
| 1426 | /* repeated key presses that didn't change state */ |
| 1427 | if (newn->mute) { |
| 1428 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 1429 | } else if (newn->volume_level != 0) { |
| 1430 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 1431 | } else { |
| 1432 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 1433 | } |
| 1434 | } |
| 1435 | } |
| 1436 | |
| 1437 | /* handle brightness */ |
| 1438 | if (oldn->brightness_toggle != newn->brightness_toggle) { |
| 1439 | if (oldn->brightness_level < newn->brightness_level) { |
| 1440 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 1441 | } else if (oldn->brightness_level > newn->brightness_level) { |
| 1442 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 1443 | } else { |
| 1444 | /* repeated key presses that didn't change state */ |
| 1445 | if (newn->brightness_level != 0) { |
| 1446 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 1447 | } else { |
| 1448 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 1449 | } |
| 1450 | } |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | #undef TPACPI_COMPARE_KEY |
| 1455 | #undef TPACPI_MAY_SEND_KEY |
| 1456 | |
| 1457 | static int hotkey_kthread(void *data) |
| 1458 | { |
| 1459 | struct tp_nvram_state s[2]; |
| 1460 | u32 mask; |
| 1461 | unsigned int si, so; |
| 1462 | unsigned long t; |
| 1463 | unsigned int change_detector, must_reset; |
| 1464 | |
| 1465 | mutex_lock(&hotkey_thread_mutex); |
| 1466 | |
| 1467 | if (tpacpi_lifecycle == TPACPI_LIFE_EXITING) |
| 1468 | goto exit; |
| 1469 | |
| 1470 | set_freezable(); |
| 1471 | |
| 1472 | so = 0; |
| 1473 | si = 1; |
| 1474 | t = 0; |
| 1475 | |
| 1476 | /* Initial state for compares */ |
| 1477 | mutex_lock(&hotkey_thread_data_mutex); |
| 1478 | change_detector = hotkey_config_change; |
| 1479 | mask = hotkey_source_mask & hotkey_mask; |
| 1480 | mutex_unlock(&hotkey_thread_data_mutex); |
| 1481 | hotkey_read_nvram(&s[so], mask); |
| 1482 | |
| 1483 | while (!kthread_should_stop() && hotkey_poll_freq) { |
| 1484 | if (t == 0) |
| 1485 | t = 1000/hotkey_poll_freq; |
| 1486 | t = msleep_interruptible(t); |
| 1487 | if (unlikely(kthread_should_stop())) |
| 1488 | break; |
| 1489 | must_reset = try_to_freeze(); |
| 1490 | if (t > 0 && !must_reset) |
| 1491 | continue; |
| 1492 | |
| 1493 | mutex_lock(&hotkey_thread_data_mutex); |
| 1494 | if (must_reset || hotkey_config_change != change_detector) { |
| 1495 | /* forget old state on thaw or config change */ |
| 1496 | si = so; |
| 1497 | t = 0; |
| 1498 | change_detector = hotkey_config_change; |
| 1499 | } |
| 1500 | mask = hotkey_source_mask & hotkey_mask; |
| 1501 | mutex_unlock(&hotkey_thread_data_mutex); |
| 1502 | |
| 1503 | if (likely(mask)) { |
| 1504 | hotkey_read_nvram(&s[si], mask); |
| 1505 | if (likely(si != so)) { |
| 1506 | hotkey_compare_and_issue_event(&s[so], &s[si], |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1507 | mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | so = si; |
| 1512 | si ^= 1; |
| 1513 | } |
| 1514 | |
| 1515 | exit: |
| 1516 | mutex_unlock(&hotkey_thread_mutex); |
| 1517 | return 0; |
| 1518 | } |
| 1519 | |
| 1520 | static void hotkey_poll_stop_sync(void) |
| 1521 | { |
| 1522 | if (tpacpi_hotkey_task) { |
| 1523 | if (frozen(tpacpi_hotkey_task) || |
| 1524 | freezing(tpacpi_hotkey_task)) |
| 1525 | thaw_process(tpacpi_hotkey_task); |
| 1526 | |
| 1527 | kthread_stop(tpacpi_hotkey_task); |
| 1528 | tpacpi_hotkey_task = NULL; |
| 1529 | mutex_lock(&hotkey_thread_mutex); |
| 1530 | /* at this point, the thread did exit */ |
| 1531 | mutex_unlock(&hotkey_thread_mutex); |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | /* call with hotkey_mutex held */ |
| 1536 | static void hotkey_poll_setup(int may_warn) |
| 1537 | { |
| 1538 | if ((hotkey_source_mask & hotkey_mask) != 0 && |
| 1539 | hotkey_poll_freq > 0 && |
| 1540 | (tpacpi_inputdev->users > 0 || hotkey_report_mode < 2)) { |
| 1541 | if (!tpacpi_hotkey_task) { |
| 1542 | tpacpi_hotkey_task = kthread_run(hotkey_kthread, |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 1543 | NULL, TPACPI_NVRAM_KTHREAD_NAME); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1544 | if (IS_ERR(tpacpi_hotkey_task)) { |
| 1545 | tpacpi_hotkey_task = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1546 | printk(TPACPI_ERR |
| 1547 | "could not create kernel thread " |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1548 | "for hotkey polling\n"); |
| 1549 | } |
| 1550 | } |
| 1551 | } else { |
| 1552 | hotkey_poll_stop_sync(); |
| 1553 | if (may_warn && |
| 1554 | hotkey_source_mask != 0 && hotkey_poll_freq == 0) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1555 | printk(TPACPI_NOTICE |
| 1556 | "hot keys 0x%08x require polling, " |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1557 | "which is currently disabled\n", |
| 1558 | hotkey_source_mask); |
| 1559 | } |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | static void hotkey_poll_setup_safe(int may_warn) |
| 1564 | { |
| 1565 | mutex_lock(&hotkey_mutex); |
| 1566 | hotkey_poll_setup(may_warn); |
| 1567 | mutex_unlock(&hotkey_mutex); |
| 1568 | } |
| 1569 | |
Henrique de Moraes Holschuh | 1bc6b9c | 2008-02-16 02:17:52 -0200 | [diff] [blame] | 1570 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1571 | |
| 1572 | static void hotkey_poll_setup_safe(int __unused) |
| 1573 | { |
| 1574 | } |
| 1575 | |
| 1576 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1577 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1578 | static int hotkey_inputdev_open(struct input_dev *dev) |
| 1579 | { |
| 1580 | switch (tpacpi_lifecycle) { |
| 1581 | case TPACPI_LIFE_INIT: |
| 1582 | /* |
| 1583 | * hotkey_init will call hotkey_poll_setup_safe |
| 1584 | * at the appropriate moment |
| 1585 | */ |
| 1586 | return 0; |
| 1587 | case TPACPI_LIFE_EXITING: |
| 1588 | return -EBUSY; |
| 1589 | case TPACPI_LIFE_RUNNING: |
| 1590 | hotkey_poll_setup_safe(0); |
| 1591 | return 0; |
| 1592 | } |
| 1593 | |
| 1594 | /* Should only happen if tpacpi_lifecycle is corrupt */ |
| 1595 | BUG(); |
| 1596 | return -EBUSY; |
| 1597 | } |
| 1598 | |
| 1599 | static void hotkey_inputdev_close(struct input_dev *dev) |
| 1600 | { |
| 1601 | /* disable hotkey polling when possible */ |
| 1602 | if (tpacpi_lifecycle == TPACPI_LIFE_RUNNING) |
| 1603 | hotkey_poll_setup_safe(0); |
| 1604 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1605 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1606 | /* sysfs hotkey enable ------------------------------------------------- */ |
| 1607 | static ssize_t hotkey_enable_show(struct device *dev, |
| 1608 | struct device_attribute *attr, |
| 1609 | char *buf) |
| 1610 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1611 | int res, status; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1612 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1613 | res = hotkey_status_get(&status); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1614 | if (res) |
| 1615 | return res; |
| 1616 | |
| 1617 | return snprintf(buf, PAGE_SIZE, "%d\n", status); |
| 1618 | } |
| 1619 | |
| 1620 | static ssize_t hotkey_enable_store(struct device *dev, |
| 1621 | struct device_attribute *attr, |
| 1622 | const char *buf, size_t count) |
| 1623 | { |
| 1624 | unsigned long t; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1625 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1626 | |
| 1627 | if (parse_strtoul(buf, 1, &t)) |
| 1628 | return -EINVAL; |
| 1629 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1630 | res = hotkey_status_set(t); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1631 | |
| 1632 | return (res) ? res : count; |
| 1633 | } |
| 1634 | |
| 1635 | static struct device_attribute dev_attr_hotkey_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1636 | __ATTR(hotkey_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1637 | hotkey_enable_show, hotkey_enable_store); |
| 1638 | |
| 1639 | /* sysfs hotkey mask --------------------------------------------------- */ |
| 1640 | static ssize_t hotkey_mask_show(struct device *dev, |
| 1641 | struct device_attribute *attr, |
| 1642 | char *buf) |
| 1643 | { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1644 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1645 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1646 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 1647 | return -ERESTARTSYS; |
| 1648 | res = hotkey_mask_get(); |
| 1649 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1650 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1651 | return (res)? |
| 1652 | res : snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_mask); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | static ssize_t hotkey_mask_store(struct device *dev, |
| 1656 | struct device_attribute *attr, |
| 1657 | const char *buf, size_t count) |
| 1658 | { |
| 1659 | unsigned long t; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1660 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1661 | |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1662 | if (parse_strtoul(buf, 0xffffffffUL, &t)) |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1663 | return -EINVAL; |
| 1664 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1665 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 1666 | return -ERESTARTSYS; |
| 1667 | |
| 1668 | res = hotkey_mask_set(t); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1669 | |
| 1670 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1671 | hotkey_poll_setup(1); |
| 1672 | #endif |
| 1673 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1674 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1675 | |
| 1676 | return (res) ? res : count; |
| 1677 | } |
| 1678 | |
| 1679 | static struct device_attribute dev_attr_hotkey_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1680 | __ATTR(hotkey_mask, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1681 | hotkey_mask_show, hotkey_mask_store); |
| 1682 | |
| 1683 | /* sysfs hotkey bios_enabled ------------------------------------------- */ |
| 1684 | static ssize_t hotkey_bios_enabled_show(struct device *dev, |
| 1685 | struct device_attribute *attr, |
| 1686 | char *buf) |
| 1687 | { |
| 1688 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_orig_status); |
| 1689 | } |
| 1690 | |
| 1691 | static struct device_attribute dev_attr_hotkey_bios_enabled = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1692 | __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] | 1693 | |
| 1694 | /* sysfs hotkey bios_mask ---------------------------------------------- */ |
| 1695 | static ssize_t hotkey_bios_mask_show(struct device *dev, |
| 1696 | struct device_attribute *attr, |
| 1697 | char *buf) |
| 1698 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1699 | 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] | 1700 | } |
| 1701 | |
| 1702 | static struct device_attribute dev_attr_hotkey_bios_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1703 | __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] | 1704 | |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1705 | /* sysfs hotkey all_mask ----------------------------------------------- */ |
| 1706 | static ssize_t hotkey_all_mask_show(struct device *dev, |
| 1707 | struct device_attribute *attr, |
| 1708 | char *buf) |
| 1709 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1710 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
| 1711 | hotkey_all_mask | hotkey_source_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | static struct device_attribute dev_attr_hotkey_all_mask = |
| 1715 | __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL); |
| 1716 | |
| 1717 | /* sysfs hotkey recommended_mask --------------------------------------- */ |
| 1718 | static ssize_t hotkey_recommended_mask_show(struct device *dev, |
| 1719 | struct device_attribute *attr, |
| 1720 | char *buf) |
| 1721 | { |
| 1722 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1723 | (hotkey_all_mask | hotkey_source_mask) |
| 1724 | & ~hotkey_reserved_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | static struct device_attribute dev_attr_hotkey_recommended_mask = |
| 1728 | __ATTR(hotkey_recommended_mask, S_IRUGO, |
| 1729 | hotkey_recommended_mask_show, NULL); |
| 1730 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1731 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1732 | |
| 1733 | /* sysfs hotkey hotkey_source_mask ------------------------------------- */ |
| 1734 | static ssize_t hotkey_source_mask_show(struct device *dev, |
| 1735 | struct device_attribute *attr, |
| 1736 | char *buf) |
| 1737 | { |
| 1738 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask); |
| 1739 | } |
| 1740 | |
| 1741 | static ssize_t hotkey_source_mask_store(struct device *dev, |
| 1742 | struct device_attribute *attr, |
| 1743 | const char *buf, size_t count) |
| 1744 | { |
| 1745 | unsigned long t; |
| 1746 | |
| 1747 | if (parse_strtoul(buf, 0xffffffffUL, &t) || |
| 1748 | ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0)) |
| 1749 | return -EINVAL; |
| 1750 | |
| 1751 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 1752 | return -ERESTARTSYS; |
| 1753 | |
| 1754 | HOTKEY_CONFIG_CRITICAL_START |
| 1755 | hotkey_source_mask = t; |
| 1756 | HOTKEY_CONFIG_CRITICAL_END |
| 1757 | |
| 1758 | hotkey_poll_setup(1); |
| 1759 | |
| 1760 | mutex_unlock(&hotkey_mutex); |
| 1761 | |
| 1762 | return count; |
| 1763 | } |
| 1764 | |
| 1765 | static struct device_attribute dev_attr_hotkey_source_mask = |
| 1766 | __ATTR(hotkey_source_mask, S_IWUSR | S_IRUGO, |
| 1767 | hotkey_source_mask_show, hotkey_source_mask_store); |
| 1768 | |
| 1769 | /* sysfs hotkey hotkey_poll_freq --------------------------------------- */ |
| 1770 | static ssize_t hotkey_poll_freq_show(struct device *dev, |
| 1771 | struct device_attribute *attr, |
| 1772 | char *buf) |
| 1773 | { |
| 1774 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq); |
| 1775 | } |
| 1776 | |
| 1777 | static ssize_t hotkey_poll_freq_store(struct device *dev, |
| 1778 | struct device_attribute *attr, |
| 1779 | const char *buf, size_t count) |
| 1780 | { |
| 1781 | unsigned long t; |
| 1782 | |
| 1783 | if (parse_strtoul(buf, 25, &t)) |
| 1784 | return -EINVAL; |
| 1785 | |
| 1786 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 1787 | return -ERESTARTSYS; |
| 1788 | |
| 1789 | hotkey_poll_freq = t; |
| 1790 | |
| 1791 | hotkey_poll_setup(1); |
| 1792 | mutex_unlock(&hotkey_mutex); |
| 1793 | |
| 1794 | return count; |
| 1795 | } |
| 1796 | |
| 1797 | static struct device_attribute dev_attr_hotkey_poll_freq = |
| 1798 | __ATTR(hotkey_poll_freq, S_IWUSR | S_IRUGO, |
| 1799 | hotkey_poll_freq_show, hotkey_poll_freq_store); |
| 1800 | |
| 1801 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1802 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1803 | /* sysfs hotkey radio_sw (pollable) ------------------------------------ */ |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 1804 | static ssize_t hotkey_radio_sw_show(struct device *dev, |
| 1805 | struct device_attribute *attr, |
| 1806 | char *buf) |
| 1807 | { |
| 1808 | int res, s; |
| 1809 | res = hotkey_get_wlsw(&s); |
| 1810 | if (res < 0) |
| 1811 | return res; |
| 1812 | |
| 1813 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); |
| 1814 | } |
| 1815 | |
| 1816 | static struct device_attribute dev_attr_hotkey_radio_sw = |
| 1817 | __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL); |
| 1818 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1819 | static void hotkey_radio_sw_notify_change(void) |
| 1820 | { |
| 1821 | if (tp_features.hotkey_wlsw) |
| 1822 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 1823 | "hotkey_radio_sw"); |
| 1824 | } |
| 1825 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1826 | /* sysfs hotkey tablet mode (pollable) --------------------------------- */ |
| 1827 | static ssize_t hotkey_tablet_mode_show(struct device *dev, |
| 1828 | struct device_attribute *attr, |
| 1829 | char *buf) |
| 1830 | { |
| 1831 | int res, s; |
| 1832 | res = hotkey_get_tablet_mode(&s); |
| 1833 | if (res < 0) |
| 1834 | return res; |
| 1835 | |
| 1836 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); |
| 1837 | } |
| 1838 | |
| 1839 | static struct device_attribute dev_attr_hotkey_tablet_mode = |
| 1840 | __ATTR(hotkey_tablet_mode, S_IRUGO, hotkey_tablet_mode_show, NULL); |
| 1841 | |
| 1842 | static void hotkey_tablet_mode_notify_change(void) |
| 1843 | { |
| 1844 | if (tp_features.hotkey_tablet) |
| 1845 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 1846 | "hotkey_tablet_mode"); |
| 1847 | } |
| 1848 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 1849 | /* sysfs hotkey report_mode -------------------------------------------- */ |
| 1850 | static ssize_t hotkey_report_mode_show(struct device *dev, |
| 1851 | struct device_attribute *attr, |
| 1852 | char *buf) |
| 1853 | { |
| 1854 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 1855 | (hotkey_report_mode != 0) ? hotkey_report_mode : 1); |
| 1856 | } |
| 1857 | |
| 1858 | static struct device_attribute dev_attr_hotkey_report_mode = |
| 1859 | __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL); |
| 1860 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1861 | /* sysfs wakeup reason (pollable) -------------------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 1862 | static ssize_t hotkey_wakeup_reason_show(struct device *dev, |
| 1863 | struct device_attribute *attr, |
| 1864 | char *buf) |
| 1865 | { |
| 1866 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason); |
| 1867 | } |
| 1868 | |
| 1869 | static struct device_attribute dev_attr_hotkey_wakeup_reason = |
| 1870 | __ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL); |
| 1871 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 1872 | static void hotkey_wakeup_reason_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1873 | { |
| 1874 | if (tp_features.hotkey_mask) |
| 1875 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 1876 | "wakeup_reason"); |
| 1877 | } |
| 1878 | |
| 1879 | /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 1880 | static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev, |
| 1881 | struct device_attribute *attr, |
| 1882 | char *buf) |
| 1883 | { |
| 1884 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack); |
| 1885 | } |
| 1886 | |
| 1887 | static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete = |
| 1888 | __ATTR(wakeup_hotunplug_complete, S_IRUGO, |
| 1889 | hotkey_wakeup_hotunplug_complete_show, NULL); |
| 1890 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 1891 | static void hotkey_wakeup_hotunplug_complete_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1892 | { |
| 1893 | if (tp_features.hotkey_mask) |
| 1894 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 1895 | "wakeup_hotunplug_complete"); |
| 1896 | } |
| 1897 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1898 | /* --------------------------------------------------------------------- */ |
| 1899 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 1900 | static struct attribute *hotkey_attributes[] __initdata = { |
| 1901 | &dev_attr_hotkey_enable.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1902 | &dev_attr_hotkey_bios_enabled.attr, |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 1903 | &dev_attr_hotkey_report_mode.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1904 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1905 | &dev_attr_hotkey_mask.attr, |
| 1906 | &dev_attr_hotkey_all_mask.attr, |
| 1907 | &dev_attr_hotkey_recommended_mask.attr, |
| 1908 | &dev_attr_hotkey_source_mask.attr, |
| 1909 | &dev_attr_hotkey_poll_freq.attr, |
| 1910 | #endif |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 1911 | }; |
| 1912 | |
| 1913 | static struct attribute *hotkey_mask_attributes[] __initdata = { |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1914 | &dev_attr_hotkey_bios_mask.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1915 | #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1916 | &dev_attr_hotkey_mask.attr, |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1917 | &dev_attr_hotkey_all_mask.attr, |
| 1918 | &dev_attr_hotkey_recommended_mask.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1919 | #endif |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 1920 | &dev_attr_hotkey_wakeup_reason.attr, |
| 1921 | &dev_attr_hotkey_wakeup_hotunplug_complete.attr, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1922 | }; |
| 1923 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 1924 | static void hotkey_exit(void) |
| 1925 | { |
| 1926 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1927 | hotkey_poll_stop_sync(); |
| 1928 | #endif |
| 1929 | |
| 1930 | if (hotkey_dev_attributes) |
| 1931 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 1932 | |
| 1933 | kfree(hotkey_keycode_map); |
| 1934 | |
| 1935 | if (tp_features.hotkey) { |
| 1936 | dbg_printk(TPACPI_DBG_EXIT, |
| 1937 | "restoring original hot key mask\n"); |
| 1938 | /* no short-circuit boolean operator below! */ |
| 1939 | if ((hotkey_mask_set(hotkey_orig_mask) | |
| 1940 | hotkey_status_set(hotkey_orig_status)) != 0) |
| 1941 | printk(TPACPI_ERR |
| 1942 | "failed to restore hot key mask " |
| 1943 | "to BIOS defaults\n"); |
| 1944 | } |
| 1945 | } |
| 1946 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1947 | static int __init hotkey_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1948 | { |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1949 | /* Requirements for changing the default keymaps: |
| 1950 | * |
| 1951 | * 1. Many of the keys are mapped to KEY_RESERVED for very |
| 1952 | * good reasons. Do not change them unless you have deep |
| 1953 | * knowledge on the IBM and Lenovo ThinkPad firmware for |
| 1954 | * the various ThinkPad models. The driver behaves |
| 1955 | * differently for KEY_RESERVED: such keys have their |
| 1956 | * hot key mask *unset* in mask_recommended, and also |
| 1957 | * in the initial hot key mask programmed into the |
| 1958 | * firmware at driver load time, which means the firm- |
| 1959 | * ware may react very differently if you change them to |
| 1960 | * something else; |
| 1961 | * |
| 1962 | * 2. You must be subscribed to the linux-thinkpad and |
| 1963 | * ibm-acpi-devel mailing lists, and you should read the |
| 1964 | * list archives since 2007 if you want to change the |
| 1965 | * keymaps. This requirement exists so that you will |
| 1966 | * know the past history of problems with the thinkpad- |
| 1967 | * acpi driver keymaps, and also that you will be |
| 1968 | * listening to any bug reports; |
| 1969 | * |
| 1970 | * 3. Do not send thinkpad-acpi specific patches directly to |
| 1971 | * for merging, *ever*. Send them to the linux-acpi |
| 1972 | * mailinglist for comments. Merging is to be done only |
| 1973 | * through acpi-test and the ACPI maintainer. |
| 1974 | * |
| 1975 | * If the above is too much to ask, don't change the keymap. |
| 1976 | * Ask the thinkpad-acpi maintainer to do it, instead. |
| 1977 | */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1978 | static u16 ibm_keycode_map[] __initdata = { |
| 1979 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 1980 | KEY_FN_F1, KEY_FN_F2, KEY_COFFEE, KEY_SLEEP, |
| 1981 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 1982 | 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] | 1983 | |
| 1984 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1985 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 1986 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 1987 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1988 | |
| 1989 | /* brightness: firmware always reacts to them, unless |
| 1990 | * X.org did some tricks in the radeon BIOS scratch |
| 1991 | * registers of *some* models */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 1992 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 1993 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1994 | |
| 1995 | /* Thinklight: firmware always react to it */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1996 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1997 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1998 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 1999 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2000 | |
| 2001 | /* Volume: firmware always react to it and reprograms |
| 2002 | * the built-in *extra* mixer. Never map it to control |
| 2003 | * another mixer by default. */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 2004 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 2005 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 2006 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2007 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2008 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2009 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2010 | /* (assignments unknown, please report if found) */ |
| 2011 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2012 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2013 | }; |
| 2014 | static u16 lenovo_keycode_map[] __initdata = { |
| 2015 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 2016 | KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP, |
| 2017 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 2018 | 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] | 2019 | |
| 2020 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2021 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 2022 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 2023 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2024 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 2025 | /* These either have to go through ACPI video, or |
| 2026 | * act like in the IBM ThinkPads, so don't ever |
| 2027 | * enable them by default */ |
Henrique de Moraes Holschuh | 56a185b | 2007-12-13 12:14:09 -0200 | [diff] [blame] | 2028 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
Henrique de Moraes Holschuh | 56a185b | 2007-12-13 12:14:09 -0200 | [diff] [blame] | 2029 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2030 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2031 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2032 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2033 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 2034 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2035 | |
| 2036 | /* Volume: z60/z61, T60 (BIOS version?): firmware always |
| 2037 | * react to it and reprograms the built-in *extra* mixer. |
| 2038 | * Never map it to control another mixer by default. |
| 2039 | * |
| 2040 | * T60?, T61, R60?, R61: firmware and EC tries to send |
| 2041 | * these over the regular keyboard, so these are no-ops, |
| 2042 | * but there are still weird bugs re. MUTE, so do not |
| 2043 | * change unless you get test reports from all Lenovo |
| 2044 | * models. May cause the BIOS to interfere with the |
| 2045 | * HDA mixer. |
| 2046 | */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 2047 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 2048 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 2049 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2050 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2051 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2052 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2053 | /* (assignments unknown, please report if found) */ |
| 2054 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2055 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2056 | }; |
| 2057 | |
| 2058 | #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map) |
| 2059 | #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map) |
| 2060 | #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0]) |
| 2061 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2062 | int res, i; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2063 | int status; |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2064 | int hkeyv; |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 2065 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2066 | vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n"); |
| 2067 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2068 | BUG_ON(!tpacpi_inputdev); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2069 | BUG_ON(tpacpi_inputdev->open != NULL || |
| 2070 | tpacpi_inputdev->close != NULL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2071 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2072 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2073 | mutex_init(&hotkey_mutex); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2074 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2075 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2076 | mutex_init(&hotkey_thread_mutex); |
| 2077 | mutex_init(&hotkey_thread_data_mutex); |
| 2078 | #endif |
| 2079 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2080 | /* hotkey not supported on 570 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2081 | tp_features.hotkey = hkey_handle != NULL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2082 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2083 | vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2084 | str_supported(tp_features.hotkey)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2085 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2086 | if (!tp_features.hotkey) |
| 2087 | return 1; |
| 2088 | |
| 2089 | hotkey_dev_attributes = create_attr_set(13, NULL); |
| 2090 | if (!hotkey_dev_attributes) |
| 2091 | return -ENOMEM; |
| 2092 | res = add_many_to_attr_set(hotkey_dev_attributes, |
| 2093 | hotkey_attributes, |
| 2094 | ARRAY_SIZE(hotkey_attributes)); |
| 2095 | if (res) |
| 2096 | goto err_exit; |
| 2097 | |
| 2098 | /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 2099 | A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking |
| 2100 | for HKEY interface version 0x100 */ |
| 2101 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { |
| 2102 | if ((hkeyv >> 8) != 1) { |
| 2103 | printk(TPACPI_ERR "unknown version of the " |
| 2104 | "HKEY interface: 0x%x\n", hkeyv); |
| 2105 | printk(TPACPI_ERR "please report this to %s\n", |
| 2106 | TPACPI_MAIL); |
| 2107 | } else { |
| 2108 | /* |
| 2109 | * MHKV 0x100 in A31, R40, R40e, |
| 2110 | * T4x, X31, and later |
| 2111 | */ |
| 2112 | tp_features.hotkey_mask = 1; |
| 2113 | } |
| 2114 | } |
| 2115 | |
| 2116 | vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n", |
| 2117 | str_supported(tp_features.hotkey_mask)); |
| 2118 | |
| 2119 | if (tp_features.hotkey_mask) { |
| 2120 | if (!acpi_evalf(hkey_handle, &hotkey_all_mask, |
| 2121 | "MHKA", "qd")) { |
| 2122 | printk(TPACPI_ERR |
| 2123 | "missing MHKA handler, " |
| 2124 | "please report this to %s\n", |
| 2125 | TPACPI_MAIL); |
| 2126 | /* FN+F12, FN+F4, FN+F3 */ |
| 2127 | hotkey_all_mask = 0x080cU; |
| 2128 | } |
| 2129 | } |
| 2130 | |
| 2131 | /* hotkey_source_mask *must* be zero for |
| 2132 | * the first hotkey_mask_get */ |
| 2133 | res = hotkey_status_get(&hotkey_orig_status); |
| 2134 | if (res) |
| 2135 | goto err_exit; |
| 2136 | |
| 2137 | if (tp_features.hotkey_mask) { |
| 2138 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2139 | if (res) |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2140 | goto err_exit; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2141 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2142 | hotkey_orig_mask = hotkey_mask; |
| 2143 | res = add_many_to_attr_set( |
| 2144 | hotkey_dev_attributes, |
| 2145 | hotkey_mask_attributes, |
| 2146 | ARRAY_SIZE(hotkey_mask_attributes)); |
| 2147 | if (res) |
| 2148 | goto err_exit; |
| 2149 | } |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2150 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2151 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2152 | if (tp_features.hotkey_mask) { |
| 2153 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK |
| 2154 | & ~hotkey_all_mask; |
| 2155 | } else { |
| 2156 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK; |
| 2157 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2158 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2159 | vdbg_printk(TPACPI_DBG_INIT, |
| 2160 | "hotkey source mask 0x%08x, polling freq %d\n", |
| 2161 | hotkey_source_mask, hotkey_poll_freq); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2162 | #endif |
| 2163 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2164 | /* Not all thinkpads have a hardware radio switch */ |
| 2165 | if (acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { |
| 2166 | tp_features.hotkey_wlsw = 1; |
| 2167 | printk(TPACPI_INFO |
| 2168 | "radio switch found; radios are %s\n", |
| 2169 | enabled(status, 0)); |
| 2170 | res = add_to_attr_set(hotkey_dev_attributes, |
| 2171 | &dev_attr_hotkey_radio_sw.attr); |
| 2172 | } |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2173 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2174 | /* For X41t, X60t, X61t Tablets... */ |
| 2175 | if (!res && acpi_evalf(hkey_handle, &status, "MHKG", "qd")) { |
| 2176 | tp_features.hotkey_tablet = 1; |
| 2177 | printk(TPACPI_INFO |
| 2178 | "possible tablet mode switch found; " |
| 2179 | "ThinkPad in %s mode\n", |
| 2180 | (status & TP_HOTKEY_TABLET_MASK)? |
| 2181 | "tablet" : "laptop"); |
| 2182 | res = add_to_attr_set(hotkey_dev_attributes, |
| 2183 | &dev_attr_hotkey_tablet_mode.attr); |
| 2184 | } |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2185 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2186 | if (!res) |
| 2187 | res = register_attr_set_with_sysfs( |
| 2188 | hotkey_dev_attributes, |
| 2189 | &tpacpi_pdev->dev.kobj); |
| 2190 | if (res) |
| 2191 | goto err_exit; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2192 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2193 | /* Set up key map */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2194 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2195 | hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, |
| 2196 | GFP_KERNEL); |
| 2197 | if (!hotkey_keycode_map) { |
| 2198 | printk(TPACPI_ERR |
| 2199 | "failed to allocate memory for key map\n"); |
| 2200 | res = -ENOMEM; |
| 2201 | goto err_exit; |
| 2202 | } |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2203 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2204 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) { |
| 2205 | dbg_printk(TPACPI_DBG_INIT, |
| 2206 | "using Lenovo default hot key map\n"); |
| 2207 | memcpy(hotkey_keycode_map, &lenovo_keycode_map, |
| 2208 | TPACPI_HOTKEY_MAP_SIZE); |
| 2209 | } else { |
| 2210 | dbg_printk(TPACPI_DBG_INIT, |
| 2211 | "using IBM default hot key map\n"); |
| 2212 | memcpy(hotkey_keycode_map, &ibm_keycode_map, |
| 2213 | TPACPI_HOTKEY_MAP_SIZE); |
| 2214 | } |
| 2215 | |
| 2216 | set_bit(EV_KEY, tpacpi_inputdev->evbit); |
| 2217 | set_bit(EV_MSC, tpacpi_inputdev->evbit); |
| 2218 | set_bit(MSC_SCAN, tpacpi_inputdev->mscbit); |
| 2219 | tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE; |
| 2220 | tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN; |
| 2221 | tpacpi_inputdev->keycode = hotkey_keycode_map; |
| 2222 | for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) { |
| 2223 | if (hotkey_keycode_map[i] != KEY_RESERVED) { |
| 2224 | set_bit(hotkey_keycode_map[i], |
| 2225 | tpacpi_inputdev->keybit); |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2226 | } else { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2227 | if (i < sizeof(hotkey_reserved_mask)*8) |
| 2228 | hotkey_reserved_mask |= 1 << i; |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2229 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2230 | } |
| 2231 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2232 | if (tp_features.hotkey_wlsw) { |
| 2233 | set_bit(EV_SW, tpacpi_inputdev->evbit); |
| 2234 | set_bit(SW_RFKILL_ALL, tpacpi_inputdev->swbit); |
| 2235 | } |
| 2236 | if (tp_features.hotkey_tablet) { |
| 2237 | set_bit(EV_SW, tpacpi_inputdev->evbit); |
| 2238 | set_bit(SW_TABLET_MODE, tpacpi_inputdev->swbit); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2239 | } |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2240 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2241 | /* Do not issue duplicate brightness change events to |
| 2242 | * userspace */ |
| 2243 | if (!tp_features.bright_acpimode) |
| 2244 | /* update bright_acpimode... */ |
| 2245 | tpacpi_check_std_acpi_brightness_support(); |
| 2246 | |
| 2247 | if (tp_features.bright_acpimode) { |
| 2248 | printk(TPACPI_INFO |
| 2249 | "This ThinkPad has standard ACPI backlight " |
| 2250 | "brightness control, supported by the ACPI " |
| 2251 | "video driver\n"); |
| 2252 | printk(TPACPI_NOTICE |
| 2253 | "Disabling thinkpad-acpi brightness events " |
| 2254 | "by default...\n"); |
| 2255 | |
| 2256 | /* The hotkey_reserved_mask change below is not |
| 2257 | * necessary while the keys are at KEY_RESERVED in the |
| 2258 | * default map, but better safe than sorry, leave it |
| 2259 | * here as a marker of what we have to do, especially |
| 2260 | * when we finally become able to set this at runtime |
| 2261 | * on response to X.org requests */ |
| 2262 | hotkey_reserved_mask |= |
| 2263 | (1 << TP_ACPI_HOTKEYSCAN_FNHOME) |
| 2264 | | (1 << TP_ACPI_HOTKEYSCAN_FNEND); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2265 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2266 | |
| 2267 | dbg_printk(TPACPI_DBG_INIT, "enabling hot key handling\n"); |
| 2268 | res = hotkey_status_set(1); |
| 2269 | if (res) { |
| 2270 | hotkey_exit(); |
| 2271 | return res; |
| 2272 | } |
| 2273 | res = hotkey_mask_set(((hotkey_all_mask | hotkey_source_mask) |
| 2274 | & ~hotkey_reserved_mask) |
| 2275 | | hotkey_orig_mask); |
| 2276 | if (res < 0 && res != -ENXIO) { |
| 2277 | hotkey_exit(); |
| 2278 | return res; |
| 2279 | } |
| 2280 | |
| 2281 | dbg_printk(TPACPI_DBG_INIT, |
| 2282 | "legacy hot key reporting over procfs %s\n", |
| 2283 | (hotkey_report_mode < 2) ? |
| 2284 | "enabled" : "disabled"); |
| 2285 | |
| 2286 | tpacpi_inputdev->open = &hotkey_inputdev_open; |
| 2287 | tpacpi_inputdev->close = &hotkey_inputdev_close; |
| 2288 | |
| 2289 | hotkey_poll_setup_safe(1); |
| 2290 | tpacpi_input_send_radiosw(); |
| 2291 | tpacpi_input_send_tabletsw(); |
| 2292 | |
| 2293 | return 0; |
| 2294 | |
| 2295 | err_exit: |
| 2296 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 2297 | hotkey_dev_attributes = NULL; |
| 2298 | |
| 2299 | return (res < 0)? res : 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
| 2303 | { |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2304 | u32 hkey; |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2305 | unsigned int scancode; |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2306 | int send_acpi_ev; |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2307 | int ignore_acpi_ev; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2308 | int unk_ev; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2309 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2310 | if (event != 0x80) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2311 | printk(TPACPI_ERR |
| 2312 | "unknown HKEY notification event %d\n", event); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2313 | /* 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] | 2314 | acpi_bus_generate_netlink_event( |
| 2315 | ibm->acpi->device->pnp.device_class, |
| 2316 | ibm->acpi->device->dev.bus_id, |
| 2317 | event, 0); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2318 | return; |
| 2319 | } |
| 2320 | |
| 2321 | while (1) { |
| 2322 | if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2323 | printk(TPACPI_ERR "failed to retrieve HKEY event\n"); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2324 | return; |
| 2325 | } |
| 2326 | |
| 2327 | if (hkey == 0) { |
| 2328 | /* queue empty */ |
| 2329 | return; |
| 2330 | } |
| 2331 | |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2332 | send_acpi_ev = 1; |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2333 | ignore_acpi_ev = 0; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2334 | unk_ev = 0; |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2335 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2336 | switch (hkey >> 12) { |
| 2337 | case 1: |
| 2338 | /* 0x1000-0x1FFF: key presses */ |
| 2339 | scancode = hkey & 0xfff; |
| 2340 | if (scancode > 0 && scancode < 0x21) { |
| 2341 | scancode--; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2342 | if (!(hotkey_source_mask & (1 << scancode))) { |
| 2343 | tpacpi_input_send_key(scancode); |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2344 | send_acpi_ev = 0; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2345 | } else { |
| 2346 | ignore_acpi_ev = 1; |
| 2347 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2348 | } else { |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2349 | unk_ev = 1; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2350 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2351 | break; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2352 | case 2: |
| 2353 | /* Wakeup reason */ |
| 2354 | switch (hkey) { |
| 2355 | case 0x2304: /* suspend, undock */ |
| 2356 | case 0x2404: /* hibernation, undock */ |
| 2357 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK; |
| 2358 | ignore_acpi_ev = 1; |
| 2359 | break; |
| 2360 | case 0x2305: /* suspend, bay eject */ |
| 2361 | case 0x2405: /* hibernation, bay eject */ |
| 2362 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ; |
| 2363 | ignore_acpi_ev = 1; |
| 2364 | break; |
| 2365 | default: |
| 2366 | unk_ev = 1; |
| 2367 | } |
| 2368 | if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) { |
| 2369 | printk(TPACPI_INFO |
| 2370 | "woke up due to a hot-unplug " |
| 2371 | "request...\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2372 | hotkey_wakeup_reason_notify_change(); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2373 | } |
| 2374 | break; |
| 2375 | case 3: |
| 2376 | /* bay-related wakeups */ |
| 2377 | if (hkey == 0x3003) { |
| 2378 | hotkey_autosleep_ack = 1; |
| 2379 | printk(TPACPI_INFO |
| 2380 | "bay ejected\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2381 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2382 | } else { |
| 2383 | unk_ev = 1; |
| 2384 | } |
| 2385 | break; |
| 2386 | case 4: |
| 2387 | /* dock-related wakeups */ |
| 2388 | if (hkey == 0x4003) { |
| 2389 | hotkey_autosleep_ack = 1; |
| 2390 | printk(TPACPI_INFO |
| 2391 | "undocked\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2392 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2393 | } else { |
| 2394 | unk_ev = 1; |
| 2395 | } |
| 2396 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2397 | case 5: |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 2398 | /* 0x5000-0x5FFF: human interface helpers */ |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2399 | switch (hkey) { |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 2400 | case 0x5010: /* Lenovo new BIOS: brightness changed */ |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 2401 | case 0x500b: /* X61t: tablet pen inserted into bay */ |
| 2402 | case 0x500c: /* X61t: tablet pen removed from bay */ |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2403 | break; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2404 | case 0x5009: /* X41t-X61t: swivel up (tablet mode) */ |
| 2405 | case 0x500a: /* X41t-X61t: swivel down (normal mode) */ |
| 2406 | tpacpi_input_send_tabletsw(); |
| 2407 | hotkey_tablet_mode_notify_change(); |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2408 | send_acpi_ev = 0; |
| 2409 | break; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2410 | case 0x5001: |
| 2411 | case 0x5002: |
| 2412 | /* LID switch events. Do not propagate */ |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2413 | ignore_acpi_ev = 1; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2414 | break; |
| 2415 | default: |
| 2416 | unk_ev = 1; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2417 | } |
| 2418 | break; |
| 2419 | case 7: |
| 2420 | /* 0x7000-0x7FFF: misc */ |
| 2421 | if (tp_features.hotkey_wlsw && hkey == 0x7000) { |
| 2422 | tpacpi_input_send_radiosw(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2423 | hotkey_radio_sw_notify_change(); |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2424 | send_acpi_ev = 0; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2425 | break; |
| 2426 | } |
| 2427 | /* fallthrough to default */ |
| 2428 | default: |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2429 | unk_ev = 1; |
| 2430 | } |
| 2431 | if (unk_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2432 | printk(TPACPI_NOTICE |
| 2433 | "unhandled HKEY event 0x%04x\n", hkey); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2434 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2435 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2436 | /* Legacy events */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2437 | if (!ignore_acpi_ev && |
| 2438 | (send_acpi_ev || hotkey_report_mode < 2)) { |
| 2439 | acpi_bus_generate_proc_event(ibm->acpi->device, |
| 2440 | event, hkey); |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2441 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2442 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2443 | /* netlink events */ |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2444 | if (!ignore_acpi_ev && send_acpi_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2445 | acpi_bus_generate_netlink_event( |
| 2446 | ibm->acpi->device->pnp.device_class, |
| 2447 | ibm->acpi->device->dev.bus_id, |
| 2448 | event, hkey); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2449 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2450 | } |
| 2451 | } |
| 2452 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2453 | static void hotkey_suspend(pm_message_t state) |
| 2454 | { |
| 2455 | /* Do these on suspend, we get the events on early resume! */ |
| 2456 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE; |
| 2457 | hotkey_autosleep_ack = 0; |
| 2458 | } |
| 2459 | |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2460 | static void hotkey_resume(void) |
| 2461 | { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2462 | if (hotkey_mask_get()) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2463 | printk(TPACPI_ERR |
| 2464 | "error while trying to read hot key mask " |
| 2465 | "from firmware\n"); |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2466 | tpacpi_input_send_radiosw(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2467 | hotkey_radio_sw_notify_change(); |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2468 | hotkey_tablet_mode_notify_change(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2469 | hotkey_wakeup_reason_notify_change(); |
| 2470 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2471 | hotkey_poll_setup_safe(0); |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2472 | } |
| 2473 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2474 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2475 | static int hotkey_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2476 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2477 | int res, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | int len = 0; |
| 2479 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2480 | if (!tp_features.hotkey) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2481 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 2482 | return len; |
| 2483 | } |
| 2484 | |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 2485 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 2486 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2487 | res = hotkey_status_get(&status); |
| 2488 | if (!res) |
| 2489 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2490 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 2491 | if (res) |
| 2492 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | |
| 2494 | 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] | 2495 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2496 | len += sprintf(p + len, "mask:\t\t0x%08x\n", hotkey_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | len += sprintf(p + len, |
| 2498 | "commands:\tenable, disable, reset, <mask>\n"); |
| 2499 | } else { |
| 2500 | len += sprintf(p + len, "mask:\t\tnot supported\n"); |
| 2501 | len += sprintf(p + len, "commands:\tenable, disable, reset\n"); |
| 2502 | } |
| 2503 | |
| 2504 | return len; |
| 2505 | } |
| 2506 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2507 | static int hotkey_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2509 | int res, status; |
| 2510 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | char *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2512 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2513 | if (!tp_features.hotkey) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | return -ENODEV; |
| 2515 | |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 2516 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 2517 | return -ERESTARTSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2518 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2519 | status = -1; |
| 2520 | mask = hotkey_mask; |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2521 | |
| 2522 | res = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2523 | while ((cmd = next_cmd(&buf))) { |
| 2524 | if (strlencmp(cmd, "enable") == 0) { |
| 2525 | status = 1; |
| 2526 | } else if (strlencmp(cmd, "disable") == 0) { |
| 2527 | status = 0; |
| 2528 | } else if (strlencmp(cmd, "reset") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2529 | status = hotkey_orig_status; |
| 2530 | mask = hotkey_orig_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { |
| 2532 | /* mask set */ |
| 2533 | } else if (sscanf(cmd, "%x", &mask) == 1) { |
| 2534 | /* mask set */ |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2535 | } else { |
| 2536 | res = -EINVAL; |
| 2537 | goto errexit; |
| 2538 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2539 | } |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2540 | if (status != -1) |
| 2541 | res = hotkey_status_set(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2543 | if (!res && mask != hotkey_mask) |
| 2544 | res = hotkey_mask_set(mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2546 | errexit: |
| 2547 | mutex_unlock(&hotkey_mutex); |
| 2548 | return res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2550 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 2551 | static const struct acpi_device_id ibm_htk_device_ids[] = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2552 | {TPACPI_ACPI_HKEY_HID, 0}, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 2553 | {"", 0}, |
| 2554 | }; |
| 2555 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2556 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = { |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 2557 | .hid = ibm_htk_device_ids, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2558 | .notify = hotkey_notify, |
| 2559 | .handle = &hkey_handle, |
| 2560 | .type = ACPI_DEVICE_NOTIFY, |
| 2561 | }; |
| 2562 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2563 | static struct ibm_struct hotkey_driver_data = { |
| 2564 | .name = "hotkey", |
| 2565 | .read = hotkey_read, |
| 2566 | .write = hotkey_write, |
| 2567 | .exit = hotkey_exit, |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2568 | .resume = hotkey_resume, |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2569 | .suspend = hotkey_suspend, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2570 | .acpi = &ibm_hotkey_acpidriver, |
| 2571 | }; |
| 2572 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2573 | /************************************************************************* |
| 2574 | * Bluetooth subdriver |
| 2575 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2577 | enum { |
| 2578 | /* ACPI GBDC/SBDC bits */ |
| 2579 | TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */ |
| 2580 | TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */ |
| 2581 | TP_ACPI_BLUETOOTH_UNK = 0x04, /* unknown function */ |
| 2582 | }; |
| 2583 | |
| 2584 | static int bluetooth_get_radiosw(void); |
| 2585 | static int bluetooth_set_radiosw(int radio_on); |
| 2586 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2587 | /* sysfs bluetooth enable ---------------------------------------------- */ |
| 2588 | static ssize_t bluetooth_enable_show(struct device *dev, |
| 2589 | struct device_attribute *attr, |
| 2590 | char *buf) |
| 2591 | { |
| 2592 | int status; |
| 2593 | |
| 2594 | status = bluetooth_get_radiosw(); |
| 2595 | if (status < 0) |
| 2596 | return status; |
| 2597 | |
| 2598 | return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0); |
| 2599 | } |
| 2600 | |
| 2601 | static ssize_t bluetooth_enable_store(struct device *dev, |
| 2602 | struct device_attribute *attr, |
| 2603 | const char *buf, size_t count) |
| 2604 | { |
| 2605 | unsigned long t; |
| 2606 | int res; |
| 2607 | |
| 2608 | if (parse_strtoul(buf, 1, &t)) |
| 2609 | return -EINVAL; |
| 2610 | |
| 2611 | res = bluetooth_set_radiosw(t); |
| 2612 | |
| 2613 | return (res) ? res : count; |
| 2614 | } |
| 2615 | |
| 2616 | static struct device_attribute dev_attr_bluetooth_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2617 | __ATTR(bluetooth_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2618 | bluetooth_enable_show, bluetooth_enable_store); |
| 2619 | |
| 2620 | /* --------------------------------------------------------------------- */ |
| 2621 | |
| 2622 | static struct attribute *bluetooth_attributes[] = { |
| 2623 | &dev_attr_bluetooth_enable.attr, |
| 2624 | NULL |
| 2625 | }; |
| 2626 | |
| 2627 | static const struct attribute_group bluetooth_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2628 | .attrs = bluetooth_attributes, |
| 2629 | }; |
| 2630 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2631 | static int __init bluetooth_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2633 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2634 | int status = 0; |
| 2635 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2636 | vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n"); |
| 2637 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2638 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2639 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2640 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 2641 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2642 | tp_features.bluetooth = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2643 | acpi_evalf(hkey_handle, &status, "GBDC", "qd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2645 | vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s, status 0x%02x\n", |
| 2646 | str_supported(tp_features.bluetooth), |
| 2647 | status); |
| 2648 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2649 | if (tp_features.bluetooth) { |
| 2650 | if (!(status & TP_ACPI_BLUETOOTH_HWPRESENT)) { |
| 2651 | /* no bluetooth hardware present in system */ |
| 2652 | tp_features.bluetooth = 0; |
| 2653 | dbg_printk(TPACPI_DBG_INIT, |
| 2654 | "bluetooth hardware not installed\n"); |
| 2655 | } else { |
| 2656 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 2657 | &bluetooth_attr_group); |
| 2658 | if (res) |
| 2659 | return res; |
| 2660 | } |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2661 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2662 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2663 | return (tp_features.bluetooth)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | } |
| 2665 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2666 | static void bluetooth_exit(void) |
| 2667 | { |
| 2668 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 2669 | &bluetooth_attr_group); |
| 2670 | } |
| 2671 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2672 | static int bluetooth_get_radiosw(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | { |
| 2674 | int status; |
| 2675 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2676 | if (!tp_features.bluetooth) |
| 2677 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2679 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 2680 | return -EIO; |
| 2681 | |
| 2682 | return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0); |
| 2683 | } |
| 2684 | |
| 2685 | static int bluetooth_set_radiosw(int radio_on) |
| 2686 | { |
| 2687 | int status; |
| 2688 | |
| 2689 | if (!tp_features.bluetooth) |
| 2690 | return -ENODEV; |
| 2691 | |
| 2692 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 2693 | return -EIO; |
| 2694 | if (radio_on) |
| 2695 | status |= TP_ACPI_BLUETOOTH_RADIOSSW; |
| 2696 | else |
| 2697 | status &= ~TP_ACPI_BLUETOOTH_RADIOSSW; |
| 2698 | if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) |
| 2699 | return -EIO; |
| 2700 | |
| 2701 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | } |
| 2703 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2704 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2705 | static int bluetooth_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | { |
| 2707 | int len = 0; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2708 | int status = bluetooth_get_radiosw(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2710 | if (!tp_features.bluetooth) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2711 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | else { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2713 | len += sprintf(p + len, "status:\t\t%s\n", |
| 2714 | (status)? "enabled" : "disabled"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 2716 | } |
| 2717 | |
| 2718 | return len; |
| 2719 | } |
| 2720 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2721 | static int bluetooth_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2723 | char *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2725 | if (!tp_features.bluetooth) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2726 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2727 | |
| 2728 | while ((cmd = next_cmd(&buf))) { |
| 2729 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2730 | bluetooth_set_radiosw(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2731 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2732 | bluetooth_set_radiosw(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | } else |
| 2734 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | } |
| 2736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | return 0; |
| 2738 | } |
| 2739 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2740 | static struct ibm_struct bluetooth_driver_data = { |
| 2741 | .name = "bluetooth", |
| 2742 | .read = bluetooth_read, |
| 2743 | .write = bluetooth_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2744 | .exit = bluetooth_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2745 | }; |
| 2746 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2747 | /************************************************************************* |
| 2748 | * Wan subdriver |
| 2749 | */ |
| 2750 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2751 | enum { |
| 2752 | /* ACPI GWAN/SWAN bits */ |
| 2753 | TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */ |
| 2754 | TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */ |
| 2755 | TP_ACPI_WANCARD_UNK = 0x04, /* unknown function */ |
| 2756 | }; |
| 2757 | |
| 2758 | static int wan_get_radiosw(void); |
| 2759 | static int wan_set_radiosw(int radio_on); |
| 2760 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2761 | /* sysfs wan enable ---------------------------------------------------- */ |
| 2762 | static ssize_t wan_enable_show(struct device *dev, |
| 2763 | struct device_attribute *attr, |
| 2764 | char *buf) |
| 2765 | { |
| 2766 | int status; |
| 2767 | |
| 2768 | status = wan_get_radiosw(); |
| 2769 | if (status < 0) |
| 2770 | return status; |
| 2771 | |
| 2772 | return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0); |
| 2773 | } |
| 2774 | |
| 2775 | static ssize_t wan_enable_store(struct device *dev, |
| 2776 | struct device_attribute *attr, |
| 2777 | const char *buf, size_t count) |
| 2778 | { |
| 2779 | unsigned long t; |
| 2780 | int res; |
| 2781 | |
| 2782 | if (parse_strtoul(buf, 1, &t)) |
| 2783 | return -EINVAL; |
| 2784 | |
| 2785 | res = wan_set_radiosw(t); |
| 2786 | |
| 2787 | return (res) ? res : count; |
| 2788 | } |
| 2789 | |
| 2790 | static struct device_attribute dev_attr_wan_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2791 | __ATTR(wwan_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2792 | wan_enable_show, wan_enable_store); |
| 2793 | |
| 2794 | /* --------------------------------------------------------------------- */ |
| 2795 | |
| 2796 | static struct attribute *wan_attributes[] = { |
| 2797 | &dev_attr_wan_enable.attr, |
| 2798 | NULL |
| 2799 | }; |
| 2800 | |
| 2801 | static const struct attribute_group wan_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2802 | .attrs = wan_attributes, |
| 2803 | }; |
| 2804 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2805 | static int __init wan_init(struct ibm_init_struct *iibm) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2806 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2807 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2808 | int status = 0; |
| 2809 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2810 | vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n"); |
| 2811 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2812 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2813 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2814 | tp_features.wan = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2815 | acpi_evalf(hkey_handle, &status, "GWAN", "qd"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2816 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2817 | vdbg_printk(TPACPI_DBG_INIT, "wan is %s, status 0x%02x\n", |
| 2818 | str_supported(tp_features.wan), |
| 2819 | status); |
| 2820 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2821 | if (tp_features.wan) { |
| 2822 | if (!(status & TP_ACPI_WANCARD_HWPRESENT)) { |
| 2823 | /* no wan hardware present in system */ |
| 2824 | tp_features.wan = 0; |
| 2825 | dbg_printk(TPACPI_DBG_INIT, |
| 2826 | "wan hardware not installed\n"); |
| 2827 | } else { |
| 2828 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 2829 | &wan_attr_group); |
| 2830 | if (res) |
| 2831 | return res; |
| 2832 | } |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2833 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2834 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2835 | return (tp_features.wan)? 0 : 1; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2836 | } |
| 2837 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2838 | static void wan_exit(void) |
| 2839 | { |
| 2840 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 2841 | &wan_attr_group); |
| 2842 | } |
| 2843 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2844 | static int wan_get_radiosw(void) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2845 | { |
| 2846 | int status; |
| 2847 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2848 | if (!tp_features.wan) |
| 2849 | return -ENODEV; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2850 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2851 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 2852 | return -EIO; |
| 2853 | |
| 2854 | return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0); |
| 2855 | } |
| 2856 | |
| 2857 | static int wan_set_radiosw(int radio_on) |
| 2858 | { |
| 2859 | int status; |
| 2860 | |
| 2861 | if (!tp_features.wan) |
| 2862 | return -ENODEV; |
| 2863 | |
| 2864 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 2865 | return -EIO; |
| 2866 | if (radio_on) |
| 2867 | status |= TP_ACPI_WANCARD_RADIOSSW; |
| 2868 | else |
| 2869 | status &= ~TP_ACPI_WANCARD_RADIOSSW; |
| 2870 | if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) |
| 2871 | return -EIO; |
| 2872 | |
| 2873 | return 0; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2874 | } |
| 2875 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2876 | /* procfs -------------------------------------------------------------- */ |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2877 | static int wan_read(char *p) |
| 2878 | { |
| 2879 | int len = 0; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2880 | int status = wan_get_radiosw(); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2881 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2882 | if (!tp_features.wan) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2883 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2884 | else { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2885 | len += sprintf(p + len, "status:\t\t%s\n", |
| 2886 | (status)? "enabled" : "disabled"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2887 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 2888 | } |
| 2889 | |
| 2890 | return len; |
| 2891 | } |
| 2892 | |
| 2893 | static int wan_write(char *buf) |
| 2894 | { |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2895 | char *cmd; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2896 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2897 | if (!tp_features.wan) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2898 | return -ENODEV; |
| 2899 | |
| 2900 | while ((cmd = next_cmd(&buf))) { |
| 2901 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2902 | wan_set_radiosw(1); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2903 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2904 | wan_set_radiosw(0); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2905 | } else |
| 2906 | return -EINVAL; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2907 | } |
| 2908 | |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2909 | return 0; |
| 2910 | } |
| 2911 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2912 | static struct ibm_struct wan_driver_data = { |
| 2913 | .name = "wan", |
| 2914 | .read = wan_read, |
| 2915 | .write = wan_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2916 | .exit = wan_exit, |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 2917 | .flags.experimental = 1, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2918 | }; |
| 2919 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2920 | /************************************************************************* |
| 2921 | * Video subdriver |
| 2922 | */ |
| 2923 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 2924 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
| 2925 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2926 | enum video_access_mode { |
| 2927 | TPACPI_VIDEO_NONE = 0, |
| 2928 | TPACPI_VIDEO_570, /* 570 */ |
| 2929 | TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */ |
| 2930 | TPACPI_VIDEO_NEW, /* all others */ |
| 2931 | }; |
| 2932 | |
| 2933 | enum { /* video status flags, based on VIDEO_570 */ |
| 2934 | TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */ |
| 2935 | TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */ |
| 2936 | TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */ |
| 2937 | }; |
| 2938 | |
| 2939 | enum { /* TPACPI_VIDEO_570 constants */ |
| 2940 | TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */ |
| 2941 | TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to |
| 2942 | * video_status_flags */ |
| 2943 | TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */ |
| 2944 | TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */ |
| 2945 | }; |
| 2946 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 2947 | static enum video_access_mode video_supported; |
| 2948 | static int video_orig_autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2949 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2950 | static int video_autosw_get(void); |
| 2951 | static int video_autosw_set(int enable); |
| 2952 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2953 | TPACPI_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2954 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2955 | static int __init video_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2957 | int ivga; |
| 2958 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2959 | vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n"); |
| 2960 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2961 | TPACPI_ACPIHANDLE_INIT(vid); |
| 2962 | TPACPI_ACPIHANDLE_INIT(vid2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2963 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2964 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
| 2965 | /* G41, assume IVGA doesn't change */ |
| 2966 | vid_handle = vid2_handle; |
| 2967 | |
| 2968 | if (!vid_handle) |
| 2969 | /* video switching not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2970 | video_supported = TPACPI_VIDEO_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2971 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) |
| 2972 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2973 | video_supported = TPACPI_VIDEO_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2974 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) |
| 2975 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2976 | video_supported = TPACPI_VIDEO_770; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2977 | else |
| 2978 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2979 | video_supported = TPACPI_VIDEO_NEW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2981 | vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n", |
| 2982 | str_supported(video_supported != TPACPI_VIDEO_NONE), |
| 2983 | video_supported); |
| 2984 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2985 | return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | } |
| 2987 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2988 | static void video_exit(void) |
| 2989 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 2990 | dbg_printk(TPACPI_DBG_EXIT, |
| 2991 | "restoring original video autoswitch mode\n"); |
| 2992 | if (video_autosw_set(video_orig_autosw)) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2993 | printk(TPACPI_ERR "error while trying to restore original " |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 2994 | "video autoswitch mode\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2995 | } |
| 2996 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 2997 | static int video_outputsw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | { |
| 2999 | int status = 0; |
| 3000 | int i; |
| 3001 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3002 | switch (video_supported) { |
| 3003 | case TPACPI_VIDEO_570: |
| 3004 | if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", |
| 3005 | TP_ACPI_VIDEO_570_PHSCMD)) |
| 3006 | return -EIO; |
| 3007 | status = i & TP_ACPI_VIDEO_570_PHSMASK; |
| 3008 | break; |
| 3009 | case TPACPI_VIDEO_770: |
| 3010 | if (!acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 3011 | return -EIO; |
| 3012 | if (i) |
| 3013 | status |= TP_ACPI_VIDEO_S_LCD; |
| 3014 | if (!acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 3015 | return -EIO; |
| 3016 | if (i) |
| 3017 | status |= TP_ACPI_VIDEO_S_CRT; |
| 3018 | break; |
| 3019 | case TPACPI_VIDEO_NEW: |
| 3020 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) || |
| 3021 | !acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 3022 | return -EIO; |
| 3023 | if (i) |
| 3024 | status |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3026 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) || |
| 3027 | !acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 3028 | return -EIO; |
| 3029 | if (i) |
| 3030 | status |= TP_ACPI_VIDEO_S_LCD; |
| 3031 | if (!acpi_evalf(NULL, &i, "\\VCDD", "d")) |
| 3032 | return -EIO; |
| 3033 | if (i) |
| 3034 | status |= TP_ACPI_VIDEO_S_DVI; |
| 3035 | break; |
| 3036 | default: |
| 3037 | return -ENOSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3038 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | |
| 3040 | return status; |
| 3041 | } |
| 3042 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3043 | static int video_outputsw_set(int status) |
| 3044 | { |
| 3045 | int autosw; |
| 3046 | int res = 0; |
| 3047 | |
| 3048 | switch (video_supported) { |
| 3049 | case TPACPI_VIDEO_570: |
| 3050 | res = acpi_evalf(NULL, NULL, |
| 3051 | "\\_SB.PHS2", "vdd", |
| 3052 | TP_ACPI_VIDEO_570_PHS2CMD, |
| 3053 | status | TP_ACPI_VIDEO_570_PHS2SET); |
| 3054 | break; |
| 3055 | case TPACPI_VIDEO_770: |
| 3056 | autosw = video_autosw_get(); |
| 3057 | if (autosw < 0) |
| 3058 | return autosw; |
| 3059 | |
| 3060 | res = video_autosw_set(1); |
| 3061 | if (res) |
| 3062 | return res; |
| 3063 | res = acpi_evalf(vid_handle, NULL, |
| 3064 | "ASWT", "vdd", status * 0x100, 0); |
| 3065 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3066 | printk(TPACPI_ERR |
| 3067 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3068 | return -EIO; |
| 3069 | } |
| 3070 | break; |
| 3071 | case TPACPI_VIDEO_NEW: |
| 3072 | res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3073 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3074 | break; |
| 3075 | default: |
| 3076 | return -ENOSYS; |
| 3077 | } |
| 3078 | |
| 3079 | return (res)? 0 : -EIO; |
| 3080 | } |
| 3081 | |
| 3082 | static int video_autosw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3084 | int autosw = 0; |
| 3085 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3086 | switch (video_supported) { |
| 3087 | case TPACPI_VIDEO_570: |
| 3088 | if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d")) |
| 3089 | return -EIO; |
| 3090 | break; |
| 3091 | case TPACPI_VIDEO_770: |
| 3092 | case TPACPI_VIDEO_NEW: |
| 3093 | if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d")) |
| 3094 | return -EIO; |
| 3095 | break; |
| 3096 | default: |
| 3097 | return -ENOSYS; |
| 3098 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3099 | |
| 3100 | return autosw & 1; |
| 3101 | } |
| 3102 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3103 | static int video_autosw_set(int enable) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3104 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3105 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0)) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3106 | return -EIO; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3107 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3108 | } |
| 3109 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3110 | static int video_outputsw_cycle(void) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3111 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3112 | int autosw = video_autosw_get(); |
| 3113 | int res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3114 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3115 | if (autosw < 0) |
| 3116 | return autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3117 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3118 | switch (video_supported) { |
| 3119 | case TPACPI_VIDEO_570: |
| 3120 | res = video_autosw_set(1); |
| 3121 | if (res) |
| 3122 | return res; |
| 3123 | res = acpi_evalf(ec_handle, NULL, "_Q16", "v"); |
| 3124 | break; |
| 3125 | case TPACPI_VIDEO_770: |
| 3126 | case TPACPI_VIDEO_NEW: |
| 3127 | res = video_autosw_set(1); |
| 3128 | if (res) |
| 3129 | return res; |
| 3130 | res = acpi_evalf(vid_handle, NULL, "VSWT", "v"); |
| 3131 | break; |
| 3132 | default: |
| 3133 | return -ENOSYS; |
| 3134 | } |
| 3135 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3136 | printk(TPACPI_ERR |
| 3137 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3138 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3139 | } |
| 3140 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3141 | return (res)? 0 : -EIO; |
| 3142 | } |
| 3143 | |
| 3144 | static int video_expand_toggle(void) |
| 3145 | { |
| 3146 | switch (video_supported) { |
| 3147 | case TPACPI_VIDEO_570: |
| 3148 | return acpi_evalf(ec_handle, NULL, "_Q17", "v")? |
| 3149 | 0 : -EIO; |
| 3150 | case TPACPI_VIDEO_770: |
| 3151 | return acpi_evalf(vid_handle, NULL, "VEXP", "v")? |
| 3152 | 0 : -EIO; |
| 3153 | case TPACPI_VIDEO_NEW: |
| 3154 | return acpi_evalf(NULL, NULL, "\\VEXP", "v")? |
| 3155 | 0 : -EIO; |
| 3156 | default: |
| 3157 | return -ENOSYS; |
| 3158 | } |
| 3159 | /* not reached */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3160 | } |
| 3161 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3162 | static int video_read(char *p) |
| 3163 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3164 | int status, autosw; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3165 | int len = 0; |
| 3166 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3167 | if (video_supported == TPACPI_VIDEO_NONE) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3168 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3169 | return len; |
| 3170 | } |
| 3171 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3172 | status = video_outputsw_get(); |
| 3173 | if (status < 0) |
| 3174 | return status; |
| 3175 | |
| 3176 | autosw = video_autosw_get(); |
| 3177 | if (autosw < 0) |
| 3178 | return autosw; |
| 3179 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3180 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 3181 | len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0)); |
| 3182 | 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] | 3183 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3184 | len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3)); |
| 3185 | len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0)); |
| 3186 | len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n"); |
| 3187 | len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3188 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3189 | len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n"); |
| 3190 | len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n"); |
| 3191 | len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n"); |
| 3192 | |
| 3193 | return len; |
| 3194 | } |
| 3195 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3196 | static int video_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3197 | { |
| 3198 | char *cmd; |
| 3199 | int enable, disable, status; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3200 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3202 | if (video_supported == TPACPI_VIDEO_NONE) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3203 | return -ENODEV; |
| 3204 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3205 | enable = 0; |
| 3206 | disable = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | |
| 3208 | while ((cmd = next_cmd(&buf))) { |
| 3209 | if (strlencmp(cmd, "lcd_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3210 | enable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | } else if (strlencmp(cmd, "lcd_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3212 | disable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | } else if (strlencmp(cmd, "crt_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3214 | enable |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3216 | disable |= TP_ACPI_VIDEO_S_CRT; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3217 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3218 | strlencmp(cmd, "dvi_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3219 | enable |= TP_ACPI_VIDEO_S_DVI; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3220 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3221 | strlencmp(cmd, "dvi_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3222 | disable |= TP_ACPI_VIDEO_S_DVI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3224 | res = video_autosw_set(1); |
| 3225 | if (res) |
| 3226 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | } else if (strlencmp(cmd, "auto_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3228 | res = video_autosw_set(0); |
| 3229 | if (res) |
| 3230 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | } else if (strlencmp(cmd, "video_switch") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3232 | res = video_outputsw_cycle(); |
| 3233 | if (res) |
| 3234 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | } else if (strlencmp(cmd, "expand_toggle") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3236 | res = video_expand_toggle(); |
| 3237 | if (res) |
| 3238 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | } else |
| 3240 | return -EINVAL; |
| 3241 | } |
| 3242 | |
| 3243 | if (enable || disable) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3244 | status = video_outputsw_get(); |
| 3245 | if (status < 0) |
| 3246 | return status; |
| 3247 | res = video_outputsw_set((status & ~disable) | enable); |
| 3248 | if (res) |
| 3249 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | return 0; |
| 3253 | } |
| 3254 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3255 | static struct ibm_struct video_driver_data = { |
| 3256 | .name = "video", |
| 3257 | .read = video_read, |
| 3258 | .write = video_write, |
| 3259 | .exit = video_exit, |
| 3260 | }; |
| 3261 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 3262 | #endif /* CONFIG_THINKPAD_ACPI_VIDEO */ |
| 3263 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3264 | /************************************************************************* |
| 3265 | * Light (thinklight) subdriver |
| 3266 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3268 | TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
| 3269 | TPACPI_HANDLE(ledb, ec, "LEDB"); /* G4x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3270 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3271 | static int light_get_status(void) |
| 3272 | { |
| 3273 | int status = 0; |
| 3274 | |
| 3275 | if (tp_features.light_status) { |
| 3276 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) |
| 3277 | return -EIO; |
| 3278 | return (!!status); |
| 3279 | } |
| 3280 | |
| 3281 | return -ENXIO; |
| 3282 | } |
| 3283 | |
| 3284 | static int light_set_status(int status) |
| 3285 | { |
| 3286 | int rc; |
| 3287 | |
| 3288 | if (tp_features.light) { |
| 3289 | if (cmos_handle) { |
| 3290 | rc = acpi_evalf(cmos_handle, NULL, NULL, "vd", |
| 3291 | (status)? |
| 3292 | TP_CMOS_THINKLIGHT_ON : |
| 3293 | TP_CMOS_THINKLIGHT_OFF); |
| 3294 | } else { |
| 3295 | rc = acpi_evalf(lght_handle, NULL, NULL, "vd", |
| 3296 | (status)? 1 : 0); |
| 3297 | } |
| 3298 | return (rc)? 0 : -EIO; |
| 3299 | } |
| 3300 | |
| 3301 | return -ENXIO; |
| 3302 | } |
| 3303 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 3304 | static void light_set_status_worker(struct work_struct *work) |
| 3305 | { |
| 3306 | struct tpacpi_led_classdev *data = |
| 3307 | container_of(work, struct tpacpi_led_classdev, work); |
| 3308 | |
| 3309 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
| 3310 | light_set_status((data->new_brightness != LED_OFF)); |
| 3311 | } |
| 3312 | |
| 3313 | static void light_sysfs_set(struct led_classdev *led_cdev, |
| 3314 | enum led_brightness brightness) |
| 3315 | { |
| 3316 | struct tpacpi_led_classdev *data = |
| 3317 | container_of(led_cdev, |
| 3318 | struct tpacpi_led_classdev, |
| 3319 | led_classdev); |
| 3320 | data->new_brightness = brightness; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 3321 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 3322 | } |
| 3323 | |
| 3324 | static enum led_brightness light_sysfs_get(struct led_classdev *led_cdev) |
| 3325 | { |
| 3326 | return (light_get_status() == 1)? LED_FULL : LED_OFF; |
| 3327 | } |
| 3328 | |
| 3329 | static struct tpacpi_led_classdev tpacpi_led_thinklight = { |
| 3330 | .led_classdev = { |
| 3331 | .name = "tpacpi::thinklight", |
| 3332 | .brightness_set = &light_sysfs_set, |
| 3333 | .brightness_get = &light_sysfs_get, |
| 3334 | } |
| 3335 | }; |
| 3336 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3337 | static int __init light_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3338 | { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3339 | int rc; |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 3340 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3341 | vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); |
| 3342 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3343 | TPACPI_ACPIHANDLE_INIT(ledb); |
| 3344 | TPACPI_ACPIHANDLE_INIT(lght); |
| 3345 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 3346 | INIT_WORK(&tpacpi_led_thinklight.work, light_set_status_worker); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3347 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3348 | /* 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] | 3349 | tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3350 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3351 | if (tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3352 | /* light status not supported on |
| 3353 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3354 | tp_features.light_status = |
| 3355 | acpi_evalf(ec_handle, NULL, "KBLT", "qv"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3356 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3357 | vdbg_printk(TPACPI_DBG_INIT, "light is %s, light status is %s\n", |
| 3358 | str_supported(tp_features.light), |
| 3359 | str_supported(tp_features.light_status)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3360 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3361 | if (!tp_features.light) |
| 3362 | return 1; |
| 3363 | |
| 3364 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 3365 | &tpacpi_led_thinklight.led_classdev); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 3366 | |
| 3367 | if (rc < 0) { |
| 3368 | tp_features.light = 0; |
| 3369 | tp_features.light_status = 0; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3370 | } else { |
| 3371 | rc = 0; |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 3372 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3373 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 3374 | return rc; |
| 3375 | } |
| 3376 | |
| 3377 | static void light_exit(void) |
| 3378 | { |
| 3379 | led_classdev_unregister(&tpacpi_led_thinklight.led_classdev); |
| 3380 | if (work_pending(&tpacpi_led_thinklight.work)) |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 3381 | flush_workqueue(tpacpi_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | } |
| 3383 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3384 | static int light_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | { |
| 3386 | int len = 0; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3387 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3389 | if (!tp_features.light) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3390 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3391 | } else if (!tp_features.light_status) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3392 | len += sprintf(p + len, "status:\t\tunknown\n"); |
| 3393 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 3394 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3395 | status = light_get_status(); |
| 3396 | if (status < 0) |
| 3397 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3398 | len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3399 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 3400 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | |
| 3402 | return len; |
| 3403 | } |
| 3404 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3405 | static int light_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3406 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3407 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3408 | int newstatus = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3409 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3410 | if (!tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3411 | return -ENODEV; |
| 3412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | while ((cmd = next_cmd(&buf))) { |
| 3414 | if (strlencmp(cmd, "on") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3415 | newstatus = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | } else if (strlencmp(cmd, "off") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3417 | newstatus = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | } else |
| 3419 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | } |
| 3421 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3422 | return light_set_status(newstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | } |
| 3424 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3425 | static struct ibm_struct light_driver_data = { |
| 3426 | .name = "light", |
| 3427 | .read = light_read, |
| 3428 | .write = light_write, |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 3429 | .exit = light_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3430 | }; |
| 3431 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3432 | /************************************************************************* |
| 3433 | * Dock subdriver |
| 3434 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3436 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3437 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3438 | static void dock_notify(struct ibm_struct *ibm, u32 event); |
| 3439 | static int dock_read(char *p); |
| 3440 | static int dock_write(char *buf); |
| 3441 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3442 | TPACPI_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3443 | "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */ |
| 3444 | "\\_SB.PCI0.PCI1.DOCK", /* all others */ |
| 3445 | "\\_SB.PCI.ISA.SLCE", /* 570 */ |
| 3446 | ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */ |
| 3447 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3448 | /* 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] | 3449 | TPACPI_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */ |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3450 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3451 | static const struct acpi_device_id ibm_pci_device_ids[] = { |
| 3452 | {PCI_ROOT_HID_STRING, 0}, |
| 3453 | {"", 0}, |
| 3454 | }; |
| 3455 | |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 3456 | static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = { |
| 3457 | { |
| 3458 | .notify = dock_notify, |
| 3459 | .handle = &dock_handle, |
| 3460 | .type = ACPI_SYSTEM_NOTIFY, |
| 3461 | }, |
| 3462 | { |
Henrique de Moraes Holschuh | 996fba0 | 2007-07-18 23:45:40 -0300 | [diff] [blame] | 3463 | /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING. |
| 3464 | * We just use it to get notifications of dock hotplug |
| 3465 | * in very old thinkpads */ |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3466 | .hid = ibm_pci_device_ids, |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 3467 | .notify = dock_notify, |
| 3468 | .handle = &pci_handle, |
| 3469 | .type = ACPI_SYSTEM_NOTIFY, |
| 3470 | }, |
| 3471 | }; |
| 3472 | |
| 3473 | static struct ibm_struct dock_driver_data[2] = { |
| 3474 | { |
| 3475 | .name = "dock", |
| 3476 | .read = dock_read, |
| 3477 | .write = dock_write, |
| 3478 | .acpi = &ibm_dock_acpidriver[0], |
| 3479 | }, |
| 3480 | { |
| 3481 | .name = "dock", |
| 3482 | .acpi = &ibm_dock_acpidriver[1], |
| 3483 | }, |
| 3484 | }; |
| 3485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3486 | #define dock_docked() (_sta(dock_handle) & 1) |
| 3487 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3488 | static int __init dock_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3489 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3490 | vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n"); |
| 3491 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3492 | TPACPI_ACPIHANDLE_INIT(dock); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3493 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3494 | vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n", |
| 3495 | str_supported(dock_handle != NULL)); |
| 3496 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3497 | return (dock_handle)? 0 : 1; |
| 3498 | } |
| 3499 | |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 3500 | static int __init dock_init2(struct ibm_init_struct *iibm) |
| 3501 | { |
| 3502 | int dock2_needed; |
| 3503 | |
| 3504 | vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver part 2\n"); |
| 3505 | |
| 3506 | if (dock_driver_data[0].flags.acpi_driver_registered && |
| 3507 | dock_driver_data[0].flags.acpi_notify_installed) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3508 | TPACPI_ACPIHANDLE_INIT(pci); |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 3509 | dock2_needed = (pci_handle != NULL); |
| 3510 | vdbg_printk(TPACPI_DBG_INIT, |
| 3511 | "dock PCI handler for the TP 570 is %s\n", |
| 3512 | str_supported(dock2_needed)); |
| 3513 | } else { |
| 3514 | vdbg_printk(TPACPI_DBG_INIT, |
| 3515 | "dock subdriver part 2 not required\n"); |
| 3516 | dock2_needed = 0; |
| 3517 | } |
| 3518 | |
| 3519 | return (dock2_needed)? 0 : 1; |
| 3520 | } |
| 3521 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3522 | static void dock_notify(struct ibm_struct *ibm, u32 event) |
| 3523 | { |
| 3524 | int docked = dock_docked(); |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3525 | int pci = ibm->acpi->hid && ibm->acpi->device && |
| 3526 | acpi_match_device_ids(ibm->acpi->device, ibm_pci_device_ids); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3527 | int data; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3528 | |
| 3529 | if (event == 1 && !pci) /* 570 */ |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3530 | data = 1; /* button */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3531 | else if (event == 1 && pci) /* 570 */ |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3532 | data = 3; /* dock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3533 | else if (event == 3 && docked) |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3534 | data = 1; /* button */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3535 | else if (event == 3 && !docked) |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3536 | data = 2; /* undock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3537 | else if (event == 0 && docked) |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3538 | data = 3; /* dock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3539 | else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3540 | printk(TPACPI_ERR "unknown dock event %d, status %d\n", |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3541 | event, _sta(dock_handle)); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3542 | data = 0; /* unknown */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3543 | } |
Len Brown | 14e04fb | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 3544 | acpi_bus_generate_proc_event(ibm->acpi->device, event, data); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3545 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, |
| 3546 | ibm->acpi->device->dev.bus_id, |
| 3547 | event, data); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3548 | } |
| 3549 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3550 | static int dock_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3551 | { |
| 3552 | int len = 0; |
| 3553 | int docked = dock_docked(); |
| 3554 | |
| 3555 | if (!dock_handle) |
| 3556 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3557 | else if (!docked) |
| 3558 | len += sprintf(p + len, "status:\t\tundocked\n"); |
| 3559 | else { |
| 3560 | len += sprintf(p + len, "status:\t\tdocked\n"); |
| 3561 | len += sprintf(p + len, "commands:\tdock, undock\n"); |
| 3562 | } |
| 3563 | |
| 3564 | return len; |
| 3565 | } |
| 3566 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3567 | static int dock_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3568 | { |
| 3569 | char *cmd; |
| 3570 | |
| 3571 | if (!dock_docked()) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3572 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | |
| 3574 | while ((cmd = next_cmd(&buf))) { |
| 3575 | if (strlencmp(cmd, "undock") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3576 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) || |
| 3577 | !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3578 | return -EIO; |
| 3579 | } else if (strlencmp(cmd, "dock") == 0) { |
| 3580 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1)) |
| 3581 | return -EIO; |
| 3582 | } else |
| 3583 | return -EINVAL; |
| 3584 | } |
| 3585 | |
| 3586 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3587 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3588 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3589 | #endif /* CONFIG_THINKPAD_ACPI_DOCK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3591 | /************************************************************************* |
| 3592 | * Bay subdriver |
| 3593 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3594 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3595 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3596 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3597 | TPACPI_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3598 | "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ |
| 3599 | "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */ |
| 3600 | "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */ |
| 3601 | ); /* A21e, R30, R31 */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3602 | 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] | 3603 | "_EJ0", /* all others */ |
| 3604 | ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3605 | 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] | 3606 | "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */ |
| 3607 | ); /* all others */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3608 | TPACPI_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3609 | "_EJ0", /* 770x */ |
| 3610 | ); /* all others */ |
| 3611 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3612 | static int __init bay_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3614 | vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n"); |
| 3615 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3616 | TPACPI_ACPIHANDLE_INIT(bay); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3617 | if (bay_handle) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3618 | TPACPI_ACPIHANDLE_INIT(bay_ej); |
| 3619 | TPACPI_ACPIHANDLE_INIT(bay2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3620 | if (bay2_handle) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3621 | TPACPI_ACPIHANDLE_INIT(bay2_ej); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3622 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3623 | tp_features.bay_status = bay_handle && |
| 3624 | acpi_evalf(bay_handle, NULL, "_STA", "qv"); |
| 3625 | tp_features.bay_status2 = bay2_handle && |
| 3626 | acpi_evalf(bay2_handle, NULL, "_STA", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3627 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3628 | tp_features.bay_eject = bay_handle && bay_ej_handle && |
| 3629 | (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental); |
| 3630 | tp_features.bay_eject2 = bay2_handle && bay2_ej_handle && |
| 3631 | (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3633 | vdbg_printk(TPACPI_DBG_INIT, |
| 3634 | "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] | 3635 | str_supported(tp_features.bay_status), |
| 3636 | str_supported(tp_features.bay_eject), |
| 3637 | str_supported(tp_features.bay_status2), |
| 3638 | str_supported(tp_features.bay_eject2)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3639 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3640 | return (tp_features.bay_status || tp_features.bay_eject || |
| 3641 | tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | } |
| 3643 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3644 | static void bay_notify(struct ibm_struct *ibm, u32 event) |
| 3645 | { |
Len Brown | 14e04fb | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 3646 | acpi_bus_generate_proc_event(ibm->acpi->device, event, 0); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3647 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, |
| 3648 | ibm->acpi->device->dev.bus_id, |
| 3649 | event, 0); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3650 | } |
| 3651 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3652 | #define bay_occupied(b) (_sta(b##_handle) & 1) |
| 3653 | |
| 3654 | static int bay_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3655 | { |
| 3656 | int len = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3657 | int occupied = bay_occupied(bay); |
| 3658 | int occupied2 = bay_occupied(bay2); |
| 3659 | int eject, eject2; |
| 3660 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3661 | len += sprintf(p + len, "status:\t\t%s\n", |
| 3662 | tp_features.bay_status ? |
| 3663 | (occupied ? "occupied" : "unoccupied") : |
| 3664 | "not supported"); |
| 3665 | if (tp_features.bay_status2) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3666 | len += sprintf(p + len, "status2:\t%s\n", occupied2 ? |
| 3667 | "occupied" : "unoccupied"); |
| 3668 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3669 | eject = tp_features.bay_eject && occupied; |
| 3670 | eject2 = tp_features.bay_eject2 && occupied2; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3671 | |
| 3672 | if (eject && eject2) |
| 3673 | len += sprintf(p + len, "commands:\teject, eject2\n"); |
| 3674 | else if (eject) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3675 | len += sprintf(p + len, "commands:\teject\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3676 | else if (eject2) |
| 3677 | len += sprintf(p + len, "commands:\teject2\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3678 | |
| 3679 | return len; |
| 3680 | } |
| 3681 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3682 | static int bay_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3683 | { |
| 3684 | char *cmd; |
| 3685 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3686 | if (!tp_features.bay_eject && !tp_features.bay_eject2) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3687 | return -ENODEV; |
| 3688 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3689 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3690 | if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3691 | if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1)) |
| 3692 | return -EIO; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3693 | } else if (tp_features.bay_eject2 && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3694 | strlencmp(cmd, "eject2") == 0) { |
| 3695 | if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | return -EIO; |
| 3697 | } else |
| 3698 | return -EINVAL; |
| 3699 | } |
| 3700 | |
| 3701 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3702 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3703 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3704 | static struct tp_acpi_drv_struct ibm_bay_acpidriver = { |
| 3705 | .notify = bay_notify, |
| 3706 | .handle = &bay_handle, |
| 3707 | .type = ACPI_SYSTEM_NOTIFY, |
| 3708 | }; |
| 3709 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3710 | static struct ibm_struct bay_driver_data = { |
| 3711 | .name = "bay", |
| 3712 | .read = bay_read, |
| 3713 | .write = bay_write, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3714 | .acpi = &ibm_bay_acpidriver, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3715 | }; |
| 3716 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3717 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3718 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3719 | /************************************************************************* |
| 3720 | * CMOS subdriver |
| 3721 | */ |
| 3722 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3723 | /* sysfs cmos_command -------------------------------------------------- */ |
| 3724 | static ssize_t cmos_command_store(struct device *dev, |
| 3725 | struct device_attribute *attr, |
| 3726 | const char *buf, size_t count) |
| 3727 | { |
| 3728 | unsigned long cmos_cmd; |
| 3729 | int res; |
| 3730 | |
| 3731 | if (parse_strtoul(buf, 21, &cmos_cmd)) |
| 3732 | return -EINVAL; |
| 3733 | |
| 3734 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 3735 | return (res)? res : count; |
| 3736 | } |
| 3737 | |
| 3738 | static struct device_attribute dev_attr_cmos_command = |
| 3739 | __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store); |
| 3740 | |
| 3741 | /* --------------------------------------------------------------------- */ |
| 3742 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3743 | static int __init cmos_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3744 | { |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3745 | int res; |
| 3746 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3747 | vdbg_printk(TPACPI_DBG_INIT, |
| 3748 | "initializing cmos commands subdriver\n"); |
| 3749 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3750 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3751 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3752 | vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n", |
| 3753 | str_supported(cmos_handle != NULL)); |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3754 | |
| 3755 | res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 3756 | if (res) |
| 3757 | return res; |
| 3758 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3759 | return (cmos_handle)? 0 : 1; |
| 3760 | } |
| 3761 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3762 | static void cmos_exit(void) |
| 3763 | { |
| 3764 | device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 3765 | } |
| 3766 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3767 | static int cmos_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3768 | { |
| 3769 | int len = 0; |
| 3770 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3771 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 3772 | R30, R31, T20-22, X20-21 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3773 | if (!cmos_handle) |
| 3774 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3775 | else { |
| 3776 | len += sprintf(p + len, "status:\t\tsupported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3777 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3778 | } |
| 3779 | |
| 3780 | return len; |
| 3781 | } |
| 3782 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3783 | static int cmos_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | { |
| 3785 | char *cmd; |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 3786 | int cmos_cmd, res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | |
| 3788 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3789 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
| 3790 | cmos_cmd >= 0 && cmos_cmd <= 21) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | /* cmos_cmd set */ |
| 3792 | } else |
| 3793 | return -EINVAL; |
| 3794 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 3795 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 3796 | if (res) |
| 3797 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3801 | } |
| 3802 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3803 | static struct ibm_struct cmos_driver_data = { |
| 3804 | .name = "cmos", |
| 3805 | .read = cmos_read, |
| 3806 | .write = cmos_write, |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3807 | .exit = cmos_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3808 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3809 | |
| 3810 | /************************************************************************* |
| 3811 | * LED subdriver |
| 3812 | */ |
| 3813 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3814 | enum led_access_mode { |
| 3815 | TPACPI_LED_NONE = 0, |
| 3816 | TPACPI_LED_570, /* 570 */ |
| 3817 | TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 3818 | TPACPI_LED_NEW, /* all others */ |
| 3819 | }; |
| 3820 | |
| 3821 | enum { /* For TPACPI_LED_OLD */ |
| 3822 | TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */ |
| 3823 | TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */ |
| 3824 | TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */ |
| 3825 | }; |
| 3826 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3827 | enum led_status_t { |
| 3828 | TPACPI_LED_OFF = 0, |
| 3829 | TPACPI_LED_ON, |
| 3830 | TPACPI_LED_BLINK, |
| 3831 | }; |
| 3832 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 3833 | static enum led_access_mode led_supported; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3834 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3835 | TPACPI_HANDLE(led, ec, "SLED", /* 570 */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3836 | "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */ |
| 3837 | /* T20-22, X20-21 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3838 | "LED", /* all others */ |
| 3839 | ); /* R30, R31 */ |
| 3840 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 3841 | #define TPACPI_LED_NUMLEDS 8 |
| 3842 | static struct tpacpi_led_classdev *tpacpi_leds; |
| 3843 | static enum led_status_t tpacpi_led_state_cache[TPACPI_LED_NUMLEDS]; |
Harvey Harrison | e3aa51f | 2008-05-29 17:51:57 -0700 | [diff] [blame] | 3844 | static const char * const tpacpi_led_names[TPACPI_LED_NUMLEDS] = { |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 3845 | /* there's a limit of 19 chars + NULL before 2.6.26 */ |
| 3846 | "tpacpi::power", |
| 3847 | "tpacpi:orange:batt", |
| 3848 | "tpacpi:green:batt", |
| 3849 | "tpacpi::dock_active", |
| 3850 | "tpacpi::bay_active", |
| 3851 | "tpacpi::dock_batt", |
| 3852 | "tpacpi::unknown_led", |
| 3853 | "tpacpi::standby", |
| 3854 | }; |
| 3855 | |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 3856 | static int led_get_status(const unsigned int led) |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3857 | { |
| 3858 | int status; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 3859 | enum led_status_t led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3860 | |
| 3861 | switch (led_supported) { |
| 3862 | case TPACPI_LED_570: |
| 3863 | if (!acpi_evalf(ec_handle, |
| 3864 | &status, "GLED", "dd", 1 << led)) |
| 3865 | return -EIO; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 3866 | led_s = (status == 0)? |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3867 | TPACPI_LED_OFF : |
| 3868 | ((status == 1)? |
| 3869 | TPACPI_LED_ON : |
| 3870 | TPACPI_LED_BLINK); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 3871 | tpacpi_led_state_cache[led] = led_s; |
| 3872 | return led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3873 | default: |
| 3874 | return -ENXIO; |
| 3875 | } |
| 3876 | |
| 3877 | /* not reached */ |
| 3878 | } |
| 3879 | |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 3880 | static int led_set_status(const unsigned int led, |
| 3881 | const enum led_status_t ledstatus) |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3882 | { |
| 3883 | /* off, on, blink. Index is led_status_t */ |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 3884 | static const unsigned int led_sled_arg1[] = { 0, 1, 3 }; |
| 3885 | static const unsigned int led_led_arg1[] = { 0, 0x80, 0xc0 }; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3886 | |
| 3887 | int rc = 0; |
| 3888 | |
| 3889 | switch (led_supported) { |
| 3890 | case TPACPI_LED_570: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 3891 | /* 570 */ |
| 3892 | if (led > 7) |
| 3893 | return -EINVAL; |
| 3894 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 3895 | (1 << led), led_sled_arg1[ledstatus])) |
| 3896 | rc = -EIO; |
| 3897 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3898 | case TPACPI_LED_OLD: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 3899 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
| 3900 | if (led > 7) |
| 3901 | return -EINVAL; |
| 3902 | rc = ec_write(TPACPI_LED_EC_HLMS, (1 << led)); |
| 3903 | if (rc >= 0) |
| 3904 | rc = ec_write(TPACPI_LED_EC_HLBL, |
| 3905 | (ledstatus == TPACPI_LED_BLINK) << led); |
| 3906 | if (rc >= 0) |
| 3907 | rc = ec_write(TPACPI_LED_EC_HLCL, |
| 3908 | (ledstatus != TPACPI_LED_OFF) << led); |
| 3909 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3910 | case TPACPI_LED_NEW: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 3911 | /* all others */ |
| 3912 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 3913 | led, led_led_arg1[ledstatus])) |
| 3914 | rc = -EIO; |
| 3915 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3916 | default: |
| 3917 | rc = -ENXIO; |
| 3918 | } |
| 3919 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 3920 | if (!rc) |
| 3921 | tpacpi_led_state_cache[led] = ledstatus; |
| 3922 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3923 | return rc; |
| 3924 | } |
| 3925 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 3926 | static void led_sysfs_set_status(unsigned int led, |
| 3927 | enum led_brightness brightness) |
| 3928 | { |
| 3929 | led_set_status(led, |
| 3930 | (brightness == LED_OFF) ? |
| 3931 | TPACPI_LED_OFF : |
| 3932 | (tpacpi_led_state_cache[led] == TPACPI_LED_BLINK) ? |
| 3933 | TPACPI_LED_BLINK : TPACPI_LED_ON); |
| 3934 | } |
| 3935 | |
| 3936 | static void led_set_status_worker(struct work_struct *work) |
| 3937 | { |
| 3938 | struct tpacpi_led_classdev *data = |
| 3939 | container_of(work, struct tpacpi_led_classdev, work); |
| 3940 | |
| 3941 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
| 3942 | led_sysfs_set_status(data->led, data->new_brightness); |
| 3943 | } |
| 3944 | |
| 3945 | static void led_sysfs_set(struct led_classdev *led_cdev, |
| 3946 | enum led_brightness brightness) |
| 3947 | { |
| 3948 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 3949 | struct tpacpi_led_classdev, led_classdev); |
| 3950 | |
| 3951 | data->new_brightness = brightness; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 3952 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | static int led_sysfs_blink_set(struct led_classdev *led_cdev, |
| 3956 | unsigned long *delay_on, unsigned long *delay_off) |
| 3957 | { |
| 3958 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 3959 | struct tpacpi_led_classdev, led_classdev); |
| 3960 | |
| 3961 | /* Can we choose the flash rate? */ |
| 3962 | if (*delay_on == 0 && *delay_off == 0) { |
| 3963 | /* yes. set them to the hardware blink rate (1 Hz) */ |
| 3964 | *delay_on = 500; /* ms */ |
| 3965 | *delay_off = 500; /* ms */ |
| 3966 | } else if ((*delay_on != 500) || (*delay_off != 500)) |
| 3967 | return -EINVAL; |
| 3968 | |
| 3969 | data->new_brightness = TPACPI_LED_BLINK; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 3970 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 3971 | |
| 3972 | return 0; |
| 3973 | } |
| 3974 | |
| 3975 | static enum led_brightness led_sysfs_get(struct led_classdev *led_cdev) |
| 3976 | { |
| 3977 | int rc; |
| 3978 | |
| 3979 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 3980 | struct tpacpi_led_classdev, led_classdev); |
| 3981 | |
| 3982 | rc = led_get_status(data->led); |
| 3983 | |
| 3984 | if (rc == TPACPI_LED_OFF || rc < 0) |
| 3985 | rc = LED_OFF; /* no error handling in led class :( */ |
| 3986 | else |
| 3987 | rc = LED_FULL; |
| 3988 | |
| 3989 | return rc; |
| 3990 | } |
| 3991 | |
| 3992 | static void led_exit(void) |
| 3993 | { |
| 3994 | unsigned int i; |
| 3995 | |
| 3996 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
| 3997 | if (tpacpi_leds[i].led_classdev.name) |
| 3998 | led_classdev_unregister(&tpacpi_leds[i].led_classdev); |
| 3999 | } |
| 4000 | |
| 4001 | kfree(tpacpi_leds); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4002 | } |
| 4003 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4004 | static int __init led_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4005 | { |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4006 | unsigned int i; |
| 4007 | int rc; |
| 4008 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4009 | vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); |
| 4010 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4011 | TPACPI_ACPIHANDLE_INIT(led); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4012 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4013 | if (!led_handle) |
| 4014 | /* led not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4015 | led_supported = TPACPI_LED_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4016 | else if (strlencmp(led_path, "SLED") == 0) |
| 4017 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4018 | led_supported = TPACPI_LED_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4019 | else if (strlencmp(led_path, "SYSL") == 0) |
| 4020 | /* 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] | 4021 | led_supported = TPACPI_LED_OLD; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4022 | else |
| 4023 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4024 | led_supported = TPACPI_LED_NEW; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4025 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4026 | vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n", |
| 4027 | str_supported(led_supported), led_supported); |
| 4028 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4029 | tpacpi_leds = kzalloc(sizeof(*tpacpi_leds) * TPACPI_LED_NUMLEDS, |
| 4030 | GFP_KERNEL); |
| 4031 | if (!tpacpi_leds) { |
| 4032 | printk(TPACPI_ERR "Out of memory for LED data\n"); |
| 4033 | return -ENOMEM; |
| 4034 | } |
| 4035 | |
| 4036 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
| 4037 | tpacpi_leds[i].led = i; |
| 4038 | |
| 4039 | tpacpi_leds[i].led_classdev.brightness_set = &led_sysfs_set; |
| 4040 | tpacpi_leds[i].led_classdev.blink_set = &led_sysfs_blink_set; |
| 4041 | if (led_supported == TPACPI_LED_570) |
| 4042 | tpacpi_leds[i].led_classdev.brightness_get = |
| 4043 | &led_sysfs_get; |
| 4044 | |
| 4045 | tpacpi_leds[i].led_classdev.name = tpacpi_led_names[i]; |
| 4046 | |
| 4047 | INIT_WORK(&tpacpi_leds[i].work, led_set_status_worker); |
| 4048 | |
| 4049 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 4050 | &tpacpi_leds[i].led_classdev); |
| 4051 | if (rc < 0) { |
| 4052 | tpacpi_leds[i].led_classdev.name = NULL; |
| 4053 | led_exit(); |
| 4054 | return rc; |
| 4055 | } |
| 4056 | } |
| 4057 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4058 | return (led_supported != TPACPI_LED_NONE)? 0 : 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4059 | } |
| 4060 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4061 | #define str_led_status(s) \ |
| 4062 | ((s) == TPACPI_LED_OFF ? "off" : \ |
| 4063 | ((s) == TPACPI_LED_ON ? "on" : "blinking")) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4064 | |
| 4065 | static int led_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4066 | { |
| 4067 | int len = 0; |
| 4068 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4069 | if (!led_supported) { |
| 4070 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 4071 | return len; |
| 4072 | } |
| 4073 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 4074 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4075 | if (led_supported == TPACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4076 | /* 570 */ |
| 4077 | int i, status; |
| 4078 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4079 | status = led_get_status(i); |
| 4080 | if (status < 0) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4081 | return -EIO; |
| 4082 | len += sprintf(p + len, "%d:\t\t%s\n", |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4083 | i, str_led_status(status)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4084 | } |
| 4085 | } |
| 4086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | len += sprintf(p + len, "commands:\t" |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4088 | "<led> on, <led> off, <led> blink (<led> is 0-7)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4089 | |
| 4090 | return len; |
| 4091 | } |
| 4092 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4093 | static int led_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4094 | { |
| 4095 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4096 | int led, rc; |
| 4097 | enum led_status_t s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4098 | |
| 4099 | if (!led_supported) |
| 4100 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4101 | |
| 4102 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4103 | if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | return -EINVAL; |
| 4105 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4106 | if (strstr(cmd, "off")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4107 | s = TPACPI_LED_OFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4108 | } else if (strstr(cmd, "on")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4109 | s = TPACPI_LED_ON; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4110 | } else if (strstr(cmd, "blink")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4111 | s = TPACPI_LED_BLINK; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4112 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4113 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4114 | } |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4115 | |
| 4116 | rc = led_set_status(led, s); |
| 4117 | if (rc < 0) |
| 4118 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4119 | } |
| 4120 | |
| 4121 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4122 | } |
| 4123 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4124 | static struct ibm_struct led_driver_data = { |
| 4125 | .name = "led", |
| 4126 | .read = led_read, |
| 4127 | .write = led_write, |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4128 | .exit = led_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4129 | }; |
| 4130 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4131 | /************************************************************************* |
| 4132 | * Beep subdriver |
| 4133 | */ |
| 4134 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4135 | TPACPI_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4136 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4137 | static int __init beep_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4138 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4139 | vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n"); |
| 4140 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4141 | TPACPI_ACPIHANDLE_INIT(beep); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4142 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4143 | vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n", |
| 4144 | str_supported(beep_handle != NULL)); |
| 4145 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4146 | return (beep_handle)? 0 : 1; |
| 4147 | } |
| 4148 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4149 | static int beep_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | { |
| 4151 | int len = 0; |
| 4152 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4153 | if (!beep_handle) |
| 4154 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 4155 | else { |
| 4156 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 4157 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n"); |
| 4158 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4159 | |
| 4160 | return len; |
| 4161 | } |
| 4162 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4163 | static int beep_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4164 | { |
| 4165 | char *cmd; |
| 4166 | int beep_cmd; |
| 4167 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4168 | if (!beep_handle) |
| 4169 | return -ENODEV; |
| 4170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4171 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4172 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && |
| 4173 | beep_cmd >= 0 && beep_cmd <= 17) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4174 | /* beep_cmd set */ |
| 4175 | } else |
| 4176 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4177 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | return -EIO; |
| 4179 | } |
| 4180 | |
| 4181 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4182 | } |
| 4183 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4184 | static struct ibm_struct beep_driver_data = { |
| 4185 | .name = "beep", |
| 4186 | .read = beep_read, |
| 4187 | .write = beep_write, |
| 4188 | }; |
| 4189 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4190 | /************************************************************************* |
| 4191 | * Thermal subdriver |
| 4192 | */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4193 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4194 | enum thermal_access_mode { |
| 4195 | TPACPI_THERMAL_NONE = 0, /* No thermal support */ |
| 4196 | TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */ |
| 4197 | TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */ |
| 4198 | TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */ |
| 4199 | TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ |
| 4200 | }; |
| 4201 | |
| 4202 | enum { /* TPACPI_THERMAL_TPEC_* */ |
| 4203 | TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */ |
| 4204 | TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */ |
| 4205 | TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */ |
| 4206 | }; |
| 4207 | |
| 4208 | #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ |
| 4209 | struct ibm_thermal_sensors_struct { |
| 4210 | s32 temp[TPACPI_MAX_THERMAL_SENSORS]; |
| 4211 | }; |
| 4212 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4213 | static enum thermal_access_mode thermal_read_mode; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4214 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4215 | /* idx is zero-based */ |
| 4216 | static int thermal_get_sensor(int idx, s32 *value) |
| 4217 | { |
| 4218 | int t; |
| 4219 | s8 tmp; |
| 4220 | char tmpi[5]; |
| 4221 | |
| 4222 | t = TP_EC_THERMAL_TMP0; |
| 4223 | |
| 4224 | switch (thermal_read_mode) { |
| 4225 | #if TPACPI_MAX_THERMAL_SENSORS >= 16 |
| 4226 | case TPACPI_THERMAL_TPEC_16: |
| 4227 | if (idx >= 8 && idx <= 15) { |
| 4228 | t = TP_EC_THERMAL_TMP8; |
| 4229 | idx -= 8; |
| 4230 | } |
| 4231 | /* fallthrough */ |
| 4232 | #endif |
| 4233 | case TPACPI_THERMAL_TPEC_8: |
| 4234 | if (idx <= 7) { |
| 4235 | if (!acpi_ec_read(t + idx, &tmp)) |
| 4236 | return -EIO; |
| 4237 | *value = tmp * 1000; |
| 4238 | return 0; |
| 4239 | } |
| 4240 | break; |
| 4241 | |
| 4242 | case TPACPI_THERMAL_ACPI_UPDT: |
| 4243 | if (idx <= 7) { |
| 4244 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 4245 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) |
| 4246 | return -EIO; |
| 4247 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 4248 | return -EIO; |
| 4249 | *value = (t - 2732) * 100; |
| 4250 | return 0; |
| 4251 | } |
| 4252 | break; |
| 4253 | |
| 4254 | case TPACPI_THERMAL_ACPI_TMP07: |
| 4255 | if (idx <= 7) { |
| 4256 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 4257 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 4258 | return -EIO; |
| 4259 | if (t > 127 || t < -127) |
| 4260 | t = TP_EC_THERMAL_TMP_NA; |
| 4261 | *value = t * 1000; |
| 4262 | return 0; |
| 4263 | } |
| 4264 | break; |
| 4265 | |
| 4266 | case TPACPI_THERMAL_NONE: |
| 4267 | default: |
| 4268 | return -ENOSYS; |
| 4269 | } |
| 4270 | |
| 4271 | return -EINVAL; |
| 4272 | } |
| 4273 | |
| 4274 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) |
| 4275 | { |
| 4276 | int res, i; |
| 4277 | int n; |
| 4278 | |
| 4279 | n = 8; |
| 4280 | i = 0; |
| 4281 | |
| 4282 | if (!s) |
| 4283 | return -EINVAL; |
| 4284 | |
| 4285 | if (thermal_read_mode == TPACPI_THERMAL_TPEC_16) |
| 4286 | n = 16; |
| 4287 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4288 | for (i = 0 ; i < n; i++) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4289 | res = thermal_get_sensor(i, &s->temp[i]); |
| 4290 | if (res) |
| 4291 | return res; |
| 4292 | } |
| 4293 | |
| 4294 | return n; |
| 4295 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4296 | |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4297 | /* sysfs temp##_input -------------------------------------------------- */ |
| 4298 | |
| 4299 | static ssize_t thermal_temp_input_show(struct device *dev, |
| 4300 | struct device_attribute *attr, |
| 4301 | char *buf) |
| 4302 | { |
| 4303 | struct sensor_device_attribute *sensor_attr = |
| 4304 | to_sensor_dev_attr(attr); |
| 4305 | int idx = sensor_attr->index; |
| 4306 | s32 value; |
| 4307 | int res; |
| 4308 | |
| 4309 | res = thermal_get_sensor(idx, &value); |
| 4310 | if (res) |
| 4311 | return res; |
| 4312 | if (value == TP_EC_THERMAL_TMP_NA * 1000) |
| 4313 | return -ENXIO; |
| 4314 | |
| 4315 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
| 4316 | } |
| 4317 | |
| 4318 | #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4319 | SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \ |
| 4320 | thermal_temp_input_show, NULL, _idxB) |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4321 | |
| 4322 | static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = { |
| 4323 | THERMAL_SENSOR_ATTR_TEMP(1, 0), |
| 4324 | THERMAL_SENSOR_ATTR_TEMP(2, 1), |
| 4325 | THERMAL_SENSOR_ATTR_TEMP(3, 2), |
| 4326 | THERMAL_SENSOR_ATTR_TEMP(4, 3), |
| 4327 | THERMAL_SENSOR_ATTR_TEMP(5, 4), |
| 4328 | THERMAL_SENSOR_ATTR_TEMP(6, 5), |
| 4329 | THERMAL_SENSOR_ATTR_TEMP(7, 6), |
| 4330 | THERMAL_SENSOR_ATTR_TEMP(8, 7), |
| 4331 | THERMAL_SENSOR_ATTR_TEMP(9, 8), |
| 4332 | THERMAL_SENSOR_ATTR_TEMP(10, 9), |
| 4333 | THERMAL_SENSOR_ATTR_TEMP(11, 10), |
| 4334 | THERMAL_SENSOR_ATTR_TEMP(12, 11), |
| 4335 | THERMAL_SENSOR_ATTR_TEMP(13, 12), |
| 4336 | THERMAL_SENSOR_ATTR_TEMP(14, 13), |
| 4337 | THERMAL_SENSOR_ATTR_TEMP(15, 14), |
| 4338 | THERMAL_SENSOR_ATTR_TEMP(16, 15), |
| 4339 | }; |
| 4340 | |
| 4341 | #define THERMAL_ATTRS(X) \ |
| 4342 | &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr |
| 4343 | |
| 4344 | static struct attribute *thermal_temp_input_attr[] = { |
| 4345 | THERMAL_ATTRS(8), |
| 4346 | THERMAL_ATTRS(9), |
| 4347 | THERMAL_ATTRS(10), |
| 4348 | THERMAL_ATTRS(11), |
| 4349 | THERMAL_ATTRS(12), |
| 4350 | THERMAL_ATTRS(13), |
| 4351 | THERMAL_ATTRS(14), |
| 4352 | THERMAL_ATTRS(15), |
| 4353 | THERMAL_ATTRS(0), |
| 4354 | THERMAL_ATTRS(1), |
| 4355 | THERMAL_ATTRS(2), |
| 4356 | THERMAL_ATTRS(3), |
| 4357 | THERMAL_ATTRS(4), |
| 4358 | THERMAL_ATTRS(5), |
| 4359 | THERMAL_ATTRS(6), |
| 4360 | THERMAL_ATTRS(7), |
| 4361 | NULL |
| 4362 | }; |
| 4363 | |
| 4364 | static const struct attribute_group thermal_temp_input16_group = { |
| 4365 | .attrs = thermal_temp_input_attr |
| 4366 | }; |
| 4367 | |
| 4368 | static const struct attribute_group thermal_temp_input8_group = { |
| 4369 | .attrs = &thermal_temp_input_attr[8] |
| 4370 | }; |
| 4371 | |
| 4372 | #undef THERMAL_SENSOR_ATTR_TEMP |
| 4373 | #undef THERMAL_ATTRS |
| 4374 | |
| 4375 | /* --------------------------------------------------------------------- */ |
| 4376 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4377 | static int __init thermal_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4378 | { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4379 | u8 t, ta1, ta2; |
| 4380 | int i; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4381 | int acpi_tmp7; |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4382 | int res; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4383 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4384 | vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n"); |
| 4385 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4386 | acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4387 | |
Henrique de Moraes Holschuh | 3d6f99c | 2007-07-18 23:45:46 -0300 | [diff] [blame] | 4388 | if (thinkpad_id.ec_model) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4389 | /* |
| 4390 | * Direct EC access mode: sensors at registers |
| 4391 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for |
| 4392 | * non-implemented, thermal sensors return 0x80 when |
| 4393 | * not available |
| 4394 | */ |
| 4395 | |
| 4396 | ta1 = ta2 = 0; |
| 4397 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4398 | if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4399 | ta1 |= t; |
| 4400 | } else { |
| 4401 | ta1 = 0; |
| 4402 | break; |
| 4403 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4404 | if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4405 | ta2 |= t; |
| 4406 | } else { |
| 4407 | ta1 = 0; |
| 4408 | break; |
| 4409 | } |
| 4410 | } |
| 4411 | if (ta1 == 0) { |
| 4412 | /* This is sheer paranoia, but we handle it anyway */ |
| 4413 | if (acpi_tmp7) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4414 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4415 | "ThinkPad ACPI EC access misbehaving, " |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4416 | "falling back to ACPI TMPx access " |
| 4417 | "mode\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4418 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4419 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4420 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4421 | "ThinkPad ACPI EC access misbehaving, " |
| 4422 | "disabling thermal sensors access\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4423 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4424 | } |
| 4425 | } else { |
| 4426 | thermal_read_mode = |
| 4427 | (ta2 != 0) ? |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4428 | TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4429 | } |
| 4430 | } else if (acpi_tmp7) { |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4431 | if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { |
| 4432 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4433 | thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4434 | } else { |
| 4435 | /* Standard ACPI TMPx access, max 8 sensors */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4436 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4437 | } |
| 4438 | } else { |
| 4439 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4440 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4441 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4442 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4443 | vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n", |
| 4444 | str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), |
| 4445 | thermal_read_mode); |
| 4446 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4447 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4448 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 4449 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4450 | &thermal_temp_input16_group); |
| 4451 | if (res) |
| 4452 | return res; |
| 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 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4458 | &thermal_temp_input8_group); |
| 4459 | if (res) |
| 4460 | return res; |
| 4461 | break; |
| 4462 | case TPACPI_THERMAL_NONE: |
| 4463 | default: |
| 4464 | return 1; |
| 4465 | } |
| 4466 | |
| 4467 | return 0; |
| 4468 | } |
| 4469 | |
| 4470 | static void thermal_exit(void) |
| 4471 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4472 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4473 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 4474 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4475 | &thermal_temp_input16_group); |
| 4476 | break; |
| 4477 | case TPACPI_THERMAL_TPEC_8: |
| 4478 | case TPACPI_THERMAL_ACPI_TMP07: |
| 4479 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 4480 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4481 | &thermal_temp_input16_group); |
| 4482 | break; |
| 4483 | case TPACPI_THERMAL_NONE: |
| 4484 | default: |
| 4485 | break; |
| 4486 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4487 | } |
| 4488 | |
| 4489 | static int thermal_read(char *p) |
| 4490 | { |
| 4491 | int len = 0; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4492 | int n, i; |
| 4493 | struct ibm_thermal_sensors_struct t; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4494 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4495 | n = thermal_get_sensors(&t); |
| 4496 | if (unlikely(n < 0)) |
| 4497 | return n; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4498 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4499 | len += sprintf(p + len, "temperatures:\t"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4500 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4501 | if (n > 0) { |
| 4502 | for (i = 0; i < (n - 1); i++) |
| 4503 | len += sprintf(p + len, "%d ", t.temp[i] / 1000); |
| 4504 | len += sprintf(p + len, "%d\n", t.temp[i] / 1000); |
| 4505 | } else |
| 4506 | len += sprintf(p + len, "not supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4507 | |
| 4508 | return len; |
| 4509 | } |
| 4510 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4511 | static struct ibm_struct thermal_driver_data = { |
| 4512 | .name = "thermal", |
| 4513 | .read = thermal_read, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4514 | .exit = thermal_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4515 | }; |
| 4516 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4517 | /************************************************************************* |
| 4518 | * EC Dump subdriver |
| 4519 | */ |
| 4520 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4521 | static u8 ecdump_regs[256]; |
| 4522 | |
| 4523 | static int ecdump_read(char *p) |
| 4524 | { |
| 4525 | int len = 0; |
| 4526 | int i, j; |
| 4527 | u8 v; |
| 4528 | |
| 4529 | len += sprintf(p + len, "EC " |
| 4530 | " +00 +01 +02 +03 +04 +05 +06 +07" |
| 4531 | " +08 +09 +0a +0b +0c +0d +0e +0f\n"); |
| 4532 | for (i = 0; i < 256; i += 16) { |
| 4533 | len += sprintf(p + len, "EC 0x%02x:", i); |
| 4534 | for (j = 0; j < 16; j++) { |
| 4535 | if (!acpi_ec_read(i + j, &v)) |
| 4536 | break; |
| 4537 | if (v != ecdump_regs[i + j]) |
| 4538 | len += sprintf(p + len, " *%02x", v); |
| 4539 | else |
| 4540 | len += sprintf(p + len, " %02x", v); |
| 4541 | ecdump_regs[i + j] = v; |
| 4542 | } |
| 4543 | len += sprintf(p + len, "\n"); |
| 4544 | if (j != 16) |
| 4545 | break; |
| 4546 | } |
| 4547 | |
| 4548 | /* These are way too dangerous to advertise openly... */ |
| 4549 | #if 0 |
| 4550 | len += sprintf(p + len, "commands:\t0x<offset> 0x<value>" |
| 4551 | " (<offset> is 00-ff, <value> is 00-ff)\n"); |
| 4552 | len += sprintf(p + len, "commands:\t0x<offset> <value> " |
| 4553 | " (<offset> is 00-ff, <value> is 0-255)\n"); |
| 4554 | #endif |
| 4555 | return len; |
| 4556 | } |
| 4557 | |
| 4558 | static int ecdump_write(char *buf) |
| 4559 | { |
| 4560 | char *cmd; |
| 4561 | int i, v; |
| 4562 | |
| 4563 | while ((cmd = next_cmd(&buf))) { |
| 4564 | if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) { |
| 4565 | /* i and v set */ |
| 4566 | } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) { |
| 4567 | /* i and v set */ |
| 4568 | } else |
| 4569 | return -EINVAL; |
| 4570 | if (i >= 0 && i < 256 && v >= 0 && v < 256) { |
| 4571 | if (!acpi_ec_write(i, v)) |
| 4572 | return -EIO; |
| 4573 | } else |
| 4574 | return -EINVAL; |
| 4575 | } |
| 4576 | |
| 4577 | return 0; |
| 4578 | } |
| 4579 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4580 | static struct ibm_struct ecdump_driver_data = { |
| 4581 | .name = "ecdump", |
| 4582 | .read = ecdump_read, |
| 4583 | .write = ecdump_write, |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 4584 | .flags.experimental = 1, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4585 | }; |
| 4586 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4587 | /************************************************************************* |
| 4588 | * Backlight/brightness subdriver |
| 4589 | */ |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 4590 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4591 | #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen" |
| 4592 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4593 | enum { |
| 4594 | TP_EC_BACKLIGHT = 0x31, |
| 4595 | |
| 4596 | /* TP_EC_BACKLIGHT bitmasks */ |
| 4597 | TP_EC_BACKLIGHT_LVLMSK = 0x1F, |
| 4598 | TP_EC_BACKLIGHT_CMDMSK = 0xE0, |
| 4599 | TP_EC_BACKLIGHT_MAPSW = 0x20, |
| 4600 | }; |
| 4601 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 4602 | static struct backlight_device *ibm_backlight_device; |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4603 | static int brightness_mode; |
| 4604 | static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */ |
| 4605 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4606 | static struct mutex brightness_mutex; |
| 4607 | |
| 4608 | /* |
| 4609 | * ThinkPads can read brightness from two places: EC 0x31, or |
| 4610 | * CMOS NVRAM byte 0x5E, bits 0-3. |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4611 | * |
| 4612 | * EC 0x31 has the following layout |
| 4613 | * Bit 7: unknown function |
| 4614 | * Bit 6: unknown function |
| 4615 | * Bit 5: Z: honour scale changes, NZ: ignore scale changes |
| 4616 | * Bit 4: must be set to zero to avoid problems |
| 4617 | * Bit 3-0: backlight brightness level |
| 4618 | * |
| 4619 | * 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] | 4620 | */ |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4621 | static int brightness_get_raw(int *status) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4622 | { |
| 4623 | u8 lec = 0, lcmos = 0, level = 0; |
| 4624 | |
| 4625 | if (brightness_mode & 1) { |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4626 | if (!acpi_ec_read(TP_EC_BACKLIGHT, &lec)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4627 | return -EIO; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4628 | level = lec & TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4629 | }; |
| 4630 | if (brightness_mode & 2) { |
| 4631 | lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) |
| 4632 | & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 4633 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 4634 | lcmos &= (tp_features.bright_16levels)? 0x0f : 0x07; |
| 4635 | level = lcmos; |
| 4636 | } |
| 4637 | |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 4638 | if (brightness_mode == 3) { |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4639 | *status = lec; /* Prefer EC, CMOS is just a backing store */ |
| 4640 | lec &= TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 4641 | if (lec == lcmos) |
| 4642 | tp_warned.bright_cmos_ec_unsync = 0; |
| 4643 | else { |
| 4644 | if (!tp_warned.bright_cmos_ec_unsync) { |
| 4645 | printk(TPACPI_ERR |
| 4646 | "CMOS NVRAM (%u) and EC (%u) do not " |
| 4647 | "agree on display brightness level\n", |
| 4648 | (unsigned int) lcmos, |
| 4649 | (unsigned int) lec); |
| 4650 | tp_warned.bright_cmos_ec_unsync = 1; |
| 4651 | } |
| 4652 | return -EIO; |
| 4653 | } |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4654 | } else { |
| 4655 | *status = level; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4656 | } |
| 4657 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4658 | return 0; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4659 | } |
| 4660 | |
| 4661 | /* May return EINTR which can always be mapped to ERESTARTSYS */ |
| 4662 | static int brightness_set(int value) |
| 4663 | { |
| 4664 | int cmos_cmd, inc, i, res; |
| 4665 | int current_value; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4666 | int command_bits; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4667 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4668 | if (value > ((tp_features.bright_16levels)? 15 : 7) || |
| 4669 | value < 0) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4670 | return -EINVAL; |
| 4671 | |
| 4672 | res = mutex_lock_interruptible(&brightness_mutex); |
| 4673 | if (res < 0) |
| 4674 | return res; |
| 4675 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4676 | res = brightness_get_raw(¤t_value); |
| 4677 | if (res < 0) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4678 | goto errout; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4679 | |
| 4680 | command_bits = current_value & TP_EC_BACKLIGHT_CMDMSK; |
| 4681 | current_value &= TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4682 | |
| 4683 | cmos_cmd = value > current_value ? |
| 4684 | TP_CMOS_BRIGHTNESS_UP : |
| 4685 | TP_CMOS_BRIGHTNESS_DOWN; |
| 4686 | inc = (value > current_value)? 1 : -1; |
| 4687 | |
| 4688 | res = 0; |
| 4689 | for (i = current_value; i != value; i += inc) { |
| 4690 | if ((brightness_mode & 2) && |
| 4691 | issue_thinkpad_cmos_command(cmos_cmd)) { |
| 4692 | res = -EIO; |
| 4693 | goto errout; |
| 4694 | } |
| 4695 | if ((brightness_mode & 1) && |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4696 | !acpi_ec_write(TP_EC_BACKLIGHT, |
| 4697 | (i + inc) | command_bits)) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4698 | res = -EIO; |
| 4699 | goto errout;; |
| 4700 | } |
| 4701 | } |
| 4702 | |
| 4703 | errout: |
| 4704 | mutex_unlock(&brightness_mutex); |
| 4705 | return res; |
| 4706 | } |
| 4707 | |
| 4708 | /* sysfs backlight class ----------------------------------------------- */ |
| 4709 | |
| 4710 | static int brightness_update_status(struct backlight_device *bd) |
| 4711 | { |
| 4712 | /* it is the backlight class's job (caller) to handle |
| 4713 | * EINTR and other errors properly */ |
| 4714 | return brightness_set( |
| 4715 | (bd->props.fb_blank == FB_BLANK_UNBLANK && |
| 4716 | bd->props.power == FB_BLANK_UNBLANK) ? |
| 4717 | bd->props.brightness : 0); |
| 4718 | } |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 4719 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4720 | static int brightness_get(struct backlight_device *bd) |
| 4721 | { |
| 4722 | int status, res; |
| 4723 | |
| 4724 | res = brightness_get_raw(&status); |
| 4725 | if (res < 0) |
| 4726 | return 0; /* FIXME: teach backlight about error handling */ |
| 4727 | |
| 4728 | return status & TP_EC_BACKLIGHT_LVLMSK; |
| 4729 | } |
| 4730 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 4731 | static struct backlight_ops ibm_backlight_data = { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4732 | .get_brightness = brightness_get, |
| 4733 | .update_status = brightness_update_status, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4734 | }; |
| 4735 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4736 | /* --------------------------------------------------------------------- */ |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 4737 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4738 | static int __init brightness_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4739 | { |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 4740 | int b; |
| 4741 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4742 | vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); |
| 4743 | |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 4744 | mutex_init(&brightness_mutex); |
| 4745 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 4746 | /* |
| 4747 | * We always attempt to detect acpi support, so as to switch |
| 4748 | * Lenovo Vista BIOS to ACPI brightness mode even if we are not |
| 4749 | * going to publish a backlight interface |
| 4750 | */ |
| 4751 | b = tpacpi_check_std_acpi_brightness_support(); |
| 4752 | if (b > 0) { |
| 4753 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) { |
| 4754 | printk(TPACPI_NOTICE |
| 4755 | "Lenovo BIOS switched to ACPI backlight " |
| 4756 | "control mode\n"); |
| 4757 | } |
| 4758 | if (brightness_enable > 1) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4759 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4760 | "standard ACPI backlight interface " |
| 4761 | "available, not loading native one...\n"); |
Henrique de Moraes Holschuh | e11e211 | 2007-10-30 17:46:22 -0200 | [diff] [blame] | 4762 | return 1; |
| 4763 | } |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 4764 | } |
| 4765 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 4766 | if (!brightness_enable) { |
| 4767 | dbg_printk(TPACPI_DBG_INIT, |
| 4768 | "brightness support disabled by " |
| 4769 | "module parameter\n"); |
| 4770 | return 1; |
| 4771 | } |
| 4772 | |
| 4773 | if (b > 16) { |
| 4774 | printk(TPACPI_ERR |
| 4775 | "Unsupported brightness interface, " |
| 4776 | "please contact %s\n", TPACPI_MAIL); |
| 4777 | return 1; |
| 4778 | } |
| 4779 | if (b == 16) |
| 4780 | tp_features.bright_16levels = 1; |
| 4781 | |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4782 | if (!brightness_mode) { |
| 4783 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) |
| 4784 | brightness_mode = 2; |
| 4785 | else |
| 4786 | brightness_mode = 3; |
| 4787 | |
| 4788 | dbg_printk(TPACPI_DBG_INIT, "selected brightness_mode=%d\n", |
| 4789 | brightness_mode); |
| 4790 | } |
| 4791 | |
| 4792 | if (brightness_mode > 3) |
| 4793 | return -EINVAL; |
| 4794 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4795 | if (brightness_get_raw(&b) < 0) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4796 | return 1; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 4797 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4798 | if (tp_features.bright_16levels) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4799 | printk(TPACPI_INFO |
| 4800 | "detected a 16-level brightness capable ThinkPad\n"); |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4801 | |
Henrique de Moraes Holschuh | 7d5a015 | 2007-04-24 11:48:20 -0300 | [diff] [blame] | 4802 | ibm_backlight_device = backlight_device_register( |
| 4803 | TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL, |
| 4804 | &ibm_backlight_data); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4805 | if (IS_ERR(ibm_backlight_device)) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4806 | printk(TPACPI_ERR "Could not register backlight device\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4807 | return PTR_ERR(ibm_backlight_device); |
| 4808 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4809 | vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4810 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4811 | ibm_backlight_device->props.max_brightness = |
| 4812 | (tp_features.bright_16levels)? 15 : 7; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4813 | ibm_backlight_device->props.brightness = b & TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 4814 | backlight_update_status(ibm_backlight_device); |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 4815 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4816 | return 0; |
| 4817 | } |
| 4818 | |
| 4819 | static void brightness_exit(void) |
| 4820 | { |
| 4821 | if (ibm_backlight_device) { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4822 | vdbg_printk(TPACPI_DBG_EXIT, |
| 4823 | "calling backlight_device_unregister()\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4824 | backlight_device_unregister(ibm_backlight_device); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4825 | } |
| 4826 | } |
| 4827 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4828 | static int brightness_read(char *p) |
| 4829 | { |
| 4830 | int len = 0; |
| 4831 | int level; |
| 4832 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4833 | level = brightness_get(NULL); |
| 4834 | if (level < 0) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4835 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 4836 | } else { |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4837 | len += sprintf(p + len, "level:\t\t%d\n", level); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4838 | len += sprintf(p + len, "commands:\tup, down\n"); |
| 4839 | len += sprintf(p + len, "commands:\tlevel <level>" |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4840 | " (<level> is 0-%d)\n", |
| 4841 | (tp_features.bright_16levels) ? 15 : 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4842 | } |
| 4843 | |
| 4844 | return len; |
| 4845 | } |
| 4846 | |
| 4847 | static int brightness_write(char *buf) |
| 4848 | { |
| 4849 | int level; |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4850 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4851 | char *cmd; |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4852 | int max_level = (tp_features.bright_16levels) ? 15 : 7; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4853 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4854 | level = brightness_get(NULL); |
| 4855 | if (level < 0) |
| 4856 | return level; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4857 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4858 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4859 | if (strlencmp(cmd, "up") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4860 | if (level < max_level) |
| 4861 | level++; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4862 | } else if (strlencmp(cmd, "down") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4863 | if (level > 0) |
| 4864 | level--; |
| 4865 | } else if (sscanf(cmd, "level %d", &level) == 1 && |
| 4866 | level >= 0 && level <= max_level) { |
| 4867 | /* new level set */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4868 | } else |
| 4869 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4870 | } |
| 4871 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4872 | /* |
| 4873 | * Now we know what the final level should be, so we try to set it. |
| 4874 | * Doing it this way makes the syscall restartable in case of EINTR |
| 4875 | */ |
| 4876 | rc = brightness_set(level); |
| 4877 | return (rc == -EINTR)? ERESTARTSYS : rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4878 | } |
| 4879 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4880 | static struct ibm_struct brightness_driver_data = { |
| 4881 | .name = "brightness", |
| 4882 | .read = brightness_read, |
| 4883 | .write = brightness_write, |
| 4884 | .exit = brightness_exit, |
| 4885 | }; |
| 4886 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4887 | /************************************************************************* |
| 4888 | * Volume subdriver |
| 4889 | */ |
| 4890 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4891 | static int volume_offset = 0x30; |
| 4892 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4893 | static int volume_read(char *p) |
| 4894 | { |
| 4895 | int len = 0; |
| 4896 | u8 level; |
| 4897 | |
| 4898 | if (!acpi_ec_read(volume_offset, &level)) { |
| 4899 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 4900 | } else { |
| 4901 | len += sprintf(p + len, "level:\t\t%d\n", level & 0xf); |
| 4902 | len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6)); |
| 4903 | len += sprintf(p + len, "commands:\tup, down, mute\n"); |
| 4904 | len += sprintf(p + len, "commands:\tlevel <level>" |
| 4905 | " (<level> is 0-15)\n"); |
| 4906 | } |
| 4907 | |
| 4908 | return len; |
| 4909 | } |
| 4910 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4911 | static int volume_write(char *buf) |
| 4912 | { |
| 4913 | int cmos_cmd, inc, i; |
| 4914 | u8 level, mute; |
| 4915 | int new_level, new_mute; |
| 4916 | char *cmd; |
| 4917 | |
| 4918 | while ((cmd = next_cmd(&buf))) { |
| 4919 | if (!acpi_ec_read(volume_offset, &level)) |
| 4920 | return -EIO; |
| 4921 | new_mute = mute = level & 0x40; |
| 4922 | new_level = level = level & 0xf; |
| 4923 | |
| 4924 | if (strlencmp(cmd, "up") == 0) { |
| 4925 | if (mute) |
| 4926 | new_mute = 0; |
| 4927 | else |
| 4928 | new_level = level == 15 ? 15 : level + 1; |
| 4929 | } else if (strlencmp(cmd, "down") == 0) { |
| 4930 | if (mute) |
| 4931 | new_mute = 0; |
| 4932 | else |
| 4933 | new_level = level == 0 ? 0 : level - 1; |
| 4934 | } else if (sscanf(cmd, "level %d", &new_level) == 1 && |
| 4935 | new_level >= 0 && new_level <= 15) { |
| 4936 | /* new_level set */ |
| 4937 | } else if (strlencmp(cmd, "mute") == 0) { |
| 4938 | new_mute = 0x40; |
| 4939 | } else |
| 4940 | return -EINVAL; |
| 4941 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4942 | if (new_level != level) { |
| 4943 | /* mute doesn't change */ |
| 4944 | |
| 4945 | cmos_cmd = (new_level > level) ? |
| 4946 | TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4947 | inc = new_level > level ? 1 : -1; |
| 4948 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4949 | if (mute && (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))) |
| 4951 | return -EIO; |
| 4952 | |
| 4953 | for (i = level; i != new_level; i += inc) |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4954 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4955 | !acpi_ec_write(volume_offset, i + inc)) |
| 4956 | return -EIO; |
| 4957 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4958 | if (mute && |
| 4959 | (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) || |
| 4960 | !acpi_ec_write(volume_offset, new_level + mute))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4961 | return -EIO; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4962 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4963 | } |
| 4964 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4965 | if (new_mute != mute) { |
| 4966 | /* level doesn't change */ |
| 4967 | |
| 4968 | cmos_cmd = (new_mute) ? |
| 4969 | TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4970 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4971 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4972 | !acpi_ec_write(volume_offset, level + new_mute)) |
| 4973 | return -EIO; |
| 4974 | } |
| 4975 | } |
| 4976 | |
| 4977 | return 0; |
| 4978 | } |
| 4979 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4980 | static struct ibm_struct volume_driver_data = { |
| 4981 | .name = "volume", |
| 4982 | .read = volume_read, |
| 4983 | .write = volume_write, |
| 4984 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4985 | |
| 4986 | /************************************************************************* |
| 4987 | * Fan subdriver |
| 4988 | */ |
| 4989 | |
| 4990 | /* |
| 4991 | * FAN ACCESS MODES |
| 4992 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4993 | * TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4994 | * ACPI GFAN method: returns fan level |
| 4995 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4996 | * see TPACPI_FAN_WR_ACPI_SFAN |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4997 | * EC 0x2f (HFSP) not available if GFAN exists |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4998 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4999 | * TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5000 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) |
| 5001 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 5002 | * EC 0x2f (HFSP) might be available *for reading*, but do not use |
| 5003 | * it for writing. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5004 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5005 | * TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 5006 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode |
| 5007 | * Supported on almost all ThinkPads |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5008 | * |
| 5009 | * Fan speed changes of any sort (including those caused by the |
| 5010 | * disengaged mode) are usually done slowly by the firmware as the |
| 5011 | * maximum ammount of fan duty cycle change per second seems to be |
| 5012 | * limited. |
| 5013 | * |
| 5014 | * Reading is not available if GFAN exists. |
| 5015 | * Writing is not available if SFAN exists. |
| 5016 | * |
| 5017 | * Bits |
| 5018 | * 7 automatic mode engaged; |
| 5019 | * (default operation mode of the ThinkPad) |
| 5020 | * fan level is ignored in this mode. |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 5021 | * 6 full speed mode (takes precedence over bit 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5022 | * not available on all thinkpads. May disable |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 5023 | * the tachometer while the fan controller ramps up |
| 5024 | * the speed (which can take up to a few *minutes*). |
| 5025 | * Speeds up fan to 100% duty-cycle, which is far above |
| 5026 | * the standard RPM levels. It is not impossible that |
| 5027 | * it could cause hardware damage. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5028 | * 5-3 unused in some models. Extra bits for fan level |
| 5029 | * in others, but still useless as all values above |
| 5030 | * 7 map to the same speed as level 7 in these models. |
| 5031 | * 2-0 fan level (0..7 usually) |
| 5032 | * 0x00 = stop |
| 5033 | * 0x07 = max (set when temperatures critical) |
| 5034 | * Some ThinkPads may have other levels, see |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5035 | * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5036 | * |
| 5037 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at |
| 5038 | * boot. Apparently the EC does not intialize it, so unless ACPI DSDT |
| 5039 | * does so, its initial value is meaningless (0x07). |
| 5040 | * |
| 5041 | * For firmware bugs, refer to: |
| 5042 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 5043 | * |
| 5044 | * ---- |
| 5045 | * |
| 5046 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): |
| 5047 | * Main fan tachometer reading (in RPM) |
| 5048 | * |
| 5049 | * This register is present on all ThinkPads with a new-style EC, and |
| 5050 | * it is known not to be present on the A21m/e, and T22, as there is |
| 5051 | * something else in offset 0x84 according to the ACPI DSDT. Other |
| 5052 | * ThinkPads from this same time period (and earlier) probably lack the |
| 5053 | * tachometer as well. |
| 5054 | * |
| 5055 | * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare |
| 5056 | * was never fixed by IBM to report the EC firmware version string |
| 5057 | * probably support the tachometer (like the early X models), so |
| 5058 | * detecting it is quite hard. We need more data to know for sure. |
| 5059 | * |
| 5060 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings |
| 5061 | * might result. |
| 5062 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 5063 | * FIRMWARE BUG: may go stale while the EC is switching to full speed |
| 5064 | * mode. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5065 | * |
| 5066 | * For firmware bugs, refer to: |
| 5067 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 5068 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5069 | * TPACPI_FAN_WR_ACPI_FANS: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5070 | * ThinkPad X31, X40, X41. Not available in the X60. |
| 5071 | * |
| 5072 | * FANS ACPI handle: takes three arguments: low speed, medium speed, |
| 5073 | * high speed. ACPI DSDT seems to map these three speeds to levels |
| 5074 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH |
| 5075 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") |
| 5076 | * |
| 5077 | * The speeds are stored on handles |
| 5078 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). |
| 5079 | * |
| 5080 | * There are three default speed sets, acessible as handles: |
| 5081 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H |
| 5082 | * |
| 5083 | * ACPI DSDT switches which set is in use depending on various |
| 5084 | * factors. |
| 5085 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5086 | * 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] | 5087 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, |
| 5088 | * but the ACPI tables just mention level 7. |
| 5089 | */ |
| 5090 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5091 | enum { /* Fan control constants */ |
| 5092 | fan_status_offset = 0x2f, /* EC register 0x2f */ |
| 5093 | fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM) |
| 5094 | * 0x84 must be read before 0x85 */ |
| 5095 | |
| 5096 | TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */ |
| 5097 | TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */ |
| 5098 | |
| 5099 | TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */ |
| 5100 | }; |
| 5101 | |
| 5102 | enum fan_status_access_mode { |
| 5103 | TPACPI_FAN_NONE = 0, /* No fan status or control */ |
| 5104 | TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */ |
| 5105 | TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */ |
| 5106 | }; |
| 5107 | |
| 5108 | enum fan_control_access_mode { |
| 5109 | TPACPI_FAN_WR_NONE = 0, /* No fan control */ |
| 5110 | TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */ |
| 5111 | TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */ |
| 5112 | TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */ |
| 5113 | }; |
| 5114 | |
| 5115 | enum fan_control_commands { |
| 5116 | TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */ |
| 5117 | TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */ |
| 5118 | TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd, |
| 5119 | * and also watchdog cmd */ |
| 5120 | }; |
| 5121 | |
| 5122 | static int fan_control_allowed; |
| 5123 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5124 | static enum fan_status_access_mode fan_status_access_mode; |
| 5125 | static enum fan_control_access_mode fan_control_access_mode; |
| 5126 | static enum fan_control_commands fan_control_commands; |
| 5127 | |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5128 | static u8 fan_control_initial_status; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5129 | static u8 fan_control_desired_level; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5130 | static int fan_watchdog_maxinterval; |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5131 | |
| 5132 | static struct mutex fan_mutex; |
| 5133 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5134 | static void fan_watchdog_fire(struct work_struct *ignored); |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 5135 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5136 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5137 | TPACPI_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
| 5138 | TPACPI_HANDLE(gfan, ec, "GFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5139 | "\\FSPD", /* 600e/x, 770e, 770x */ |
| 5140 | ); /* all others */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5141 | TPACPI_HANDLE(sfan, ec, "SFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5142 | "JFNS", /* 770x-JL */ |
| 5143 | ); /* all others */ |
| 5144 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5145 | /* |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5146 | * Call with fan_mutex held |
| 5147 | */ |
| 5148 | static void fan_update_desired_level(u8 status) |
| 5149 | { |
| 5150 | if ((status & |
| 5151 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 5152 | if (status > 7) |
| 5153 | fan_control_desired_level = 7; |
| 5154 | else |
| 5155 | fan_control_desired_level = status; |
| 5156 | } |
| 5157 | } |
| 5158 | |
| 5159 | static int fan_get_status(u8 *status) |
| 5160 | { |
| 5161 | u8 s; |
| 5162 | |
| 5163 | /* TODO: |
| 5164 | * Add TPACPI_FAN_RD_ACPI_FANS ? */ |
| 5165 | |
| 5166 | switch (fan_status_access_mode) { |
| 5167 | case TPACPI_FAN_RD_ACPI_GFAN: |
| 5168 | /* 570, 600e/x, 770e, 770x */ |
| 5169 | |
| 5170 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) |
| 5171 | return -EIO; |
| 5172 | |
| 5173 | if (likely(status)) |
| 5174 | *status = s & 0x07; |
| 5175 | |
| 5176 | break; |
| 5177 | |
| 5178 | case TPACPI_FAN_RD_TPEC: |
| 5179 | /* all except 570, 600e/x, 770e, 770x */ |
| 5180 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) |
| 5181 | return -EIO; |
| 5182 | |
| 5183 | if (likely(status)) |
| 5184 | *status = s; |
| 5185 | |
| 5186 | break; |
| 5187 | |
| 5188 | default: |
| 5189 | return -ENXIO; |
| 5190 | } |
| 5191 | |
| 5192 | return 0; |
| 5193 | } |
| 5194 | |
| 5195 | static int fan_get_status_safe(u8 *status) |
| 5196 | { |
| 5197 | int rc; |
| 5198 | u8 s; |
| 5199 | |
| 5200 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5201 | return -ERESTARTSYS; |
| 5202 | rc = fan_get_status(&s); |
| 5203 | if (!rc) |
| 5204 | fan_update_desired_level(s); |
| 5205 | mutex_unlock(&fan_mutex); |
| 5206 | |
| 5207 | if (status) |
| 5208 | *status = s; |
| 5209 | |
| 5210 | return rc; |
| 5211 | } |
| 5212 | |
| 5213 | static int fan_get_speed(unsigned int *speed) |
| 5214 | { |
| 5215 | u8 hi, lo; |
| 5216 | |
| 5217 | switch (fan_status_access_mode) { |
| 5218 | case TPACPI_FAN_RD_TPEC: |
| 5219 | /* all except 570, 600e/x, 770e, 770x */ |
| 5220 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
| 5221 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) |
| 5222 | return -EIO; |
| 5223 | |
| 5224 | if (likely(speed)) |
| 5225 | *speed = (hi << 8) | lo; |
| 5226 | |
| 5227 | break; |
| 5228 | |
| 5229 | default: |
| 5230 | return -ENXIO; |
| 5231 | } |
| 5232 | |
| 5233 | return 0; |
| 5234 | } |
| 5235 | |
| 5236 | static int fan_set_level(int level) |
| 5237 | { |
| 5238 | if (!fan_control_allowed) |
| 5239 | return -EPERM; |
| 5240 | |
| 5241 | switch (fan_control_access_mode) { |
| 5242 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 5243 | if (level >= 0 && level <= 7) { |
| 5244 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) |
| 5245 | return -EIO; |
| 5246 | } else |
| 5247 | return -EINVAL; |
| 5248 | break; |
| 5249 | |
| 5250 | case TPACPI_FAN_WR_ACPI_FANS: |
| 5251 | case TPACPI_FAN_WR_TPEC: |
| 5252 | if ((level != TP_EC_FAN_AUTO) && |
| 5253 | (level != TP_EC_FAN_FULLSPEED) && |
| 5254 | ((level < 0) || (level > 7))) |
| 5255 | return -EINVAL; |
| 5256 | |
| 5257 | /* safety net should the EC not support AUTO |
| 5258 | * or FULLSPEED mode bits and just ignore them */ |
| 5259 | if (level & TP_EC_FAN_FULLSPEED) |
| 5260 | level |= 7; /* safety min speed 7 */ |
Roel Kluin | 547266e | 2008-02-05 00:24:56 +0100 | [diff] [blame] | 5261 | else if (level & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5262 | level |= 4; /* safety min speed 4 */ |
| 5263 | |
| 5264 | if (!acpi_ec_write(fan_status_offset, level)) |
| 5265 | return -EIO; |
| 5266 | else |
| 5267 | tp_features.fan_ctrl_status_undef = 0; |
| 5268 | break; |
| 5269 | |
| 5270 | default: |
| 5271 | return -ENXIO; |
| 5272 | } |
| 5273 | return 0; |
| 5274 | } |
| 5275 | |
| 5276 | static int fan_set_level_safe(int level) |
| 5277 | { |
| 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 | if (level == TPACPI_FAN_LAST_LEVEL) |
| 5287 | level = fan_control_desired_level; |
| 5288 | |
| 5289 | rc = fan_set_level(level); |
| 5290 | if (!rc) |
| 5291 | fan_update_desired_level(level); |
| 5292 | |
| 5293 | mutex_unlock(&fan_mutex); |
| 5294 | return rc; |
| 5295 | } |
| 5296 | |
| 5297 | static int fan_set_enable(void) |
| 5298 | { |
| 5299 | u8 s; |
| 5300 | int rc; |
| 5301 | |
| 5302 | if (!fan_control_allowed) |
| 5303 | return -EPERM; |
| 5304 | |
| 5305 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5306 | return -ERESTARTSYS; |
| 5307 | |
| 5308 | switch (fan_control_access_mode) { |
| 5309 | case TPACPI_FAN_WR_ACPI_FANS: |
| 5310 | case TPACPI_FAN_WR_TPEC: |
| 5311 | rc = fan_get_status(&s); |
| 5312 | if (rc < 0) |
| 5313 | break; |
| 5314 | |
| 5315 | /* Don't go out of emergency fan mode */ |
| 5316 | if (s != 7) { |
| 5317 | s &= 0x07; |
| 5318 | s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */ |
| 5319 | } |
| 5320 | |
| 5321 | if (!acpi_ec_write(fan_status_offset, s)) |
| 5322 | rc = -EIO; |
| 5323 | else { |
| 5324 | tp_features.fan_ctrl_status_undef = 0; |
| 5325 | rc = 0; |
| 5326 | } |
| 5327 | break; |
| 5328 | |
| 5329 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 5330 | rc = fan_get_status(&s); |
| 5331 | if (rc < 0) |
| 5332 | break; |
| 5333 | |
| 5334 | s &= 0x07; |
| 5335 | |
| 5336 | /* Set fan to at least level 4 */ |
| 5337 | s |= 4; |
| 5338 | |
| 5339 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5340 | rc = -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5341 | else |
| 5342 | rc = 0; |
| 5343 | break; |
| 5344 | |
| 5345 | default: |
| 5346 | rc = -ENXIO; |
| 5347 | } |
| 5348 | |
| 5349 | mutex_unlock(&fan_mutex); |
| 5350 | return rc; |
| 5351 | } |
| 5352 | |
| 5353 | static int fan_set_disable(void) |
| 5354 | { |
| 5355 | int rc; |
| 5356 | |
| 5357 | if (!fan_control_allowed) |
| 5358 | return -EPERM; |
| 5359 | |
| 5360 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5361 | return -ERESTARTSYS; |
| 5362 | |
| 5363 | rc = 0; |
| 5364 | switch (fan_control_access_mode) { |
| 5365 | case TPACPI_FAN_WR_ACPI_FANS: |
| 5366 | case TPACPI_FAN_WR_TPEC: |
| 5367 | if (!acpi_ec_write(fan_status_offset, 0x00)) |
| 5368 | rc = -EIO; |
| 5369 | else { |
| 5370 | fan_control_desired_level = 0; |
| 5371 | tp_features.fan_ctrl_status_undef = 0; |
| 5372 | } |
| 5373 | break; |
| 5374 | |
| 5375 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 5376 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) |
| 5377 | rc = -EIO; |
| 5378 | else |
| 5379 | fan_control_desired_level = 0; |
| 5380 | break; |
| 5381 | |
| 5382 | default: |
| 5383 | rc = -ENXIO; |
| 5384 | } |
| 5385 | |
| 5386 | |
| 5387 | mutex_unlock(&fan_mutex); |
| 5388 | return rc; |
| 5389 | } |
| 5390 | |
| 5391 | static int fan_set_speed(int speed) |
| 5392 | { |
| 5393 | int rc; |
| 5394 | |
| 5395 | if (!fan_control_allowed) |
| 5396 | return -EPERM; |
| 5397 | |
| 5398 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5399 | return -ERESTARTSYS; |
| 5400 | |
| 5401 | rc = 0; |
| 5402 | switch (fan_control_access_mode) { |
| 5403 | case TPACPI_FAN_WR_ACPI_FANS: |
| 5404 | if (speed >= 0 && speed <= 65535) { |
| 5405 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", |
| 5406 | speed, speed, speed)) |
| 5407 | rc = -EIO; |
| 5408 | } else |
| 5409 | rc = -EINVAL; |
| 5410 | break; |
| 5411 | |
| 5412 | default: |
| 5413 | rc = -ENXIO; |
| 5414 | } |
| 5415 | |
| 5416 | mutex_unlock(&fan_mutex); |
| 5417 | return rc; |
| 5418 | } |
| 5419 | |
| 5420 | static void fan_watchdog_reset(void) |
| 5421 | { |
| 5422 | static int fan_watchdog_active; |
| 5423 | |
| 5424 | if (fan_control_access_mode == TPACPI_FAN_WR_NONE) |
| 5425 | return; |
| 5426 | |
| 5427 | if (fan_watchdog_active) |
| 5428 | cancel_delayed_work(&fan_watchdog_task); |
| 5429 | |
| 5430 | if (fan_watchdog_maxinterval > 0 && |
| 5431 | tpacpi_lifecycle != TPACPI_LIFE_EXITING) { |
| 5432 | fan_watchdog_active = 1; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 5433 | if (!queue_delayed_work(tpacpi_wq, &fan_watchdog_task, |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5434 | msecs_to_jiffies(fan_watchdog_maxinterval |
| 5435 | * 1000))) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5436 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 5437 | "failed to queue the fan watchdog, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5438 | "watchdog will not trigger\n"); |
| 5439 | } |
| 5440 | } else |
| 5441 | fan_watchdog_active = 0; |
| 5442 | } |
| 5443 | |
| 5444 | static void fan_watchdog_fire(struct work_struct *ignored) |
| 5445 | { |
| 5446 | int rc; |
| 5447 | |
| 5448 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 5449 | return; |
| 5450 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5451 | printk(TPACPI_NOTICE "fan watchdog: enabling fan\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5452 | rc = fan_set_enable(); |
| 5453 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5454 | printk(TPACPI_ERR "fan watchdog: error %d while enabling fan, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5455 | "will try again later...\n", -rc); |
| 5456 | /* reschedule for later */ |
| 5457 | fan_watchdog_reset(); |
| 5458 | } |
| 5459 | } |
| 5460 | |
| 5461 | /* |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5462 | * SYSFS fan layout: hwmon compatible (device) |
| 5463 | * |
| 5464 | * pwm*_enable: |
| 5465 | * 0: "disengaged" mode |
| 5466 | * 1: manual mode |
| 5467 | * 2: native EC "auto" mode (recommended, hardware default) |
| 5468 | * |
| 5469 | * pwm*: set speed in manual mode, ignored otherwise. |
| 5470 | * 0 is level 0; 255 is level 7. Intermediate points done with linear |
| 5471 | * interpolation. |
| 5472 | * |
| 5473 | * fan*_input: tachometer reading, RPM |
| 5474 | * |
| 5475 | * |
| 5476 | * SYSFS fan layout: extensions |
| 5477 | * |
| 5478 | * fan_watchdog (driver): |
| 5479 | * fan watchdog interval in seconds, 0 disables (default), max 120 |
| 5480 | */ |
| 5481 | |
| 5482 | /* sysfs fan pwm1_enable ----------------------------------------------- */ |
| 5483 | static ssize_t fan_pwm1_enable_show(struct device *dev, |
| 5484 | struct device_attribute *attr, |
| 5485 | char *buf) |
| 5486 | { |
| 5487 | int res, mode; |
| 5488 | u8 status; |
| 5489 | |
| 5490 | res = fan_get_status_safe(&status); |
| 5491 | if (res) |
| 5492 | return res; |
| 5493 | |
| 5494 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 5495 | if (status != fan_control_initial_status) { |
| 5496 | tp_features.fan_ctrl_status_undef = 0; |
| 5497 | } else { |
| 5498 | /* Return most likely status. In fact, it |
| 5499 | * might be the only possible status */ |
| 5500 | status = TP_EC_FAN_AUTO; |
| 5501 | } |
| 5502 | } |
| 5503 | |
| 5504 | if (status & TP_EC_FAN_FULLSPEED) { |
| 5505 | mode = 0; |
| 5506 | } else if (status & TP_EC_FAN_AUTO) { |
| 5507 | mode = 2; |
| 5508 | } else |
| 5509 | mode = 1; |
| 5510 | |
| 5511 | return snprintf(buf, PAGE_SIZE, "%d\n", mode); |
| 5512 | } |
| 5513 | |
| 5514 | static ssize_t fan_pwm1_enable_store(struct device *dev, |
| 5515 | struct device_attribute *attr, |
| 5516 | const char *buf, size_t count) |
| 5517 | { |
| 5518 | unsigned long t; |
| 5519 | int res, level; |
| 5520 | |
| 5521 | if (parse_strtoul(buf, 2, &t)) |
| 5522 | return -EINVAL; |
| 5523 | |
| 5524 | switch (t) { |
| 5525 | case 0: |
| 5526 | level = TP_EC_FAN_FULLSPEED; |
| 5527 | break; |
| 5528 | case 1: |
| 5529 | level = TPACPI_FAN_LAST_LEVEL; |
| 5530 | break; |
| 5531 | case 2: |
| 5532 | level = TP_EC_FAN_AUTO; |
| 5533 | break; |
| 5534 | case 3: |
| 5535 | /* reserved for software-controlled auto mode */ |
| 5536 | return -ENOSYS; |
| 5537 | default: |
| 5538 | return -EINVAL; |
| 5539 | } |
| 5540 | |
| 5541 | res = fan_set_level_safe(level); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 5542 | if (res == -ENXIO) |
| 5543 | return -EINVAL; |
| 5544 | else if (res < 0) |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5545 | return res; |
| 5546 | |
| 5547 | fan_watchdog_reset(); |
| 5548 | |
| 5549 | return count; |
| 5550 | } |
| 5551 | |
| 5552 | static struct device_attribute dev_attr_fan_pwm1_enable = |
| 5553 | __ATTR(pwm1_enable, S_IWUSR | S_IRUGO, |
| 5554 | fan_pwm1_enable_show, fan_pwm1_enable_store); |
| 5555 | |
| 5556 | /* sysfs fan pwm1 ------------------------------------------------------ */ |
| 5557 | static ssize_t fan_pwm1_show(struct device *dev, |
| 5558 | struct device_attribute *attr, |
| 5559 | char *buf) |
| 5560 | { |
| 5561 | int res; |
| 5562 | u8 status; |
| 5563 | |
| 5564 | res = fan_get_status_safe(&status); |
| 5565 | if (res) |
| 5566 | return res; |
| 5567 | |
| 5568 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 5569 | if (status != fan_control_initial_status) { |
| 5570 | tp_features.fan_ctrl_status_undef = 0; |
| 5571 | } else { |
| 5572 | status = TP_EC_FAN_AUTO; |
| 5573 | } |
| 5574 | } |
| 5575 | |
| 5576 | if ((status & |
| 5577 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0) |
| 5578 | status = fan_control_desired_level; |
| 5579 | |
| 5580 | if (status > 7) |
| 5581 | status = 7; |
| 5582 | |
| 5583 | return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7); |
| 5584 | } |
| 5585 | |
| 5586 | static ssize_t fan_pwm1_store(struct device *dev, |
| 5587 | struct device_attribute *attr, |
| 5588 | const char *buf, size_t count) |
| 5589 | { |
| 5590 | unsigned long s; |
| 5591 | int rc; |
| 5592 | u8 status, newlevel; |
| 5593 | |
| 5594 | if (parse_strtoul(buf, 255, &s)) |
| 5595 | return -EINVAL; |
| 5596 | |
| 5597 | /* scale down from 0-255 to 0-7 */ |
| 5598 | newlevel = (s >> 5) & 0x07; |
| 5599 | |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 5600 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5601 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5602 | |
| 5603 | rc = fan_get_status(&status); |
| 5604 | if (!rc && (status & |
| 5605 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 5606 | rc = fan_set_level(newlevel); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 5607 | if (rc == -ENXIO) |
| 5608 | rc = -EINVAL; |
| 5609 | else if (!rc) { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5610 | fan_update_desired_level(newlevel); |
Henrique de Moraes Holschuh | ca4ac2f | 2007-04-27 22:00:11 -0300 | [diff] [blame] | 5611 | fan_watchdog_reset(); |
| 5612 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5613 | } |
| 5614 | |
| 5615 | mutex_unlock(&fan_mutex); |
| 5616 | return (rc)? rc : count; |
| 5617 | } |
| 5618 | |
| 5619 | static struct device_attribute dev_attr_fan_pwm1 = |
| 5620 | __ATTR(pwm1, S_IWUSR | S_IRUGO, |
| 5621 | fan_pwm1_show, fan_pwm1_store); |
| 5622 | |
| 5623 | /* sysfs fan fan1_input ------------------------------------------------ */ |
| 5624 | static ssize_t fan_fan1_input_show(struct device *dev, |
| 5625 | struct device_attribute *attr, |
| 5626 | char *buf) |
| 5627 | { |
| 5628 | int res; |
| 5629 | unsigned int speed; |
| 5630 | |
| 5631 | res = fan_get_speed(&speed); |
| 5632 | if (res < 0) |
| 5633 | return res; |
| 5634 | |
| 5635 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 5636 | } |
| 5637 | |
| 5638 | static struct device_attribute dev_attr_fan_fan1_input = |
| 5639 | __ATTR(fan1_input, S_IRUGO, |
| 5640 | fan_fan1_input_show, NULL); |
| 5641 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5642 | /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5643 | static ssize_t fan_fan_watchdog_show(struct device_driver *drv, |
| 5644 | char *buf) |
| 5645 | { |
| 5646 | return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval); |
| 5647 | } |
| 5648 | |
| 5649 | static ssize_t fan_fan_watchdog_store(struct device_driver *drv, |
| 5650 | const char *buf, size_t count) |
| 5651 | { |
| 5652 | unsigned long t; |
| 5653 | |
| 5654 | if (parse_strtoul(buf, 120, &t)) |
| 5655 | return -EINVAL; |
| 5656 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 5657 | if (!fan_control_allowed) |
| 5658 | return -EPERM; |
| 5659 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5660 | fan_watchdog_maxinterval = t; |
| 5661 | fan_watchdog_reset(); |
| 5662 | |
| 5663 | return count; |
| 5664 | } |
| 5665 | |
| 5666 | static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO, |
| 5667 | fan_fan_watchdog_show, fan_fan_watchdog_store); |
| 5668 | |
| 5669 | /* --------------------------------------------------------------------- */ |
| 5670 | static struct attribute *fan_attributes[] = { |
| 5671 | &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr, |
| 5672 | &dev_attr_fan_fan1_input.attr, |
| 5673 | NULL |
| 5674 | }; |
| 5675 | |
| 5676 | static const struct attribute_group fan_attr_group = { |
| 5677 | .attrs = fan_attributes, |
| 5678 | }; |
| 5679 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5680 | static int __init fan_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5681 | { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5682 | int rc; |
| 5683 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5684 | vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n"); |
| 5685 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5686 | mutex_init(&fan_mutex); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5687 | fan_status_access_mode = TPACPI_FAN_NONE; |
| 5688 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5689 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5690 | fan_watchdog_maxinterval = 0; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5691 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5692 | fan_control_desired_level = 7; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5693 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5694 | TPACPI_ACPIHANDLE_INIT(fans); |
| 5695 | TPACPI_ACPIHANDLE_INIT(gfan); |
| 5696 | TPACPI_ACPIHANDLE_INIT(sfan); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5697 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5698 | if (gfan_handle) { |
| 5699 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5700 | fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5701 | } else { |
| 5702 | /* all other ThinkPads: note that even old-style |
| 5703 | * ThinkPad ECs supports the fan control register */ |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5704 | if (likely(acpi_ec_read(fan_status_offset, |
| 5705 | &fan_control_initial_status))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5706 | fan_status_access_mode = TPACPI_FAN_RD_TPEC; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5707 | |
| 5708 | /* In some ThinkPads, neither the EC nor the ACPI |
| 5709 | * DSDT initialize the fan status, and it ends up |
| 5710 | * being set to 0x07 when it *could* be either |
| 5711 | * 0x07 or 0x80. |
| 5712 | * |
| 5713 | * Enable for TP-1Y (T43), TP-78 (R51e), |
| 5714 | * TP-76 (R52), TP-70 (T43, R52), which are known |
| 5715 | * to be buggy. */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5716 | if (fan_control_initial_status == 0x07) { |
| 5717 | switch (thinkpad_id.ec_model) { |
| 5718 | case 0x5931: /* TP-1Y */ |
| 5719 | case 0x3837: /* TP-78 */ |
| 5720 | case 0x3637: /* TP-76 */ |
| 5721 | case 0x3037: /* TP-70 */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5722 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5723 | "fan_init: initial fan status " |
| 5724 | "is unknown, assuming it is " |
| 5725 | "in auto mode\n"); |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5726 | tp_features.fan_ctrl_status_undef = 1; |
| 5727 | ;; |
| 5728 | } |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5729 | } |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5730 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5731 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5732 | "ThinkPad ACPI EC access misbehaving, " |
| 5733 | "fan status and control unavailable\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5734 | return 1; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5735 | } |
| 5736 | } |
| 5737 | |
| 5738 | if (sfan_handle) { |
| 5739 | /* 570, 770x-JL */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5740 | fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 5741 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5742 | TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5743 | } else { |
| 5744 | if (!gfan_handle) { |
| 5745 | /* gfan without sfan means no fan control */ |
| 5746 | /* all other models implement TP EC 0x2f control */ |
| 5747 | |
| 5748 | if (fans_handle) { |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5749 | /* X31, X40, X41 */ |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5750 | fan_control_access_mode = |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5751 | TPACPI_FAN_WR_ACPI_FANS; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5752 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5753 | TPACPI_FAN_CMD_SPEED | |
| 5754 | TPACPI_FAN_CMD_LEVEL | |
| 5755 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5756 | } else { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5757 | fan_control_access_mode = TPACPI_FAN_WR_TPEC; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5758 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5759 | TPACPI_FAN_CMD_LEVEL | |
| 5760 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5761 | } |
| 5762 | } |
| 5763 | } |
| 5764 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5765 | vdbg_printk(TPACPI_DBG_INIT, "fan is %s, modes %d, %d\n", |
| 5766 | str_supported(fan_status_access_mode != TPACPI_FAN_NONE || |
| 5767 | fan_control_access_mode != TPACPI_FAN_WR_NONE), |
| 5768 | fan_status_access_mode, fan_control_access_mode); |
| 5769 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 5770 | /* fan control master switch */ |
| 5771 | if (!fan_control_allowed) { |
| 5772 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
| 5773 | fan_control_commands = 0; |
| 5774 | dbg_printk(TPACPI_DBG_INIT, |
| 5775 | "fan control features disabled by parameter\n"); |
| 5776 | } |
| 5777 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5778 | /* update fan_control_desired_level */ |
| 5779 | if (fan_status_access_mode != TPACPI_FAN_NONE) |
| 5780 | fan_get_status_safe(NULL); |
| 5781 | |
| 5782 | if (fan_status_access_mode != TPACPI_FAN_NONE || |
| 5783 | fan_control_access_mode != TPACPI_FAN_WR_NONE) { |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5784 | rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5785 | &fan_attr_group); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5786 | if (rc < 0) |
| 5787 | return rc; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 5788 | |
| 5789 | rc = driver_create_file(&tpacpi_hwmon_pdriver.driver, |
| 5790 | &driver_attr_fan_watchdog); |
| 5791 | if (rc < 0) { |
| 5792 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
| 5793 | &fan_attr_group); |
| 5794 | return rc; |
| 5795 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5796 | return 0; |
| 5797 | } else |
| 5798 | return 1; |
| 5799 | } |
| 5800 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5801 | static void fan_exit(void) |
| 5802 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5803 | vdbg_printk(TPACPI_DBG_EXIT, |
| 5804 | "cancelling any pending fan watchdog tasks\n"); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5805 | |
| 5806 | /* FIXME: can we really do this unconditionally? */ |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5807 | 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] | 5808 | driver_remove_file(&tpacpi_hwmon_pdriver.driver, |
| 5809 | &driver_attr_fan_watchdog); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5810 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5811 | cancel_delayed_work(&fan_watchdog_task); |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 5812 | flush_workqueue(tpacpi_wq); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5813 | } |
| 5814 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5815 | static int fan_read(char *p) |
| 5816 | { |
| 5817 | int len = 0; |
| 5818 | int rc; |
| 5819 | u8 status; |
| 5820 | unsigned int speed = 0; |
| 5821 | |
| 5822 | switch (fan_status_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5823 | case TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5824 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5825 | rc = fan_get_status_safe(&status); |
| 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, "status:\t\t%s\n" |
| 5830 | "level:\t\t%d\n", |
| 5831 | (status != 0) ? "enabled" : "disabled", status); |
| 5832 | break; |
| 5833 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5834 | case TPACPI_FAN_RD_TPEC: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5835 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5836 | rc = fan_get_status_safe(&status); |
| 5837 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5838 | return rc; |
| 5839 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5840 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5841 | if (status != fan_control_initial_status) |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5842 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5843 | else |
| 5844 | /* Return most likely status. In fact, it |
| 5845 | * might be the only possible status */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5846 | status = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5847 | } |
| 5848 | |
| 5849 | len += sprintf(p + len, "status:\t\t%s\n", |
| 5850 | (status != 0) ? "enabled" : "disabled"); |
| 5851 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5852 | rc = fan_get_speed(&speed); |
| 5853 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5854 | return rc; |
| 5855 | |
| 5856 | len += sprintf(p + len, "speed:\t\t%d\n", speed); |
| 5857 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5858 | if (status & TP_EC_FAN_FULLSPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5859 | /* Disengaged mode takes precedence */ |
| 5860 | len += sprintf(p + len, "level:\t\tdisengaged\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5861 | else if (status & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5862 | len += sprintf(p + len, "level:\t\tauto\n"); |
| 5863 | else |
| 5864 | len += sprintf(p + len, "level:\t\t%d\n", status); |
| 5865 | break; |
| 5866 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5867 | case TPACPI_FAN_NONE: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5868 | default: |
| 5869 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 5870 | } |
| 5871 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5872 | if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5873 | len += sprintf(p + len, "commands:\tlevel <level>"); |
| 5874 | |
| 5875 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5876 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5877 | len += sprintf(p + len, " (<level> is 0-7)\n"); |
| 5878 | break; |
| 5879 | |
| 5880 | default: |
| 5881 | len += sprintf(p + len, " (<level> is 0-7, " |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5882 | "auto, disengaged, full-speed)\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5883 | break; |
| 5884 | } |
| 5885 | } |
| 5886 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5887 | if (fan_control_commands & TPACPI_FAN_CMD_ENABLE) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5888 | len += sprintf(p + len, "commands:\tenable, disable\n" |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5889 | "commands:\twatchdog <timeout> (<timeout> " |
| 5890 | "is 0 (off), 1-120 (seconds))\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5891 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5892 | if (fan_control_commands & TPACPI_FAN_CMD_SPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5893 | len += sprintf(p + len, "commands:\tspeed <speed>" |
| 5894 | " (<speed> is 0-65535)\n"); |
| 5895 | |
| 5896 | return len; |
| 5897 | } |
| 5898 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5899 | static int fan_write_cmd_level(const char *cmd, int *rc) |
| 5900 | { |
| 5901 | int level; |
| 5902 | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5903 | if (strlencmp(cmd, "level auto") == 0) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5904 | level = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5905 | else if ((strlencmp(cmd, "level disengaged") == 0) | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5906 | (strlencmp(cmd, "level full-speed") == 0)) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5907 | level = TP_EC_FAN_FULLSPEED; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5908 | else if (sscanf(cmd, "level %d", &level) != 1) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5909 | return 0; |
| 5910 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5911 | *rc = fan_set_level_safe(level); |
| 5912 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5913 | printk(TPACPI_ERR "level command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5914 | "access mode %d", fan_control_access_mode); |
| 5915 | |
| 5916 | return 1; |
| 5917 | } |
| 5918 | |
| 5919 | static int fan_write_cmd_enable(const char *cmd, int *rc) |
| 5920 | { |
| 5921 | if (strlencmp(cmd, "enable") != 0) |
| 5922 | return 0; |
| 5923 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5924 | *rc = fan_set_enable(); |
| 5925 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5926 | printk(TPACPI_ERR "enable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5927 | "access mode %d", fan_control_access_mode); |
| 5928 | |
| 5929 | return 1; |
| 5930 | } |
| 5931 | |
| 5932 | static int fan_write_cmd_disable(const char *cmd, int *rc) |
| 5933 | { |
| 5934 | if (strlencmp(cmd, "disable") != 0) |
| 5935 | return 0; |
| 5936 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5937 | *rc = fan_set_disable(); |
| 5938 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5939 | printk(TPACPI_ERR "disable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5940 | "access mode %d", fan_control_access_mode); |
| 5941 | |
| 5942 | return 1; |
| 5943 | } |
| 5944 | |
| 5945 | static int fan_write_cmd_speed(const char *cmd, int *rc) |
| 5946 | { |
| 5947 | int speed; |
| 5948 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5949 | /* TODO: |
| 5950 | * Support speed <low> <medium> <high> ? */ |
| 5951 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5952 | if (sscanf(cmd, "speed %d", &speed) != 1) |
| 5953 | return 0; |
| 5954 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5955 | *rc = fan_set_speed(speed); |
| 5956 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5957 | printk(TPACPI_ERR "speed command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5958 | "access mode %d", fan_control_access_mode); |
| 5959 | |
| 5960 | return 1; |
| 5961 | } |
| 5962 | |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5963 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) |
| 5964 | { |
| 5965 | int interval; |
| 5966 | |
| 5967 | if (sscanf(cmd, "watchdog %d", &interval) != 1) |
| 5968 | return 0; |
| 5969 | |
| 5970 | if (interval < 0 || interval > 120) |
| 5971 | *rc = -EINVAL; |
| 5972 | else |
| 5973 | fan_watchdog_maxinterval = interval; |
| 5974 | |
| 5975 | return 1; |
| 5976 | } |
| 5977 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5978 | static int fan_write(char *buf) |
| 5979 | { |
| 5980 | char *cmd; |
| 5981 | int rc = 0; |
| 5982 | |
| 5983 | while (!rc && (cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5984 | if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5985 | fan_write_cmd_level(cmd, &rc)) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5986 | !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5987 | (fan_write_cmd_enable(cmd, &rc) || |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5988 | fan_write_cmd_disable(cmd, &rc) || |
| 5989 | fan_write_cmd_watchdog(cmd, &rc))) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5990 | !((fan_control_commands & TPACPI_FAN_CMD_SPEED) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5991 | fan_write_cmd_speed(cmd, &rc)) |
| 5992 | ) |
| 5993 | rc = -EINVAL; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5994 | else if (!rc) |
| 5995 | fan_watchdog_reset(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5996 | } |
| 5997 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5998 | return rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5999 | } |
| 6000 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6001 | static struct ibm_struct fan_driver_data = { |
| 6002 | .name = "fan", |
| 6003 | .read = fan_read, |
| 6004 | .write = fan_write, |
| 6005 | .exit = fan_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6006 | }; |
| 6007 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6008 | /**************************************************************************** |
| 6009 | **************************************************************************** |
| 6010 | * |
| 6011 | * Infrastructure |
| 6012 | * |
| 6013 | **************************************************************************** |
| 6014 | ****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6015 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6016 | /* sysfs name ---------------------------------------------------------- */ |
| 6017 | static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev, |
| 6018 | struct device_attribute *attr, |
| 6019 | char *buf) |
| 6020 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6021 | return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6022 | } |
| 6023 | |
| 6024 | static struct device_attribute dev_attr_thinkpad_acpi_pdev_name = |
| 6025 | __ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL); |
| 6026 | |
| 6027 | /* --------------------------------------------------------------------- */ |
| 6028 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6029 | /* /proc support */ |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 6030 | static struct proc_dir_entry *proc_dir; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6031 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6032 | /* |
| 6033 | * Module and infrastructure proble, init and exit handling |
| 6034 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6035 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6036 | static int force_load; |
| 6037 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6038 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6039 | static const char * __init str_supported(int is_supported) |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6040 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6041 | static char text_unsupported[] __initdata = "not supported"; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6042 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6043 | return (is_supported)? &text_unsupported[4] : &text_unsupported[0]; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6044 | } |
| 6045 | #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ |
| 6046 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6047 | static void ibm_exit(struct ibm_struct *ibm) |
| 6048 | { |
| 6049 | dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); |
| 6050 | |
| 6051 | list_del_init(&ibm->all_drivers); |
| 6052 | |
| 6053 | if (ibm->flags.acpi_notify_installed) { |
| 6054 | dbg_printk(TPACPI_DBG_EXIT, |
| 6055 | "%s: acpi_remove_notify_handler\n", ibm->name); |
| 6056 | BUG_ON(!ibm->acpi); |
| 6057 | acpi_remove_notify_handler(*ibm->acpi->handle, |
| 6058 | ibm->acpi->type, |
| 6059 | dispatch_acpi_notify); |
| 6060 | ibm->flags.acpi_notify_installed = 0; |
| 6061 | ibm->flags.acpi_notify_installed = 0; |
| 6062 | } |
| 6063 | |
| 6064 | if (ibm->flags.proc_created) { |
| 6065 | dbg_printk(TPACPI_DBG_EXIT, |
| 6066 | "%s: remove_proc_entry\n", ibm->name); |
| 6067 | remove_proc_entry(ibm->name, proc_dir); |
| 6068 | ibm->flags.proc_created = 0; |
| 6069 | } |
| 6070 | |
| 6071 | if (ibm->flags.acpi_driver_registered) { |
| 6072 | dbg_printk(TPACPI_DBG_EXIT, |
| 6073 | "%s: acpi_bus_unregister_driver\n", ibm->name); |
| 6074 | BUG_ON(!ibm->acpi); |
| 6075 | acpi_bus_unregister_driver(ibm->acpi->driver); |
| 6076 | kfree(ibm->acpi->driver); |
| 6077 | ibm->acpi->driver = NULL; |
| 6078 | ibm->flags.acpi_driver_registered = 0; |
| 6079 | } |
| 6080 | |
| 6081 | if (ibm->flags.init_called && ibm->exit) { |
| 6082 | ibm->exit(); |
| 6083 | ibm->flags.init_called = 0; |
| 6084 | } |
| 6085 | |
| 6086 | dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); |
| 6087 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6088 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6089 | static int __init ibm_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6090 | { |
| 6091 | int ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6092 | struct ibm_struct *ibm = iibm->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6093 | struct proc_dir_entry *entry; |
| 6094 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6095 | BUG_ON(ibm == NULL); |
| 6096 | |
| 6097 | INIT_LIST_HEAD(&ibm->all_drivers); |
| 6098 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 6099 | if (ibm->flags.experimental && !experimental) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6100 | return 0; |
| 6101 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6102 | dbg_printk(TPACPI_DBG_INIT, |
| 6103 | "probing for %s\n", ibm->name); |
| 6104 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6105 | if (iibm->init) { |
| 6106 | ret = iibm->init(iibm); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6107 | if (ret > 0) |
| 6108 | return 0; /* probe failed */ |
| 6109 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6110 | return ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6111 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 6112 | ibm->flags.init_called = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6113 | } |
| 6114 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 6115 | if (ibm->acpi) { |
| 6116 | if (ibm->acpi->hid) { |
| 6117 | ret = register_tpacpi_subdriver(ibm); |
| 6118 | if (ret) |
| 6119 | goto err_out; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6120 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 6121 | |
| 6122 | if (ibm->acpi->notify) { |
| 6123 | ret = setup_acpi_notify(ibm); |
| 6124 | if (ret == -ENODEV) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6125 | printk(TPACPI_NOTICE "disabling subdriver %s\n", |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 6126 | ibm->name); |
| 6127 | ret = 0; |
| 6128 | goto err_out; |
| 6129 | } |
| 6130 | if (ret < 0) |
| 6131 | goto err_out; |
| 6132 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6133 | } |
| 6134 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6135 | dbg_printk(TPACPI_DBG_INIT, |
| 6136 | "%s installed\n", ibm->name); |
| 6137 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6138 | if (ibm->read) { |
| 6139 | entry = create_proc_entry(ibm->name, |
| 6140 | S_IFREG | S_IRUGO | S_IWUSR, |
| 6141 | proc_dir); |
| 6142 | if (!entry) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6143 | printk(TPACPI_ERR "unable to create proc entry %s\n", |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6144 | ibm->name); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6145 | ret = -ENODEV; |
| 6146 | goto err_out; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6147 | } |
| 6148 | entry->owner = THIS_MODULE; |
| 6149 | entry->data = ibm; |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 6150 | entry->read_proc = &dispatch_procfs_read; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6151 | if (ibm->write) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 6152 | entry->write_proc = &dispatch_procfs_write; |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 6153 | ibm->flags.proc_created = 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6154 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6155 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6156 | list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers); |
| 6157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6158 | return 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6159 | |
| 6160 | err_out: |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6161 | dbg_printk(TPACPI_DBG_INIT, |
| 6162 | "%s: at error exit path with result %d\n", |
| 6163 | ibm->name, ret); |
| 6164 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6165 | ibm_exit(ibm); |
| 6166 | return (ret < 0)? ret : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6167 | } |
| 6168 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6169 | /* Probing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6170 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6171 | 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] | 6172 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 6173 | const struct dmi_device *dev = NULL; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 6174 | char ec_fw_string[18]; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 6175 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6176 | if (!tp) |
| 6177 | return; |
| 6178 | |
| 6179 | memset(tp, 0, sizeof(*tp)); |
| 6180 | |
| 6181 | if (dmi_name_in_vendors("IBM")) |
| 6182 | tp->vendor = PCI_VENDOR_ID_IBM; |
| 6183 | else if (dmi_name_in_vendors("LENOVO")) |
| 6184 | tp->vendor = PCI_VENDOR_ID_LENOVO; |
| 6185 | else |
| 6186 | return; |
| 6187 | |
| 6188 | tp->bios_version_str = kstrdup(dmi_get_system_info(DMI_BIOS_VERSION), |
| 6189 | GFP_KERNEL); |
| 6190 | if (!tp->bios_version_str) |
| 6191 | return; |
| 6192 | tp->bios_model = tp->bios_version_str[0] |
| 6193 | | (tp->bios_version_str[1] << 8); |
| 6194 | |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 6195 | /* |
| 6196 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, |
| 6197 | * X32 or newer, all Z series; Some models must have an |
| 6198 | * up-to-date BIOS or they will not be detected. |
| 6199 | * |
| 6200 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 6201 | */ |
| 6202 | 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] | 6203 | if (sscanf(dev->name, |
| 6204 | "IBM ThinkPad Embedded Controller -[%17c", |
| 6205 | ec_fw_string) == 1) { |
| 6206 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; |
| 6207 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6208 | |
| 6209 | tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); |
| 6210 | tp->ec_model = ec_fw_string[0] |
| 6211 | | (ec_fw_string[1] << 8); |
| 6212 | break; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 6213 | } |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 6214 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6215 | |
| 6216 | tp->model_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION), |
| 6217 | GFP_KERNEL); |
Cyrill Gorcunov | 90fe17f | 2008-04-18 13:27:29 -0700 | [diff] [blame] | 6218 | if (tp->model_str && strnicmp(tp->model_str, "ThinkPad", 8) != 0) { |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6219 | kfree(tp->model_str); |
| 6220 | tp->model_str = NULL; |
| 6221 | } |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 6222 | |
| 6223 | tp->nummodel_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_NAME), |
| 6224 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6225 | } |
| 6226 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6227 | static int __init probe_for_thinkpad(void) |
| 6228 | { |
| 6229 | int is_thinkpad; |
| 6230 | |
| 6231 | if (acpi_disabled) |
| 6232 | return -ENODEV; |
| 6233 | |
| 6234 | /* |
| 6235 | * Non-ancient models have better DMI tagging, but very old models |
| 6236 | * don't. |
| 6237 | */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6238 | is_thinkpad = (thinkpad_id.model_str != NULL); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6239 | |
| 6240 | /* 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] | 6241 | TPACPI_ACPIHANDLE_INIT(ec); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6242 | if (!ec_handle) { |
| 6243 | if (is_thinkpad) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6244 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6245 | "Not yet supported ThinkPad detected!\n"); |
| 6246 | return -ENODEV; |
| 6247 | } |
| 6248 | |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 6249 | /* |
| 6250 | * Risks a regression on very old machines, but reduces potential |
| 6251 | * false positives a damn great deal |
| 6252 | */ |
| 6253 | if (!is_thinkpad) |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6254 | is_thinkpad = (thinkpad_id.vendor == PCI_VENDOR_ID_IBM); |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 6255 | |
| 6256 | if (!is_thinkpad && !force_load) |
| 6257 | return -ENODEV; |
| 6258 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6259 | return 0; |
| 6260 | } |
| 6261 | |
| 6262 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6263 | /* Module init, exit, parameters */ |
| 6264 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6265 | static struct ibm_init_struct ibms_init[] __initdata = { |
| 6266 | { |
| 6267 | .init = thinkpad_acpi_driver_init, |
| 6268 | .data = &thinkpad_acpi_driver_data, |
| 6269 | }, |
| 6270 | { |
| 6271 | .init = hotkey_init, |
| 6272 | .data = &hotkey_driver_data, |
| 6273 | }, |
| 6274 | { |
| 6275 | .init = bluetooth_init, |
| 6276 | .data = &bluetooth_driver_data, |
| 6277 | }, |
| 6278 | { |
| 6279 | .init = wan_init, |
| 6280 | .data = &wan_driver_data, |
| 6281 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 6282 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6283 | { |
| 6284 | .init = video_init, |
| 6285 | .data = &video_driver_data, |
| 6286 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 6287 | #endif |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6288 | { |
| 6289 | .init = light_init, |
| 6290 | .data = &light_driver_data, |
| 6291 | }, |
| 6292 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
| 6293 | { |
| 6294 | .init = dock_init, |
| 6295 | .data = &dock_driver_data[0], |
| 6296 | }, |
| 6297 | { |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 6298 | .init = dock_init2, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6299 | .data = &dock_driver_data[1], |
| 6300 | }, |
| 6301 | #endif |
| 6302 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
| 6303 | { |
| 6304 | .init = bay_init, |
| 6305 | .data = &bay_driver_data, |
| 6306 | }, |
| 6307 | #endif |
| 6308 | { |
| 6309 | .init = cmos_init, |
| 6310 | .data = &cmos_driver_data, |
| 6311 | }, |
| 6312 | { |
| 6313 | .init = led_init, |
| 6314 | .data = &led_driver_data, |
| 6315 | }, |
| 6316 | { |
| 6317 | .init = beep_init, |
| 6318 | .data = &beep_driver_data, |
| 6319 | }, |
| 6320 | { |
| 6321 | .init = thermal_init, |
| 6322 | .data = &thermal_driver_data, |
| 6323 | }, |
| 6324 | { |
| 6325 | .data = &ecdump_driver_data, |
| 6326 | }, |
| 6327 | { |
| 6328 | .init = brightness_init, |
| 6329 | .data = &brightness_driver_data, |
| 6330 | }, |
| 6331 | { |
| 6332 | .data = &volume_driver_data, |
| 6333 | }, |
| 6334 | { |
| 6335 | .init = fan_init, |
| 6336 | .data = &fan_driver_data, |
| 6337 | }, |
| 6338 | }; |
| 6339 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6340 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) |
| 6341 | { |
| 6342 | unsigned int i; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6343 | struct ibm_struct *ibm; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6344 | |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 6345 | if (!kp || !kp->name || !val) |
| 6346 | return -EINVAL; |
| 6347 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6348 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 6349 | ibm = ibms_init[i].data; |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 6350 | WARN_ON(ibm == NULL); |
| 6351 | |
| 6352 | if (!ibm || !ibm->name) |
| 6353 | continue; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6354 | |
| 6355 | if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { |
| 6356 | if (strlen(val) > sizeof(ibms_init[i].param) - 2) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6357 | return -ENOSPC; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6358 | strcpy(ibms_init[i].param, val); |
| 6359 | strcat(ibms_init[i].param, ","); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6360 | return 0; |
| 6361 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6362 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6363 | |
| 6364 | return -EINVAL; |
| 6365 | } |
| 6366 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6367 | module_param(experimental, int, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6368 | MODULE_PARM_DESC(experimental, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6369 | "Enables experimental features when non-zero"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6370 | |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 6371 | module_param_named(debug, dbg_level, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6372 | MODULE_PARM_DESC(debug, "Sets debug level bit-mask"); |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 6373 | |
Henrique de Moraes Holschuh | 86cc944 | 2007-07-18 23:45:41 -0300 | [diff] [blame] | 6374 | module_param(force_load, bool, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6375 | MODULE_PARM_DESC(force_load, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6376 | "Attempts to load the driver even on a " |
| 6377 | "mis-identified ThinkPad when true"); |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 6378 | |
Henrique de Moraes Holschuh | 86cc944 | 2007-07-18 23:45:41 -0300 | [diff] [blame] | 6379 | module_param_named(fan_control, fan_control_allowed, bool, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6380 | MODULE_PARM_DESC(fan_control, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6381 | "Enables setting fan parameters features when true"); |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 6382 | |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6383 | module_param_named(brightness_mode, brightness_mode, int, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6384 | MODULE_PARM_DESC(brightness_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6385 | "Selects brightness control strategy: " |
| 6386 | "0=auto, 1=EC, 2=CMOS, 3=both"); |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6387 | |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 6388 | module_param(brightness_enable, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6389 | MODULE_PARM_DESC(brightness_enable, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6390 | "Enables backlight control when 1, disables when 0"); |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 6391 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 6392 | module_param(hotkey_report_mode, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6393 | MODULE_PARM_DESC(hotkey_report_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6394 | "used for backwards compatibility with userspace, " |
| 6395 | "see documentation"); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 6396 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6397 | #define TPACPI_PARAM(feature) \ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6398 | module_param_call(feature, set_ibm_param, NULL, NULL, 0); \ |
Henrique de Moraes Holschuh | cbb1484 | 2008-02-16 02:17:50 -0200 | [diff] [blame] | 6399 | MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6400 | "at module load, see documentation") |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6401 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6402 | TPACPI_PARAM(hotkey); |
| 6403 | TPACPI_PARAM(bluetooth); |
| 6404 | TPACPI_PARAM(video); |
| 6405 | TPACPI_PARAM(light); |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 6406 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6407 | TPACPI_PARAM(dock); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6408 | #endif |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 6409 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6410 | TPACPI_PARAM(bay); |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 6411 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6412 | TPACPI_PARAM(cmos); |
| 6413 | TPACPI_PARAM(led); |
| 6414 | TPACPI_PARAM(beep); |
| 6415 | TPACPI_PARAM(ecdump); |
| 6416 | TPACPI_PARAM(brightness); |
| 6417 | TPACPI_PARAM(volume); |
| 6418 | TPACPI_PARAM(fan); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6419 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6420 | static void thinkpad_acpi_module_exit(void) |
| 6421 | { |
| 6422 | struct ibm_struct *ibm, *itmp; |
| 6423 | |
| 6424 | tpacpi_lifecycle = TPACPI_LIFE_EXITING; |
| 6425 | |
| 6426 | list_for_each_entry_safe_reverse(ibm, itmp, |
| 6427 | &tpacpi_all_drivers, |
| 6428 | all_drivers) { |
| 6429 | ibm_exit(ibm); |
| 6430 | } |
| 6431 | |
| 6432 | dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); |
| 6433 | |
| 6434 | if (tpacpi_inputdev) { |
| 6435 | if (tp_features.input_device_registered) |
| 6436 | input_unregister_device(tpacpi_inputdev); |
| 6437 | else |
| 6438 | input_free_device(tpacpi_inputdev); |
| 6439 | } |
| 6440 | |
| 6441 | if (tpacpi_hwmon) |
| 6442 | hwmon_device_unregister(tpacpi_hwmon); |
| 6443 | |
| 6444 | if (tp_features.sensors_pdev_attrs_registered) |
| 6445 | device_remove_file(&tpacpi_sensors_pdev->dev, |
| 6446 | &dev_attr_thinkpad_acpi_pdev_name); |
| 6447 | if (tpacpi_sensors_pdev) |
| 6448 | platform_device_unregister(tpacpi_sensors_pdev); |
| 6449 | if (tpacpi_pdev) |
| 6450 | platform_device_unregister(tpacpi_pdev); |
| 6451 | |
| 6452 | if (tp_features.sensors_pdrv_attrs_registered) |
| 6453 | tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.driver); |
| 6454 | if (tp_features.platform_drv_attrs_registered) |
| 6455 | tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); |
| 6456 | |
| 6457 | if (tp_features.sensors_pdrv_registered) |
| 6458 | platform_driver_unregister(&tpacpi_hwmon_pdriver); |
| 6459 | |
| 6460 | if (tp_features.platform_drv_registered) |
| 6461 | platform_driver_unregister(&tpacpi_pdriver); |
| 6462 | |
| 6463 | if (proc_dir) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6464 | remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6465 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 6466 | if (tpacpi_wq) |
| 6467 | destroy_workqueue(tpacpi_wq); |
| 6468 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6469 | kfree(thinkpad_id.bios_version_str); |
| 6470 | kfree(thinkpad_id.ec_version_str); |
| 6471 | kfree(thinkpad_id.model_str); |
| 6472 | } |
| 6473 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6474 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6475 | static int __init thinkpad_acpi_module_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6476 | { |
| 6477 | int ret, i; |
| 6478 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 6479 | tpacpi_lifecycle = TPACPI_LIFE_INIT; |
| 6480 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 6481 | /* Parameter checking */ |
| 6482 | if (hotkey_report_mode > 2) |
| 6483 | return -EINVAL; |
| 6484 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6485 | /* Driver-level probe */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6486 | |
| 6487 | get_thinkpad_model_data(&thinkpad_id); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6488 | ret = probe_for_thinkpad(); |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6489 | if (ret) { |
| 6490 | thinkpad_acpi_module_exit(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6491 | return ret; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6492 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6493 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6494 | /* Driver initialization */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6495 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6496 | TPACPI_ACPIHANDLE_INIT(ecrd); |
| 6497 | TPACPI_ACPIHANDLE_INIT(ecwr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6498 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 6499 | tpacpi_wq = create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME); |
| 6500 | if (!tpacpi_wq) { |
| 6501 | thinkpad_acpi_module_exit(); |
| 6502 | return -ENOMEM; |
| 6503 | } |
| 6504 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6505 | proc_dir = proc_mkdir(TPACPI_PROC_DIR, acpi_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6506 | if (!proc_dir) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6507 | printk(TPACPI_ERR |
| 6508 | "unable to create proc dir " TPACPI_PROC_DIR); |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6509 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6510 | return -ENODEV; |
| 6511 | } |
| 6512 | proc_dir->owner = THIS_MODULE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6513 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6514 | ret = platform_driver_register(&tpacpi_pdriver); |
| 6515 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6516 | printk(TPACPI_ERR |
| 6517 | "unable to register main platform driver\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 | ac36393 | 2007-07-27 17:04:40 -0300 | [diff] [blame] | 6521 | tp_features.platform_drv_registered = 1; |
| 6522 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6523 | ret = platform_driver_register(&tpacpi_hwmon_pdriver); |
| 6524 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6525 | printk(TPACPI_ERR |
| 6526 | "unable to register hwmon platform driver\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6527 | thinkpad_acpi_module_exit(); |
| 6528 | return ret; |
| 6529 | } |
| 6530 | tp_features.sensors_pdrv_registered = 1; |
| 6531 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 6532 | ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 6533 | if (!ret) { |
| 6534 | tp_features.platform_drv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6535 | ret = tpacpi_create_driver_attributes( |
| 6536 | &tpacpi_hwmon_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 6537 | } |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 6538 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6539 | printk(TPACPI_ERR |
| 6540 | "unable to create sysfs driver attributes\n"); |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 6541 | thinkpad_acpi_module_exit(); |
| 6542 | return ret; |
| 6543 | } |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 6544 | tp_features.sensors_pdrv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 6545 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6546 | |
| 6547 | /* Device initialization */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6548 | tpacpi_pdev = platform_device_register_simple(TPACPI_DRVR_NAME, -1, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6549 | NULL, 0); |
| 6550 | if (IS_ERR(tpacpi_pdev)) { |
| 6551 | ret = PTR_ERR(tpacpi_pdev); |
| 6552 | tpacpi_pdev = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6553 | printk(TPACPI_ERR "unable to register platform device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6554 | thinkpad_acpi_module_exit(); |
| 6555 | return ret; |
| 6556 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6557 | tpacpi_sensors_pdev = platform_device_register_simple( |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6558 | TPACPI_HWMON_DRVR_NAME, |
| 6559 | -1, NULL, 0); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6560 | if (IS_ERR(tpacpi_sensors_pdev)) { |
| 6561 | ret = PTR_ERR(tpacpi_sensors_pdev); |
| 6562 | tpacpi_sensors_pdev = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6563 | printk(TPACPI_ERR |
| 6564 | "unable to register hwmon platform device\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6565 | thinkpad_acpi_module_exit(); |
| 6566 | return ret; |
| 6567 | } |
| 6568 | ret = device_create_file(&tpacpi_sensors_pdev->dev, |
| 6569 | &dev_attr_thinkpad_acpi_pdev_name); |
| 6570 | if (ret) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6571 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6572 | "unable to create sysfs hwmon device attributes\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6573 | thinkpad_acpi_module_exit(); |
| 6574 | return ret; |
| 6575 | } |
| 6576 | tp_features.sensors_pdev_attrs_registered = 1; |
| 6577 | tpacpi_hwmon = hwmon_device_register(&tpacpi_sensors_pdev->dev); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6578 | if (IS_ERR(tpacpi_hwmon)) { |
| 6579 | ret = PTR_ERR(tpacpi_hwmon); |
| 6580 | tpacpi_hwmon = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6581 | printk(TPACPI_ERR "unable to register hwmon device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6582 | thinkpad_acpi_module_exit(); |
| 6583 | return ret; |
| 6584 | } |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 6585 | mutex_init(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6586 | tpacpi_inputdev = input_allocate_device(); |
| 6587 | if (!tpacpi_inputdev) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6588 | printk(TPACPI_ERR "unable to allocate input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6589 | thinkpad_acpi_module_exit(); |
| 6590 | return -ENOMEM; |
| 6591 | } else { |
| 6592 | /* Prepare input device, but don't register */ |
| 6593 | tpacpi_inputdev->name = "ThinkPad Extra Buttons"; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6594 | tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0"; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6595 | tpacpi_inputdev->id.bustype = BUS_HOST; |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 6596 | tpacpi_inputdev->id.vendor = (thinkpad_id.vendor) ? |
| 6597 | thinkpad_id.vendor : |
| 6598 | PCI_VENDOR_ID_IBM; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6599 | tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; |
| 6600 | tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; |
| 6601 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6602 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 6603 | ret = ibm_init(&ibms_init[i]); |
| 6604 | if (ret >= 0 && *ibms_init[i].param) |
| 6605 | ret = ibms_init[i].data->write(ibms_init[i].param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6606 | if (ret < 0) { |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6607 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6608 | return ret; |
| 6609 | } |
| 6610 | } |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6611 | ret = input_register_device(tpacpi_inputdev); |
| 6612 | if (ret < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6613 | printk(TPACPI_ERR "unable to register input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6614 | thinkpad_acpi_module_exit(); |
| 6615 | return ret; |
| 6616 | } else { |
| 6617 | tp_features.input_device_registered = 1; |
| 6618 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6619 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 6620 | tpacpi_lifecycle = TPACPI_LIFE_RUNNING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6621 | return 0; |
| 6622 | } |
| 6623 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6624 | /* Please remove this in year 2009 */ |
| 6625 | MODULE_ALIAS("ibm_acpi"); |
| 6626 | |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 6627 | MODULE_ALIAS(TPACPI_DRVR_SHORTNAME); |
| 6628 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6629 | /* |
| 6630 | * DMI matching for module autoloading |
| 6631 | * |
| 6632 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 6633 | * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads |
| 6634 | * |
| 6635 | * Only models listed in thinkwiki will be supported, so add yours |
| 6636 | * if it is not there yet. |
| 6637 | */ |
| 6638 | #define IBM_BIOS_MODULE_ALIAS(__type) \ |
| 6639 | MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW") |
| 6640 | |
| 6641 | /* Non-ancient thinkpads */ |
| 6642 | MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*"); |
| 6643 | MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*"); |
| 6644 | |
| 6645 | /* Ancient thinkpad BIOSes have to be identified by |
| 6646 | * BIOS type or model number, and there are far less |
| 6647 | * BIOS types than model numbers... */ |
| 6648 | IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]"); |
| 6649 | IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]"); |
| 6650 | IBM_BIOS_MODULE_ALIAS("K[U,X-Z]"); |
| 6651 | |
| 6652 | MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh"); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6653 | MODULE_DESCRIPTION(TPACPI_DESC); |
| 6654 | MODULE_VERSION(TPACPI_VERSION); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6655 | MODULE_LICENSE("GPL"); |
| 6656 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6657 | module_init(thinkpad_acpi_module_init); |
| 6658 | module_exit(thinkpad_acpi_module_exit); |