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