David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 1 | /* |
Ike Panhc | a4b5a27 | 2010-12-13 18:00:48 +0800 | [diff] [blame] | 2 | * ideapad-laptop.c - Lenovo IdeaPad ACPI Extras |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 3 | * |
| 4 | * Copyright © 2010 Intel Corporation |
| 5 | * Copyright © 2010 David Woodhouse <dwmw2@infradead.org> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 20 | * 02110-1301, USA. |
| 21 | */ |
| 22 | |
Joe Perches | 9ab2398 | 2011-03-29 15:21:43 -0700 | [diff] [blame] | 23 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 24 | |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 25 | #include <linux/kernel.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/types.h> |
| 29 | #include <acpi/acpi_bus.h> |
| 30 | #include <acpi/acpi_drivers.h> |
| 31 | #include <linux/rfkill.h> |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 32 | #include <linux/platform_device.h> |
Ike Panhc | f63409a | 2010-12-13 18:00:38 +0800 | [diff] [blame] | 33 | #include <linux/input.h> |
| 34 | #include <linux/input/sparse-keymap.h> |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 35 | #include <linux/backlight.h> |
| 36 | #include <linux/fb.h> |
Ike Panhc | 773e320 | 2011-09-06 02:32:52 +0800 | [diff] [blame] | 37 | #include <linux/debugfs.h> |
| 38 | #include <linux/seq_file.h> |
Maxim Mikityanskiy | 07a4a4f | 2012-07-06 16:08:00 +0800 | [diff] [blame] | 39 | #include <linux/i8042.h> |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 40 | |
Ike Panhc | c1f7365 | 2010-12-13 18:01:12 +0800 | [diff] [blame] | 41 | #define IDEAPAD_RFKILL_DEV_NUM (3) |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 42 | |
Ike Panhc | 3371f48 | 2011-06-30 19:50:40 +0800 | [diff] [blame] | 43 | #define CFG_BT_BIT (16) |
| 44 | #define CFG_3G_BIT (17) |
| 45 | #define CFG_WIFI_BIT (18) |
Ike Panhc | a84511f | 2011-06-30 19:50:47 +0800 | [diff] [blame] | 46 | #define CFG_CAMERA_BIT (19) |
Ike Panhc | 3371f48 | 2011-06-30 19:50:40 +0800 | [diff] [blame] | 47 | |
Ike Panhc | 2be1dc2 | 2011-09-06 02:31:53 +0800 | [diff] [blame] | 48 | enum { |
| 49 | VPCCMD_R_VPC1 = 0x10, |
| 50 | VPCCMD_R_BL_MAX, |
| 51 | VPCCMD_R_BL, |
| 52 | VPCCMD_W_BL, |
| 53 | VPCCMD_R_WIFI, |
| 54 | VPCCMD_W_WIFI, |
| 55 | VPCCMD_R_BT, |
| 56 | VPCCMD_W_BT, |
| 57 | VPCCMD_R_BL_POWER, |
| 58 | VPCCMD_R_NOVO, |
| 59 | VPCCMD_R_VPC2, |
| 60 | VPCCMD_R_TOUCHPAD, |
| 61 | VPCCMD_W_TOUCHPAD, |
| 62 | VPCCMD_R_CAMERA, |
| 63 | VPCCMD_W_CAMERA, |
| 64 | VPCCMD_R_3G, |
| 65 | VPCCMD_W_3G, |
| 66 | VPCCMD_R_ODD, /* 0x21 */ |
Maxim Mikityanskiy | 0c7bbeb9 | 2012-07-06 16:08:11 +0800 | [diff] [blame] | 67 | VPCCMD_W_FAN, |
| 68 | VPCCMD_R_RF, |
Ike Panhc | 2be1dc2 | 2011-09-06 02:31:53 +0800 | [diff] [blame] | 69 | VPCCMD_W_RF, |
Maxim Mikityanskiy | 0c7bbeb9 | 2012-07-06 16:08:11 +0800 | [diff] [blame] | 70 | VPCCMD_R_FAN = 0x2B, |
Maxim Mikityanskiy | 296f9fe | 2012-07-06 16:07:50 +0800 | [diff] [blame] | 71 | VPCCMD_R_SPECIAL_BUTTONS = 0x31, |
Ike Panhc | 2be1dc2 | 2011-09-06 02:31:53 +0800 | [diff] [blame] | 72 | VPCCMD_W_BL_POWER = 0x33, |
| 73 | }; |
| 74 | |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 75 | struct ideapad_private { |
Ike Panhc | c1f7365 | 2010-12-13 18:01:12 +0800 | [diff] [blame] | 76 | struct rfkill *rfk[IDEAPAD_RFKILL_DEV_NUM]; |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 77 | struct platform_device *platform_device; |
Ike Panhc | f63409a | 2010-12-13 18:00:38 +0800 | [diff] [blame] | 78 | struct input_dev *inputdev; |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 79 | struct backlight_device *blightdev; |
Ike Panhc | 773e320 | 2011-09-06 02:32:52 +0800 | [diff] [blame] | 80 | struct dentry *debug; |
Ike Panhc | 3371f48 | 2011-06-30 19:50:40 +0800 | [diff] [blame] | 81 | unsigned long cfg; |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 82 | }; |
| 83 | |
Ike Panhc | c1f7365 | 2010-12-13 18:01:12 +0800 | [diff] [blame] | 84 | static acpi_handle ideapad_handle; |
Ike Panhc | 773e320 | 2011-09-06 02:32:52 +0800 | [diff] [blame] | 85 | static struct ideapad_private *ideapad_priv; |
Ike Panhc | bfa97b7 | 2010-10-01 15:40:22 +0800 | [diff] [blame] | 86 | static bool no_bt_rfkill; |
| 87 | module_param(no_bt_rfkill, bool, 0444); |
| 88 | MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth."); |
| 89 | |
Ike Panhc | 6a09f21 | 2010-10-01 15:38:46 +0800 | [diff] [blame] | 90 | /* |
| 91 | * ACPI Helpers |
| 92 | */ |
| 93 | #define IDEAPAD_EC_TIMEOUT (100) /* in ms */ |
| 94 | |
| 95 | static int read_method_int(acpi_handle handle, const char *method, int *val) |
| 96 | { |
| 97 | acpi_status status; |
| 98 | unsigned long long result; |
| 99 | |
| 100 | status = acpi_evaluate_integer(handle, (char *)method, NULL, &result); |
| 101 | if (ACPI_FAILURE(status)) { |
| 102 | *val = -1; |
| 103 | return -1; |
| 104 | } else { |
| 105 | *val = result; |
| 106 | return 0; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | static int method_vpcr(acpi_handle handle, int cmd, int *ret) |
| 111 | { |
| 112 | acpi_status status; |
| 113 | unsigned long long result; |
| 114 | struct acpi_object_list params; |
| 115 | union acpi_object in_obj; |
| 116 | |
| 117 | params.count = 1; |
| 118 | params.pointer = &in_obj; |
| 119 | in_obj.type = ACPI_TYPE_INTEGER; |
| 120 | in_obj.integer.value = cmd; |
| 121 | |
| 122 | status = acpi_evaluate_integer(handle, "VPCR", ¶ms, &result); |
| 123 | |
| 124 | if (ACPI_FAILURE(status)) { |
| 125 | *ret = -1; |
| 126 | return -1; |
| 127 | } else { |
| 128 | *ret = result; |
| 129 | return 0; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | static int method_vpcw(acpi_handle handle, int cmd, int data) |
| 134 | { |
| 135 | struct acpi_object_list params; |
| 136 | union acpi_object in_obj[2]; |
| 137 | acpi_status status; |
| 138 | |
| 139 | params.count = 2; |
| 140 | params.pointer = in_obj; |
| 141 | in_obj[0].type = ACPI_TYPE_INTEGER; |
| 142 | in_obj[0].integer.value = cmd; |
| 143 | in_obj[1].type = ACPI_TYPE_INTEGER; |
| 144 | in_obj[1].integer.value = data; |
| 145 | |
| 146 | status = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL); |
| 147 | if (status != AE_OK) |
| 148 | return -1; |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | static int read_ec_data(acpi_handle handle, int cmd, unsigned long *data) |
| 153 | { |
| 154 | int val; |
| 155 | unsigned long int end_jiffies; |
| 156 | |
| 157 | if (method_vpcw(handle, 1, cmd)) |
| 158 | return -1; |
| 159 | |
| 160 | for (end_jiffies = jiffies+(HZ)*IDEAPAD_EC_TIMEOUT/1000+1; |
| 161 | time_before(jiffies, end_jiffies);) { |
| 162 | schedule(); |
| 163 | if (method_vpcr(handle, 1, &val)) |
| 164 | return -1; |
| 165 | if (val == 0) { |
| 166 | if (method_vpcr(handle, 0, &val)) |
| 167 | return -1; |
| 168 | *data = val; |
| 169 | return 0; |
| 170 | } |
| 171 | } |
| 172 | pr_err("timeout in read_ec_cmd\n"); |
| 173 | return -1; |
| 174 | } |
| 175 | |
| 176 | static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data) |
| 177 | { |
| 178 | int val; |
| 179 | unsigned long int end_jiffies; |
| 180 | |
| 181 | if (method_vpcw(handle, 0, data)) |
| 182 | return -1; |
| 183 | if (method_vpcw(handle, 1, cmd)) |
| 184 | return -1; |
| 185 | |
| 186 | for (end_jiffies = jiffies+(HZ)*IDEAPAD_EC_TIMEOUT/1000+1; |
| 187 | time_before(jiffies, end_jiffies);) { |
| 188 | schedule(); |
| 189 | if (method_vpcr(handle, 1, &val)) |
| 190 | return -1; |
| 191 | if (val == 0) |
| 192 | return 0; |
| 193 | } |
| 194 | pr_err("timeout in write_ec_cmd\n"); |
| 195 | return -1; |
| 196 | } |
Ike Panhc | 6a09f21 | 2010-10-01 15:38:46 +0800 | [diff] [blame] | 197 | |
Ike Panhc | a4b5a27 | 2010-12-13 18:00:48 +0800 | [diff] [blame] | 198 | /* |
Ike Panhc | 773e320 | 2011-09-06 02:32:52 +0800 | [diff] [blame] | 199 | * debugfs |
| 200 | */ |
Ike Panhc | 773e320 | 2011-09-06 02:32:52 +0800 | [diff] [blame] | 201 | static int debugfs_status_show(struct seq_file *s, void *data) |
| 202 | { |
| 203 | unsigned long value; |
| 204 | |
| 205 | if (!read_ec_data(ideapad_handle, VPCCMD_R_BL_MAX, &value)) |
| 206 | seq_printf(s, "Backlight max:\t%lu\n", value); |
| 207 | if (!read_ec_data(ideapad_handle, VPCCMD_R_BL, &value)) |
| 208 | seq_printf(s, "Backlight now:\t%lu\n", value); |
| 209 | if (!read_ec_data(ideapad_handle, VPCCMD_R_BL_POWER, &value)) |
| 210 | seq_printf(s, "BL power value:\t%s\n", value ? "On" : "Off"); |
| 211 | seq_printf(s, "=====================\n"); |
| 212 | |
| 213 | if (!read_ec_data(ideapad_handle, VPCCMD_R_RF, &value)) |
| 214 | seq_printf(s, "Radio status:\t%s(%lu)\n", |
| 215 | value ? "On" : "Off", value); |
| 216 | if (!read_ec_data(ideapad_handle, VPCCMD_R_WIFI, &value)) |
| 217 | seq_printf(s, "Wifi status:\t%s(%lu)\n", |
| 218 | value ? "On" : "Off", value); |
| 219 | if (!read_ec_data(ideapad_handle, VPCCMD_R_BT, &value)) |
| 220 | seq_printf(s, "BT status:\t%s(%lu)\n", |
| 221 | value ? "On" : "Off", value); |
| 222 | if (!read_ec_data(ideapad_handle, VPCCMD_R_3G, &value)) |
| 223 | seq_printf(s, "3G status:\t%s(%lu)\n", |
| 224 | value ? "On" : "Off", value); |
| 225 | seq_printf(s, "=====================\n"); |
| 226 | |
| 227 | if (!read_ec_data(ideapad_handle, VPCCMD_R_TOUCHPAD, &value)) |
| 228 | seq_printf(s, "Touchpad status:%s(%lu)\n", |
| 229 | value ? "On" : "Off", value); |
| 230 | if (!read_ec_data(ideapad_handle, VPCCMD_R_CAMERA, &value)) |
| 231 | seq_printf(s, "Camera status:\t%s(%lu)\n", |
| 232 | value ? "On" : "Off", value); |
| 233 | |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | static int debugfs_status_open(struct inode *inode, struct file *file) |
| 238 | { |
| 239 | return single_open(file, debugfs_status_show, NULL); |
| 240 | } |
| 241 | |
| 242 | static const struct file_operations debugfs_status_fops = { |
| 243 | .owner = THIS_MODULE, |
| 244 | .open = debugfs_status_open, |
| 245 | .read = seq_read, |
| 246 | .llseek = seq_lseek, |
| 247 | .release = single_release, |
| 248 | }; |
| 249 | |
| 250 | static int debugfs_cfg_show(struct seq_file *s, void *data) |
| 251 | { |
| 252 | if (!ideapad_priv) { |
| 253 | seq_printf(s, "cfg: N/A\n"); |
| 254 | } else { |
| 255 | seq_printf(s, "cfg: 0x%.8lX\n\nCapability: ", |
| 256 | ideapad_priv->cfg); |
| 257 | if (test_bit(CFG_BT_BIT, &ideapad_priv->cfg)) |
| 258 | seq_printf(s, "Bluetooth "); |
| 259 | if (test_bit(CFG_3G_BIT, &ideapad_priv->cfg)) |
| 260 | seq_printf(s, "3G "); |
| 261 | if (test_bit(CFG_WIFI_BIT, &ideapad_priv->cfg)) |
| 262 | seq_printf(s, "Wireless "); |
| 263 | if (test_bit(CFG_CAMERA_BIT, &ideapad_priv->cfg)) |
| 264 | seq_printf(s, "Camera "); |
| 265 | seq_printf(s, "\nGraphic: "); |
| 266 | switch ((ideapad_priv->cfg)&0x700) { |
| 267 | case 0x100: |
| 268 | seq_printf(s, "Intel"); |
| 269 | break; |
| 270 | case 0x200: |
| 271 | seq_printf(s, "ATI"); |
| 272 | break; |
| 273 | case 0x300: |
| 274 | seq_printf(s, "Nvidia"); |
| 275 | break; |
| 276 | case 0x400: |
| 277 | seq_printf(s, "Intel and ATI"); |
| 278 | break; |
| 279 | case 0x500: |
| 280 | seq_printf(s, "Intel and Nvidia"); |
| 281 | break; |
| 282 | } |
| 283 | seq_printf(s, "\n"); |
| 284 | } |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | static int debugfs_cfg_open(struct inode *inode, struct file *file) |
| 289 | { |
| 290 | return single_open(file, debugfs_cfg_show, NULL); |
| 291 | } |
| 292 | |
| 293 | static const struct file_operations debugfs_cfg_fops = { |
| 294 | .owner = THIS_MODULE, |
| 295 | .open = debugfs_cfg_open, |
| 296 | .read = seq_read, |
| 297 | .llseek = seq_lseek, |
| 298 | .release = single_release, |
| 299 | }; |
| 300 | |
| 301 | static int __devinit ideapad_debugfs_init(struct ideapad_private *priv) |
| 302 | { |
| 303 | struct dentry *node; |
| 304 | |
| 305 | priv->debug = debugfs_create_dir("ideapad", NULL); |
| 306 | if (priv->debug == NULL) { |
| 307 | pr_err("failed to create debugfs directory"); |
| 308 | goto errout; |
| 309 | } |
| 310 | |
| 311 | node = debugfs_create_file("cfg", S_IRUGO, priv->debug, NULL, |
| 312 | &debugfs_cfg_fops); |
| 313 | if (!node) { |
| 314 | pr_err("failed to create cfg in debugfs"); |
| 315 | goto errout; |
| 316 | } |
| 317 | |
| 318 | node = debugfs_create_file("status", S_IRUGO, priv->debug, NULL, |
| 319 | &debugfs_status_fops); |
| 320 | if (!node) { |
Ike Panhc | a5c3892 | 2012-05-03 17:38:35 +0800 | [diff] [blame] | 321 | pr_err("failed to create status in debugfs"); |
Ike Panhc | 773e320 | 2011-09-06 02:32:52 +0800 | [diff] [blame] | 322 | goto errout; |
| 323 | } |
| 324 | |
| 325 | return 0; |
| 326 | |
| 327 | errout: |
| 328 | return -ENOMEM; |
| 329 | } |
| 330 | |
| 331 | static void ideapad_debugfs_exit(struct ideapad_private *priv) |
| 332 | { |
| 333 | debugfs_remove_recursive(priv->debug); |
| 334 | priv->debug = NULL; |
| 335 | } |
| 336 | |
| 337 | /* |
Ike Panhc | 3371f48 | 2011-06-30 19:50:40 +0800 | [diff] [blame] | 338 | * sysfs |
Ike Panhc | a4b5a27 | 2010-12-13 18:00:48 +0800 | [diff] [blame] | 339 | */ |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 340 | static ssize_t show_ideapad_cam(struct device *dev, |
| 341 | struct device_attribute *attr, |
| 342 | char *buf) |
| 343 | { |
Ike Panhc | 26c81d5 | 2010-10-01 15:39:40 +0800 | [diff] [blame] | 344 | unsigned long result; |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 345 | |
Ike Panhc | 2be1dc2 | 2011-09-06 02:31:53 +0800 | [diff] [blame] | 346 | if (read_ec_data(ideapad_handle, VPCCMD_R_CAMERA, &result)) |
Ike Panhc | 26c81d5 | 2010-10-01 15:39:40 +0800 | [diff] [blame] | 347 | return sprintf(buf, "-1\n"); |
| 348 | return sprintf(buf, "%lu\n", result); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | static ssize_t store_ideapad_cam(struct device *dev, |
| 352 | struct device_attribute *attr, |
| 353 | const char *buf, size_t count) |
| 354 | { |
| 355 | int ret, state; |
| 356 | |
| 357 | if (!count) |
| 358 | return 0; |
| 359 | if (sscanf(buf, "%i", &state) != 1) |
| 360 | return -EINVAL; |
Ike Panhc | 2be1dc2 | 2011-09-06 02:31:53 +0800 | [diff] [blame] | 361 | ret = write_ec_cmd(ideapad_handle, VPCCMD_W_CAMERA, state); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 362 | if (ret < 0) |
Maxim Mikityanskiy | 0c7bbeb9 | 2012-07-06 16:08:11 +0800 | [diff] [blame] | 363 | return -EIO; |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 364 | return count; |
| 365 | } |
| 366 | |
| 367 | static DEVICE_ATTR(camera_power, 0644, show_ideapad_cam, store_ideapad_cam); |
| 368 | |
Maxim Mikityanskiy | 0c7bbeb9 | 2012-07-06 16:08:11 +0800 | [diff] [blame] | 369 | static ssize_t show_ideapad_fan(struct device *dev, |
| 370 | struct device_attribute *attr, |
| 371 | char *buf) |
| 372 | { |
| 373 | unsigned long result; |
| 374 | |
| 375 | if (read_ec_data(ideapad_handle, VPCCMD_R_FAN, &result)) |
| 376 | return sprintf(buf, "-1\n"); |
| 377 | return sprintf(buf, "%lu\n", result); |
| 378 | } |
| 379 | |
| 380 | static ssize_t store_ideapad_fan(struct device *dev, |
| 381 | struct device_attribute *attr, |
| 382 | const char *buf, size_t count) |
| 383 | { |
| 384 | int ret, state; |
| 385 | |
| 386 | if (!count) |
| 387 | return 0; |
| 388 | if (sscanf(buf, "%i", &state) != 1) |
| 389 | return -EINVAL; |
| 390 | if (state < 0 || state > 4 || state == 3) |
| 391 | return -EINVAL; |
| 392 | ret = write_ec_cmd(ideapad_handle, VPCCMD_W_FAN, state); |
| 393 | if (ret < 0) |
| 394 | return -EIO; |
| 395 | return count; |
| 396 | } |
| 397 | |
| 398 | static DEVICE_ATTR(fan_mode, 0644, show_ideapad_fan, store_ideapad_fan); |
| 399 | |
Ike Panhc | 3371f48 | 2011-06-30 19:50:40 +0800 | [diff] [blame] | 400 | static struct attribute *ideapad_attributes[] = { |
| 401 | &dev_attr_camera_power.attr, |
Maxim Mikityanskiy | 0c7bbeb9 | 2012-07-06 16:08:11 +0800 | [diff] [blame] | 402 | &dev_attr_fan_mode.attr, |
Ike Panhc | 3371f48 | 2011-06-30 19:50:40 +0800 | [diff] [blame] | 403 | NULL |
| 404 | }; |
| 405 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 406 | static umode_t ideapad_is_visible(struct kobject *kobj, |
Ike Panhc | a84511f | 2011-06-30 19:50:47 +0800 | [diff] [blame] | 407 | struct attribute *attr, |
| 408 | int idx) |
| 409 | { |
| 410 | struct device *dev = container_of(kobj, struct device, kobj); |
| 411 | struct ideapad_private *priv = dev_get_drvdata(dev); |
| 412 | bool supported; |
| 413 | |
| 414 | if (attr == &dev_attr_camera_power.attr) |
| 415 | supported = test_bit(CFG_CAMERA_BIT, &(priv->cfg)); |
Maxim Mikityanskiy | 0c7bbeb9 | 2012-07-06 16:08:11 +0800 | [diff] [blame] | 416 | else if (attr == &dev_attr_fan_mode.attr) { |
| 417 | unsigned long value; |
| 418 | supported = !read_ec_data(ideapad_handle, VPCCMD_R_FAN, &value); |
| 419 | } else |
Ike Panhc | a84511f | 2011-06-30 19:50:47 +0800 | [diff] [blame] | 420 | supported = true; |
| 421 | |
| 422 | return supported ? attr->mode : 0; |
| 423 | } |
| 424 | |
Ike Panhc | 3371f48 | 2011-06-30 19:50:40 +0800 | [diff] [blame] | 425 | static struct attribute_group ideapad_attribute_group = { |
Ike Panhc | a84511f | 2011-06-30 19:50:47 +0800 | [diff] [blame] | 426 | .is_visible = ideapad_is_visible, |
Ike Panhc | 3371f48 | 2011-06-30 19:50:40 +0800 | [diff] [blame] | 427 | .attrs = ideapad_attributes |
| 428 | }; |
| 429 | |
Ike Panhc | a4b5a27 | 2010-12-13 18:00:48 +0800 | [diff] [blame] | 430 | /* |
| 431 | * Rfkill |
| 432 | */ |
Ike Panhc | c1f7365 | 2010-12-13 18:01:12 +0800 | [diff] [blame] | 433 | struct ideapad_rfk_data { |
| 434 | char *name; |
| 435 | int cfgbit; |
| 436 | int opcode; |
| 437 | int type; |
| 438 | }; |
| 439 | |
| 440 | const struct ideapad_rfk_data ideapad_rfk_data[] = { |
Ike Panhc | 2be1dc2 | 2011-09-06 02:31:53 +0800 | [diff] [blame] | 441 | { "ideapad_wlan", CFG_WIFI_BIT, VPCCMD_W_WIFI, RFKILL_TYPE_WLAN }, |
| 442 | { "ideapad_bluetooth", CFG_BT_BIT, VPCCMD_W_BT, RFKILL_TYPE_BLUETOOTH }, |
| 443 | { "ideapad_3g", CFG_3G_BIT, VPCCMD_W_3G, RFKILL_TYPE_WWAN }, |
Ike Panhc | c1f7365 | 2010-12-13 18:01:12 +0800 | [diff] [blame] | 444 | }; |
| 445 | |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 446 | static int ideapad_rfk_set(void *data, bool blocked) |
| 447 | { |
Ike Panhc | c1f7365 | 2010-12-13 18:01:12 +0800 | [diff] [blame] | 448 | unsigned long opcode = (unsigned long)data; |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 449 | |
Ike Panhc | c1f7365 | 2010-12-13 18:01:12 +0800 | [diff] [blame] | 450 | return write_ec_cmd(ideapad_handle, opcode, !blocked); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | static struct rfkill_ops ideapad_rfk_ops = { |
| 454 | .set_block = ideapad_rfk_set, |
| 455 | }; |
| 456 | |
Ike Panhc | 923de84 | 2011-09-06 02:32:01 +0800 | [diff] [blame] | 457 | static void ideapad_sync_rfk_state(struct ideapad_private *priv) |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 458 | { |
Ike Panhc | 2b7266b | 2010-10-01 15:39:49 +0800 | [diff] [blame] | 459 | unsigned long hw_blocked; |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 460 | int i; |
| 461 | |
Ike Panhc | 2be1dc2 | 2011-09-06 02:31:53 +0800 | [diff] [blame] | 462 | if (read_ec_data(ideapad_handle, VPCCMD_R_RF, &hw_blocked)) |
Ike Panhc | 2b7266b | 2010-10-01 15:39:49 +0800 | [diff] [blame] | 463 | return; |
| 464 | hw_blocked = !hw_blocked; |
| 465 | |
Ike Panhc | c1f7365 | 2010-12-13 18:01:12 +0800 | [diff] [blame] | 466 | for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 467 | if (priv->rfk[i]) |
| 468 | rfkill_set_hw_state(priv->rfk[i], hw_blocked); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 469 | } |
| 470 | |
Ike Panhc | a4b5a27 | 2010-12-13 18:00:48 +0800 | [diff] [blame] | 471 | static int __devinit ideapad_register_rfkill(struct acpi_device *adevice, |
| 472 | int dev) |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 473 | { |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 474 | struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 475 | int ret; |
Ike Panhc | 2b7266b | 2010-10-01 15:39:49 +0800 | [diff] [blame] | 476 | unsigned long sw_blocked; |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 477 | |
Ike Panhc | bfa97b7 | 2010-10-01 15:40:22 +0800 | [diff] [blame] | 478 | if (no_bt_rfkill && |
| 479 | (ideapad_rfk_data[dev].type == RFKILL_TYPE_BLUETOOTH)) { |
| 480 | /* Force to enable bluetooth when no_bt_rfkill=1 */ |
Ike Panhc | c1f7365 | 2010-12-13 18:01:12 +0800 | [diff] [blame] | 481 | write_ec_cmd(ideapad_handle, |
Ike Panhc | bfa97b7 | 2010-10-01 15:40:22 +0800 | [diff] [blame] | 482 | ideapad_rfk_data[dev].opcode, 1); |
| 483 | return 0; |
| 484 | } |
| 485 | |
Ike Panhc | 2b7266b | 2010-10-01 15:39:49 +0800 | [diff] [blame] | 486 | priv->rfk[dev] = rfkill_alloc(ideapad_rfk_data[dev].name, &adevice->dev, |
| 487 | ideapad_rfk_data[dev].type, &ideapad_rfk_ops, |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 488 | (void *)(long)dev); |
| 489 | if (!priv->rfk[dev]) |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 490 | return -ENOMEM; |
| 491 | |
Ike Panhc | c1f7365 | 2010-12-13 18:01:12 +0800 | [diff] [blame] | 492 | if (read_ec_data(ideapad_handle, ideapad_rfk_data[dev].opcode-1, |
Ike Panhc | 2b7266b | 2010-10-01 15:39:49 +0800 | [diff] [blame] | 493 | &sw_blocked)) { |
| 494 | rfkill_init_sw_state(priv->rfk[dev], 0); |
| 495 | } else { |
| 496 | sw_blocked = !sw_blocked; |
| 497 | rfkill_init_sw_state(priv->rfk[dev], sw_blocked); |
| 498 | } |
| 499 | |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 500 | ret = rfkill_register(priv->rfk[dev]); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 501 | if (ret) { |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 502 | rfkill_destroy(priv->rfk[dev]); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 503 | return ret; |
| 504 | } |
| 505 | return 0; |
| 506 | } |
| 507 | |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 508 | static void ideapad_unregister_rfkill(struct acpi_device *adevice, int dev) |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 509 | { |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 510 | struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); |
| 511 | |
| 512 | if (!priv->rfk[dev]) |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 513 | return; |
| 514 | |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 515 | rfkill_unregister(priv->rfk[dev]); |
| 516 | rfkill_destroy(priv->rfk[dev]); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 517 | } |
| 518 | |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 519 | /* |
| 520 | * Platform device |
| 521 | */ |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 522 | static int __devinit ideapad_platform_init(struct ideapad_private *priv) |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 523 | { |
| 524 | int result; |
| 525 | |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 526 | priv->platform_device = platform_device_alloc("ideapad", -1); |
| 527 | if (!priv->platform_device) |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 528 | return -ENOMEM; |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 529 | platform_set_drvdata(priv->platform_device, priv); |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 530 | |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 531 | result = platform_device_add(priv->platform_device); |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 532 | if (result) |
| 533 | goto fail_platform_device; |
| 534 | |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 535 | result = sysfs_create_group(&priv->platform_device->dev.kobj, |
Ike Panhc | c9f718d | 2010-12-13 18:00:27 +0800 | [diff] [blame] | 536 | &ideapad_attribute_group); |
| 537 | if (result) |
| 538 | goto fail_sysfs; |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 539 | return 0; |
| 540 | |
Ike Panhc | c9f718d | 2010-12-13 18:00:27 +0800 | [diff] [blame] | 541 | fail_sysfs: |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 542 | platform_device_del(priv->platform_device); |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 543 | fail_platform_device: |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 544 | platform_device_put(priv->platform_device); |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 545 | return result; |
| 546 | } |
| 547 | |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 548 | static void ideapad_platform_exit(struct ideapad_private *priv) |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 549 | { |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 550 | sysfs_remove_group(&priv->platform_device->dev.kobj, |
Ike Panhc | c9f718d | 2010-12-13 18:00:27 +0800 | [diff] [blame] | 551 | &ideapad_attribute_group); |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 552 | platform_device_unregister(priv->platform_device); |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 553 | } |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 554 | |
Ike Panhc | f63409a | 2010-12-13 18:00:38 +0800 | [diff] [blame] | 555 | /* |
| 556 | * input device |
| 557 | */ |
| 558 | static const struct key_entry ideapad_keymap[] = { |
Ike Panhc | f43d9ec | 2011-09-06 02:32:10 +0800 | [diff] [blame] | 559 | { KE_KEY, 6, { KEY_SWITCHVIDEOMODE } }, |
Maxim Mikityanskiy | 296f9fe | 2012-07-06 16:07:50 +0800 | [diff] [blame] | 560 | { KE_KEY, 7, { KEY_CAMERA } }, |
| 561 | { KE_KEY, 11, { KEY_F16 } }, |
Ike Panhc | f43d9ec | 2011-09-06 02:32:10 +0800 | [diff] [blame] | 562 | { KE_KEY, 13, { KEY_WLAN } }, |
| 563 | { KE_KEY, 16, { KEY_PROG1 } }, |
| 564 | { KE_KEY, 17, { KEY_PROG2 } }, |
Maxim Mikityanskiy | 296f9fe | 2012-07-06 16:07:50 +0800 | [diff] [blame] | 565 | { KE_KEY, 64, { KEY_PROG3 } }, |
| 566 | { KE_KEY, 65, { KEY_PROG4 } }, |
Maxim Mikityanskiy | 07a4a4f | 2012-07-06 16:08:00 +0800 | [diff] [blame] | 567 | { KE_KEY, 66, { KEY_TOUCHPAD_OFF } }, |
| 568 | { KE_KEY, 67, { KEY_TOUCHPAD_ON } }, |
Ike Panhc | f63409a | 2010-12-13 18:00:38 +0800 | [diff] [blame] | 569 | { KE_END, 0 }, |
| 570 | }; |
| 571 | |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 572 | static int __devinit ideapad_input_init(struct ideapad_private *priv) |
Ike Panhc | f63409a | 2010-12-13 18:00:38 +0800 | [diff] [blame] | 573 | { |
| 574 | struct input_dev *inputdev; |
| 575 | int error; |
| 576 | |
| 577 | inputdev = input_allocate_device(); |
| 578 | if (!inputdev) { |
| 579 | pr_info("Unable to allocate input device\n"); |
| 580 | return -ENOMEM; |
| 581 | } |
| 582 | |
| 583 | inputdev->name = "Ideapad extra buttons"; |
| 584 | inputdev->phys = "ideapad/input0"; |
| 585 | inputdev->id.bustype = BUS_HOST; |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 586 | inputdev->dev.parent = &priv->platform_device->dev; |
Ike Panhc | f63409a | 2010-12-13 18:00:38 +0800 | [diff] [blame] | 587 | |
| 588 | error = sparse_keymap_setup(inputdev, ideapad_keymap, NULL); |
| 589 | if (error) { |
| 590 | pr_err("Unable to setup input device keymap\n"); |
| 591 | goto err_free_dev; |
| 592 | } |
| 593 | |
| 594 | error = input_register_device(inputdev); |
| 595 | if (error) { |
| 596 | pr_err("Unable to register input device\n"); |
| 597 | goto err_free_keymap; |
| 598 | } |
| 599 | |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 600 | priv->inputdev = inputdev; |
Ike Panhc | f63409a | 2010-12-13 18:00:38 +0800 | [diff] [blame] | 601 | return 0; |
| 602 | |
| 603 | err_free_keymap: |
| 604 | sparse_keymap_free(inputdev); |
| 605 | err_free_dev: |
| 606 | input_free_device(inputdev); |
| 607 | return error; |
| 608 | } |
| 609 | |
Axel Lin | 7451a55 | 2011-07-27 15:27:34 +0800 | [diff] [blame] | 610 | static void ideapad_input_exit(struct ideapad_private *priv) |
Ike Panhc | f63409a | 2010-12-13 18:00:38 +0800 | [diff] [blame] | 611 | { |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 612 | sparse_keymap_free(priv->inputdev); |
| 613 | input_unregister_device(priv->inputdev); |
| 614 | priv->inputdev = NULL; |
Ike Panhc | f63409a | 2010-12-13 18:00:38 +0800 | [diff] [blame] | 615 | } |
| 616 | |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 617 | static void ideapad_input_report(struct ideapad_private *priv, |
| 618 | unsigned long scancode) |
Ike Panhc | f63409a | 2010-12-13 18:00:38 +0800 | [diff] [blame] | 619 | { |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 620 | sparse_keymap_report_event(priv->inputdev, scancode, 1, true); |
Ike Panhc | f63409a | 2010-12-13 18:00:38 +0800 | [diff] [blame] | 621 | } |
Ike Panhc | f63409a | 2010-12-13 18:00:38 +0800 | [diff] [blame] | 622 | |
Ike Panhc | f43d9ec | 2011-09-06 02:32:10 +0800 | [diff] [blame] | 623 | static void ideapad_input_novokey(struct ideapad_private *priv) |
| 624 | { |
| 625 | unsigned long long_pressed; |
| 626 | |
| 627 | if (read_ec_data(ideapad_handle, VPCCMD_R_NOVO, &long_pressed)) |
| 628 | return; |
| 629 | if (long_pressed) |
| 630 | ideapad_input_report(priv, 17); |
| 631 | else |
| 632 | ideapad_input_report(priv, 16); |
| 633 | } |
| 634 | |
Maxim Mikityanskiy | 296f9fe | 2012-07-06 16:07:50 +0800 | [diff] [blame] | 635 | static void ideapad_check_special_buttons(struct ideapad_private *priv) |
| 636 | { |
| 637 | unsigned long bit, value; |
| 638 | |
| 639 | read_ec_data(ideapad_handle, VPCCMD_R_SPECIAL_BUTTONS, &value); |
| 640 | |
| 641 | for (bit = 0; bit < 16; bit++) { |
| 642 | if (test_bit(bit, &value)) { |
| 643 | switch (bit) { |
| 644 | case 6: |
| 645 | /* Thermal Management button */ |
| 646 | ideapad_input_report(priv, 65); |
| 647 | break; |
| 648 | case 1: |
| 649 | /* OneKey Theater button */ |
| 650 | ideapad_input_report(priv, 64); |
| 651 | break; |
| 652 | } |
| 653 | } |
| 654 | } |
| 655 | } |
| 656 | |
Ike Panhc | a4b5a27 | 2010-12-13 18:00:48 +0800 | [diff] [blame] | 657 | /* |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 658 | * backlight |
| 659 | */ |
| 660 | static int ideapad_backlight_get_brightness(struct backlight_device *blightdev) |
| 661 | { |
| 662 | unsigned long now; |
| 663 | |
Ike Panhc | 2be1dc2 | 2011-09-06 02:31:53 +0800 | [diff] [blame] | 664 | if (read_ec_data(ideapad_handle, VPCCMD_R_BL, &now)) |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 665 | return -EIO; |
| 666 | return now; |
| 667 | } |
| 668 | |
| 669 | static int ideapad_backlight_update_status(struct backlight_device *blightdev) |
| 670 | { |
Ike Panhc | 2be1dc2 | 2011-09-06 02:31:53 +0800 | [diff] [blame] | 671 | if (write_ec_cmd(ideapad_handle, VPCCMD_W_BL, |
| 672 | blightdev->props.brightness)) |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 673 | return -EIO; |
Ike Panhc | 2be1dc2 | 2011-09-06 02:31:53 +0800 | [diff] [blame] | 674 | if (write_ec_cmd(ideapad_handle, VPCCMD_W_BL_POWER, |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 675 | blightdev->props.power == FB_BLANK_POWERDOWN ? 0 : 1)) |
| 676 | return -EIO; |
| 677 | |
| 678 | return 0; |
| 679 | } |
| 680 | |
| 681 | static const struct backlight_ops ideapad_backlight_ops = { |
| 682 | .get_brightness = ideapad_backlight_get_brightness, |
| 683 | .update_status = ideapad_backlight_update_status, |
| 684 | }; |
| 685 | |
| 686 | static int ideapad_backlight_init(struct ideapad_private *priv) |
| 687 | { |
| 688 | struct backlight_device *blightdev; |
| 689 | struct backlight_properties props; |
| 690 | unsigned long max, now, power; |
| 691 | |
Ike Panhc | 2be1dc2 | 2011-09-06 02:31:53 +0800 | [diff] [blame] | 692 | if (read_ec_data(ideapad_handle, VPCCMD_R_BL_MAX, &max)) |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 693 | return -EIO; |
Ike Panhc | 2be1dc2 | 2011-09-06 02:31:53 +0800 | [diff] [blame] | 694 | if (read_ec_data(ideapad_handle, VPCCMD_R_BL, &now)) |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 695 | return -EIO; |
Ike Panhc | 2be1dc2 | 2011-09-06 02:31:53 +0800 | [diff] [blame] | 696 | if (read_ec_data(ideapad_handle, VPCCMD_R_BL_POWER, &power)) |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 697 | return -EIO; |
| 698 | |
| 699 | memset(&props, 0, sizeof(struct backlight_properties)); |
| 700 | props.max_brightness = max; |
| 701 | props.type = BACKLIGHT_PLATFORM; |
| 702 | blightdev = backlight_device_register("ideapad", |
| 703 | &priv->platform_device->dev, |
| 704 | priv, |
| 705 | &ideapad_backlight_ops, |
| 706 | &props); |
| 707 | if (IS_ERR(blightdev)) { |
| 708 | pr_err("Could not register backlight device\n"); |
| 709 | return PTR_ERR(blightdev); |
| 710 | } |
| 711 | |
| 712 | priv->blightdev = blightdev; |
| 713 | blightdev->props.brightness = now; |
| 714 | blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; |
| 715 | backlight_update_status(blightdev); |
| 716 | |
| 717 | return 0; |
| 718 | } |
| 719 | |
| 720 | static void ideapad_backlight_exit(struct ideapad_private *priv) |
| 721 | { |
| 722 | if (priv->blightdev) |
| 723 | backlight_device_unregister(priv->blightdev); |
| 724 | priv->blightdev = NULL; |
| 725 | } |
| 726 | |
| 727 | static void ideapad_backlight_notify_power(struct ideapad_private *priv) |
| 728 | { |
| 729 | unsigned long power; |
| 730 | struct backlight_device *blightdev = priv->blightdev; |
| 731 | |
Rene Bollford | d4afc77 | 2011-10-23 09:56:42 +0200 | [diff] [blame] | 732 | if (!blightdev) |
| 733 | return; |
Ike Panhc | 2be1dc2 | 2011-09-06 02:31:53 +0800 | [diff] [blame] | 734 | if (read_ec_data(ideapad_handle, VPCCMD_R_BL_POWER, &power)) |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 735 | return; |
| 736 | blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; |
| 737 | } |
| 738 | |
| 739 | static void ideapad_backlight_notify_brightness(struct ideapad_private *priv) |
| 740 | { |
| 741 | unsigned long now; |
| 742 | |
| 743 | /* if we control brightness via acpi video driver */ |
| 744 | if (priv->blightdev == NULL) { |
Ike Panhc | 2be1dc2 | 2011-09-06 02:31:53 +0800 | [diff] [blame] | 745 | read_ec_data(ideapad_handle, VPCCMD_R_BL, &now); |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 746 | return; |
| 747 | } |
| 748 | |
| 749 | backlight_force_update(priv->blightdev, BACKLIGHT_UPDATE_HOTKEY); |
| 750 | } |
| 751 | |
| 752 | /* |
Ike Panhc | a4b5a27 | 2010-12-13 18:00:48 +0800 | [diff] [blame] | 753 | * module init/exit |
| 754 | */ |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 755 | static const struct acpi_device_id ideapad_device_ids[] = { |
| 756 | { "VPC2004", 0}, |
| 757 | { "", 0}, |
| 758 | }; |
| 759 | MODULE_DEVICE_TABLE(acpi, ideapad_device_ids); |
| 760 | |
Maxim Mikityanskiy | 07a4a4f | 2012-07-06 16:08:00 +0800 | [diff] [blame] | 761 | static void ideapad_sync_touchpad_state(struct acpi_device *adevice) |
| 762 | { |
| 763 | struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); |
| 764 | unsigned long value; |
| 765 | |
| 766 | /* Without reading from EC touchpad LED doesn't switch state */ |
| 767 | if (!read_ec_data(adevice->handle, VPCCMD_R_TOUCHPAD, &value)) { |
| 768 | /* Some IdeaPads don't really turn off touchpad - they only |
| 769 | * switch the LED state. We (de)activate KBC AUX port to turn |
| 770 | * touchpad off and on. We send KEY_TOUCHPAD_OFF and |
| 771 | * KEY_TOUCHPAD_ON to not to get out of sync with LED */ |
| 772 | unsigned char param; |
| 773 | i8042_command(¶m, value ? I8042_CMD_AUX_ENABLE : |
| 774 | I8042_CMD_AUX_DISABLE); |
| 775 | ideapad_input_report(priv, value ? 67 : 66); |
| 776 | } |
| 777 | } |
| 778 | |
Ike Panhc | a4b5a27 | 2010-12-13 18:00:48 +0800 | [diff] [blame] | 779 | static int __devinit ideapad_acpi_add(struct acpi_device *adevice) |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 780 | { |
Ike Panhc | 3371f48 | 2011-06-30 19:50:40 +0800 | [diff] [blame] | 781 | int ret, i; |
Dan Carpenter | 57f9616 | 2012-06-12 19:28:50 +0300 | [diff] [blame] | 782 | int cfg; |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 783 | struct ideapad_private *priv; |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 784 | |
Dan Carpenter | 57f9616 | 2012-06-12 19:28:50 +0300 | [diff] [blame] | 785 | if (read_method_int(adevice->handle, "_CFG", &cfg)) |
Ike Panhc | 6f8371c | 2010-10-01 15:39:14 +0800 | [diff] [blame] | 786 | return -ENODEV; |
| 787 | |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 788 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 789 | if (!priv) |
| 790 | return -ENOMEM; |
Ike Panhc | c9f718d | 2010-12-13 18:00:27 +0800 | [diff] [blame] | 791 | dev_set_drvdata(&adevice->dev, priv); |
Ike Panhc | 773e320 | 2011-09-06 02:32:52 +0800 | [diff] [blame] | 792 | ideapad_priv = priv; |
Ike Panhc | c1f7365 | 2010-12-13 18:01:12 +0800 | [diff] [blame] | 793 | ideapad_handle = adevice->handle; |
Ike Panhc | 3371f48 | 2011-06-30 19:50:40 +0800 | [diff] [blame] | 794 | priv->cfg = cfg; |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 795 | |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 796 | ret = ideapad_platform_init(priv); |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 797 | if (ret) |
| 798 | goto platform_failed; |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 799 | |
Ike Panhc | 773e320 | 2011-09-06 02:32:52 +0800 | [diff] [blame] | 800 | ret = ideapad_debugfs_init(priv); |
| 801 | if (ret) |
| 802 | goto debugfs_failed; |
| 803 | |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 804 | ret = ideapad_input_init(priv); |
Ike Panhc | f63409a | 2010-12-13 18:00:38 +0800 | [diff] [blame] | 805 | if (ret) |
| 806 | goto input_failed; |
| 807 | |
Ike Panhc | c1f7365 | 2010-12-13 18:01:12 +0800 | [diff] [blame] | 808 | for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) { |
Dan Carpenter | 57f9616 | 2012-06-12 19:28:50 +0300 | [diff] [blame] | 809 | if (test_bit(ideapad_rfk_data[i].cfgbit, &priv->cfg)) |
Ike Panhc | c9f718d | 2010-12-13 18:00:27 +0800 | [diff] [blame] | 810 | ideapad_register_rfkill(adevice, i); |
Ike Panhc | c1f7365 | 2010-12-13 18:01:12 +0800 | [diff] [blame] | 811 | else |
| 812 | priv->rfk[i] = NULL; |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 813 | } |
Ike Panhc | 923de84 | 2011-09-06 02:32:01 +0800 | [diff] [blame] | 814 | ideapad_sync_rfk_state(priv); |
Maxim Mikityanskiy | 07a4a4f | 2012-07-06 16:08:00 +0800 | [diff] [blame] | 815 | ideapad_sync_touchpad_state(adevice); |
Ike Panhc | c9f718d | 2010-12-13 18:00:27 +0800 | [diff] [blame] | 816 | |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 817 | if (!acpi_video_backlight_support()) { |
| 818 | ret = ideapad_backlight_init(priv); |
| 819 | if (ret && ret != -ENODEV) |
| 820 | goto backlight_failed; |
| 821 | } |
| 822 | |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 823 | return 0; |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 824 | |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 825 | backlight_failed: |
| 826 | for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) |
| 827 | ideapad_unregister_rfkill(adevice, i); |
Axel Lin | 7451a55 | 2011-07-27 15:27:34 +0800 | [diff] [blame] | 828 | ideapad_input_exit(priv); |
Ike Panhc | f63409a | 2010-12-13 18:00:38 +0800 | [diff] [blame] | 829 | input_failed: |
Ike Panhc | 773e320 | 2011-09-06 02:32:52 +0800 | [diff] [blame] | 830 | ideapad_debugfs_exit(priv); |
| 831 | debugfs_failed: |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 832 | ideapad_platform_exit(priv); |
Ike Panhc | 98ee691 | 2010-12-13 18:00:15 +0800 | [diff] [blame] | 833 | platform_failed: |
| 834 | kfree(priv); |
| 835 | return ret; |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 836 | } |
| 837 | |
Ike Panhc | a4b5a27 | 2010-12-13 18:00:48 +0800 | [diff] [blame] | 838 | static int __devexit ideapad_acpi_remove(struct acpi_device *adevice, int type) |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 839 | { |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 840 | struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 841 | int i; |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 842 | |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 843 | ideapad_backlight_exit(priv); |
Ike Panhc | c1f7365 | 2010-12-13 18:01:12 +0800 | [diff] [blame] | 844 | for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 845 | ideapad_unregister_rfkill(adevice, i); |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 846 | ideapad_input_exit(priv); |
Ike Panhc | 773e320 | 2011-09-06 02:32:52 +0800 | [diff] [blame] | 847 | ideapad_debugfs_exit(priv); |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 848 | ideapad_platform_exit(priv); |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 849 | dev_set_drvdata(&adevice->dev, NULL); |
| 850 | kfree(priv); |
Ike Panhc | c9f718d | 2010-12-13 18:00:27 +0800 | [diff] [blame] | 851 | |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 852 | return 0; |
| 853 | } |
| 854 | |
David Woodhouse | ce32632 | 2010-08-11 17:59:35 +0100 | [diff] [blame] | 855 | static void ideapad_acpi_notify(struct acpi_device *adevice, u32 event) |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 856 | { |
Ike Panhc | 8693ae8 | 2010-12-13 18:01:01 +0800 | [diff] [blame] | 857 | struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); |
Ike Panhc | 8e7d354 | 2010-10-01 15:39:05 +0800 | [diff] [blame] | 858 | acpi_handle handle = adevice->handle; |
| 859 | unsigned long vpc1, vpc2, vpc_bit; |
| 860 | |
Ike Panhc | 2be1dc2 | 2011-09-06 02:31:53 +0800 | [diff] [blame] | 861 | if (read_ec_data(handle, VPCCMD_R_VPC1, &vpc1)) |
Ike Panhc | 8e7d354 | 2010-10-01 15:39:05 +0800 | [diff] [blame] | 862 | return; |
Ike Panhc | 2be1dc2 | 2011-09-06 02:31:53 +0800 | [diff] [blame] | 863 | if (read_ec_data(handle, VPCCMD_R_VPC2, &vpc2)) |
Ike Panhc | 8e7d354 | 2010-10-01 15:39:05 +0800 | [diff] [blame] | 864 | return; |
| 865 | |
| 866 | vpc1 = (vpc2 << 8) | vpc1; |
| 867 | for (vpc_bit = 0; vpc_bit < 16; vpc_bit++) { |
| 868 | if (test_bit(vpc_bit, &vpc1)) { |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 869 | switch (vpc_bit) { |
| 870 | case 9: |
Ike Panhc | 923de84 | 2011-09-06 02:32:01 +0800 | [diff] [blame] | 871 | ideapad_sync_rfk_state(priv); |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 872 | break; |
Ike Panhc | 20a769c | 2012-05-03 17:38:46 +0800 | [diff] [blame] | 873 | case 13: |
Maxim Mikityanskiy | 296f9fe | 2012-07-06 16:07:50 +0800 | [diff] [blame] | 874 | case 11: |
| 875 | case 7: |
Ike Panhc | 20a769c | 2012-05-03 17:38:46 +0800 | [diff] [blame] | 876 | case 6: |
| 877 | ideapad_input_report(priv, vpc_bit); |
| 878 | break; |
Maxim Mikityanskiy | 07a4a4f | 2012-07-06 16:08:00 +0800 | [diff] [blame] | 879 | case 5: |
| 880 | ideapad_sync_touchpad_state(adevice); |
| 881 | break; |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 882 | case 4: |
| 883 | ideapad_backlight_notify_brightness(priv); |
| 884 | break; |
Ike Panhc | f43d9ec | 2011-09-06 02:32:10 +0800 | [diff] [blame] | 885 | case 3: |
| 886 | ideapad_input_novokey(priv); |
| 887 | break; |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 888 | case 2: |
| 889 | ideapad_backlight_notify_power(priv); |
| 890 | break; |
Maxim Mikityanskiy | 296f9fe | 2012-07-06 16:07:50 +0800 | [diff] [blame] | 891 | case 0: |
| 892 | ideapad_check_special_buttons(priv); |
| 893 | break; |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 894 | default: |
Ike Panhc | 20a769c | 2012-05-03 17:38:46 +0800 | [diff] [blame] | 895 | pr_info("Unknown event: %lu\n", vpc_bit); |
Ike Panhc | a4ecbb8 | 2011-06-30 19:50:52 +0800 | [diff] [blame] | 896 | } |
Ike Panhc | 8e7d354 | 2010-10-01 15:39:05 +0800 | [diff] [blame] | 897 | } |
| 898 | } |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 899 | } |
| 900 | |
Maxim Mikityanskiy | 07a4a4f | 2012-07-06 16:08:00 +0800 | [diff] [blame] | 901 | static int ideapad_acpi_resume(struct device *device) |
| 902 | { |
| 903 | ideapad_sync_rfk_state(ideapad_priv); |
| 904 | ideapad_sync_touchpad_state(to_acpi_device(device)); |
| 905 | return 0; |
| 906 | } |
| 907 | |
| 908 | static SIMPLE_DEV_PM_OPS(ideapad_pm, NULL, ideapad_acpi_resume); |
| 909 | |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 910 | static struct acpi_driver ideapad_acpi_driver = { |
| 911 | .name = "ideapad_acpi", |
| 912 | .class = "IdeaPad", |
| 913 | .ids = ideapad_device_ids, |
| 914 | .ops.add = ideapad_acpi_add, |
| 915 | .ops.remove = ideapad_acpi_remove, |
| 916 | .ops.notify = ideapad_acpi_notify, |
Maxim Mikityanskiy | 07a4a4f | 2012-07-06 16:08:00 +0800 | [diff] [blame] | 917 | .drv.pm = &ideapad_pm, |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 918 | .owner = THIS_MODULE, |
| 919 | }; |
| 920 | |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 921 | static int __init ideapad_acpi_module_init(void) |
| 922 | { |
Ike Panhc | a4b5a27 | 2010-12-13 18:00:48 +0800 | [diff] [blame] | 923 | return acpi_bus_register_driver(&ideapad_acpi_driver); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 924 | } |
| 925 | |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 926 | static void __exit ideapad_acpi_module_exit(void) |
| 927 | { |
| 928 | acpi_bus_unregister_driver(&ideapad_acpi_driver); |
David Woodhouse | 58ac7aa | 2010-08-10 23:44:05 +0100 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); |
| 932 | MODULE_DESCRIPTION("IdeaPad ACPI Extras"); |
| 933 | MODULE_LICENSE("GPL"); |
| 934 | |
| 935 | module_init(ideapad_acpi_module_init); |
| 936 | module_exit(ideapad_acpi_module_exit); |