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