blob: 19ec95147f6925d1de52e99886f7efc6a10dff7a [file] [log] [blame]
David Woodhouse58ac7aa2010-08-10 23:44:05 +01001/*
Ike Panhca4b5a272010-12-13 18:00:48 +08002 * ideapad-laptop.c - Lenovo IdeaPad ACPI Extras
David Woodhouse58ac7aa2010-08-10 23:44:05 +01003 *
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 Perches9ab23982011-03-29 15:21:43 -070023#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
David Woodhouse58ac7aa2010-08-10 23:44:05 +010025#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 Panhc98ee6912010-12-13 18:00:15 +080032#include <linux/platform_device.h>
Ike Panhcf63409a2010-12-13 18:00:38 +080033#include <linux/input.h>
34#include <linux/input/sparse-keymap.h>
Ike Panhca4ecbb82011-06-30 19:50:52 +080035#include <linux/backlight.h>
36#include <linux/fb.h>
Ike Panhc773e3202011-09-06 02:32:52 +080037#include <linux/debugfs.h>
38#include <linux/seq_file.h>
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +080039#include <linux/i8042.h>
David Woodhouse58ac7aa2010-08-10 23:44:05 +010040
Ike Panhcc1f73652010-12-13 18:01:12 +080041#define IDEAPAD_RFKILL_DEV_NUM (3)
David Woodhouse58ac7aa2010-08-10 23:44:05 +010042
Ike Panhc3371f482011-06-30 19:50:40 +080043#define CFG_BT_BIT (16)
44#define CFG_3G_BIT (17)
45#define CFG_WIFI_BIT (18)
Ike Panhca84511f2011-06-30 19:50:47 +080046#define CFG_CAMERA_BIT (19)
Ike Panhc3371f482011-06-30 19:50:40 +080047
Ike Panhc2be1dc22011-09-06 02:31:53 +080048enum {
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 Mikityanskiy0c7bbeb92012-07-06 16:08:11 +080067 VPCCMD_W_FAN,
68 VPCCMD_R_RF,
Ike Panhc2be1dc22011-09-06 02:31:53 +080069 VPCCMD_W_RF,
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +080070 VPCCMD_R_FAN = 0x2B,
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +080071 VPCCMD_R_SPECIAL_BUTTONS = 0x31,
Ike Panhc2be1dc22011-09-06 02:31:53 +080072 VPCCMD_W_BL_POWER = 0x33,
73};
74
Zhang Rui331e0ea2013-09-25 20:39:49 +080075struct ideapad_rfk_priv {
76 int dev;
77 struct ideapad_private *priv;
78};
79
David Woodhousece326322010-08-11 17:59:35 +010080struct ideapad_private {
Zhang Rui469f6432013-09-25 20:39:47 +080081 struct acpi_device *adev;
Ike Panhcc1f73652010-12-13 18:01:12 +080082 struct rfkill *rfk[IDEAPAD_RFKILL_DEV_NUM];
Zhang Rui331e0ea2013-09-25 20:39:49 +080083 struct ideapad_rfk_priv rfk_priv[IDEAPAD_RFKILL_DEV_NUM];
Ike Panhc98ee6912010-12-13 18:00:15 +080084 struct platform_device *platform_device;
Ike Panhcf63409a2010-12-13 18:00:38 +080085 struct input_dev *inputdev;
Ike Panhca4ecbb82011-06-30 19:50:52 +080086 struct backlight_device *blightdev;
Ike Panhc773e3202011-09-06 02:32:52 +080087 struct dentry *debug;
Ike Panhc3371f482011-06-30 19:50:40 +080088 unsigned long cfg;
David Woodhouse58ac7aa2010-08-10 23:44:05 +010089};
90
Ike Panhcbfa97b72010-10-01 15:40:22 +080091static bool no_bt_rfkill;
92module_param(no_bt_rfkill, bool, 0444);
93MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth.");
94
Ike Panhc6a09f212010-10-01 15:38:46 +080095/*
96 * ACPI Helpers
97 */
98#define IDEAPAD_EC_TIMEOUT (100) /* in ms */
99
100static 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
115static 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", &params, &result);
128
129 if (ACPI_FAILURE(status)) {
130 *ret = -1;
131 return -1;
132 } else {
133 *ret = result;
134 return 0;
135 }
136}
137
138static 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", &params, NULL);
152 if (status != AE_OK)
153 return -1;
154 return 0;
155}
156
157static 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
181static 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 Panhc6a09f212010-10-01 15:38:46 +0800202
Ike Panhca4b5a272010-12-13 18:00:48 +0800203/*
Ike Panhc773e3202011-09-06 02:32:52 +0800204 * debugfs
205 */
Ike Panhc773e3202011-09-06 02:32:52 +0800206static int debugfs_status_show(struct seq_file *s, void *data)
207{
Zhang Rui331e0ea2013-09-25 20:39:49 +0800208 struct ideapad_private *priv = s->private;
Ike Panhc773e3202011-09-06 02:32:52 +0800209 unsigned long value;
210
Zhang Rui331e0ea2013-09-25 20:39:49 +0800211 if (!priv)
212 return -EINVAL;
213
214 if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &value))
Ike Panhc773e3202011-09-06 02:32:52 +0800215 seq_printf(s, "Backlight max:\t%lu\n", value);
Zhang Rui331e0ea2013-09-25 20:39:49 +0800216 if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL, &value))
Ike Panhc773e3202011-09-06 02:32:52 +0800217 seq_printf(s, "Backlight now:\t%lu\n", value);
Zhang Rui331e0ea2013-09-25 20:39:49 +0800218 if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &value))
Ike Panhc773e3202011-09-06 02:32:52 +0800219 seq_printf(s, "BL power value:\t%s\n", value ? "On" : "Off");
220 seq_printf(s, "=====================\n");
221
Zhang Rui331e0ea2013-09-25 20:39:49 +0800222 if (!read_ec_data(priv->adev->handle, VPCCMD_R_RF, &value))
Ike Panhc773e3202011-09-06 02:32:52 +0800223 seq_printf(s, "Radio status:\t%s(%lu)\n",
224 value ? "On" : "Off", value);
Zhang Rui331e0ea2013-09-25 20:39:49 +0800225 if (!read_ec_data(priv->adev->handle, VPCCMD_R_WIFI, &value))
Ike Panhc773e3202011-09-06 02:32:52 +0800226 seq_printf(s, "Wifi status:\t%s(%lu)\n",
227 value ? "On" : "Off", value);
Zhang Rui331e0ea2013-09-25 20:39:49 +0800228 if (!read_ec_data(priv->adev->handle, VPCCMD_R_BT, &value))
Ike Panhc773e3202011-09-06 02:32:52 +0800229 seq_printf(s, "BT status:\t%s(%lu)\n",
230 value ? "On" : "Off", value);
Zhang Rui331e0ea2013-09-25 20:39:49 +0800231 if (!read_ec_data(priv->adev->handle, VPCCMD_R_3G, &value))
Ike Panhc773e3202011-09-06 02:32:52 +0800232 seq_printf(s, "3G status:\t%s(%lu)\n",
233 value ? "On" : "Off", value);
234 seq_printf(s, "=====================\n");
235
Zhang Rui331e0ea2013-09-25 20:39:49 +0800236 if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value))
Ike Panhc773e3202011-09-06 02:32:52 +0800237 seq_printf(s, "Touchpad status:%s(%lu)\n",
238 value ? "On" : "Off", value);
Zhang Rui331e0ea2013-09-25 20:39:49 +0800239 if (!read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &value))
Ike Panhc773e3202011-09-06 02:32:52 +0800240 seq_printf(s, "Camera status:\t%s(%lu)\n",
241 value ? "On" : "Off", value);
242
243 return 0;
244}
245
246static int debugfs_status_open(struct inode *inode, struct file *file)
247{
Zhang Rui331e0ea2013-09-25 20:39:49 +0800248 return single_open(file, debugfs_status_show, inode->i_private);
Ike Panhc773e3202011-09-06 02:32:52 +0800249}
250
251static 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
259static int debugfs_cfg_show(struct seq_file *s, void *data)
260{
Zhang Rui331e0ea2013-09-25 20:39:49 +0800261 struct ideapad_private *priv = s->private;
262
263 if (!priv) {
Ike Panhc773e3202011-09-06 02:32:52 +0800264 seq_printf(s, "cfg: N/A\n");
265 } else {
266 seq_printf(s, "cfg: 0x%.8lX\n\nCapability: ",
Zhang Rui331e0ea2013-09-25 20:39:49 +0800267 priv->cfg);
268 if (test_bit(CFG_BT_BIT, &priv->cfg))
Ike Panhc773e3202011-09-06 02:32:52 +0800269 seq_printf(s, "Bluetooth ");
Zhang Rui331e0ea2013-09-25 20:39:49 +0800270 if (test_bit(CFG_3G_BIT, &priv->cfg))
Ike Panhc773e3202011-09-06 02:32:52 +0800271 seq_printf(s, "3G ");
Zhang Rui331e0ea2013-09-25 20:39:49 +0800272 if (test_bit(CFG_WIFI_BIT, &priv->cfg))
Ike Panhc773e3202011-09-06 02:32:52 +0800273 seq_printf(s, "Wireless ");
Zhang Rui331e0ea2013-09-25 20:39:49 +0800274 if (test_bit(CFG_CAMERA_BIT, &priv->cfg))
Ike Panhc773e3202011-09-06 02:32:52 +0800275 seq_printf(s, "Camera ");
276 seq_printf(s, "\nGraphic: ");
Zhang Rui331e0ea2013-09-25 20:39:49 +0800277 switch ((priv->cfg)&0x700) {
Ike Panhc773e3202011-09-06 02:32:52 +0800278 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
299static int debugfs_cfg_open(struct inode *inode, struct file *file)
300{
Zhang Rui331e0ea2013-09-25 20:39:49 +0800301 return single_open(file, debugfs_cfg_show, inode->i_private);
Ike Panhc773e3202011-09-06 02:32:52 +0800302}
303
304static 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-Hartmanb859f152012-12-21 13:18:33 -0800312static int ideapad_debugfs_init(struct ideapad_private *priv)
Ike Panhc773e3202011-09-06 02:32:52 +0800313{
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 Rui331e0ea2013-09-25 20:39:49 +0800322 node = debugfs_create_file("cfg", S_IRUGO, priv->debug, priv,
Ike Panhc773e3202011-09-06 02:32:52 +0800323 &debugfs_cfg_fops);
324 if (!node) {
325 pr_err("failed to create cfg in debugfs");
326 goto errout;
327 }
328
Zhang Rui331e0ea2013-09-25 20:39:49 +0800329 node = debugfs_create_file("status", S_IRUGO, priv->debug, priv,
Ike Panhc773e3202011-09-06 02:32:52 +0800330 &debugfs_status_fops);
331 if (!node) {
Ike Panhca5c38922012-05-03 17:38:35 +0800332 pr_err("failed to create status in debugfs");
Ike Panhc773e3202011-09-06 02:32:52 +0800333 goto errout;
334 }
335
336 return 0;
337
338errout:
339 return -ENOMEM;
340}
341
342static void ideapad_debugfs_exit(struct ideapad_private *priv)
343{
344 debugfs_remove_recursive(priv->debug);
345 priv->debug = NULL;
346}
347
348/*
Ike Panhc3371f482011-06-30 19:50:40 +0800349 * sysfs
Ike Panhca4b5a272010-12-13 18:00:48 +0800350 */
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100351static ssize_t show_ideapad_cam(struct device *dev,
352 struct device_attribute *attr,
353 char *buf)
354{
Ike Panhc26c81d52010-10-01 15:39:40 +0800355 unsigned long result;
Zhang Rui331e0ea2013-09-25 20:39:49 +0800356 struct ideapad_private *priv = dev_get_drvdata(dev);
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100357
Zhang Rui331e0ea2013-09-25 20:39:49 +0800358 if (read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &result))
Ike Panhc26c81d52010-10-01 15:39:40 +0800359 return sprintf(buf, "-1\n");
360 return sprintf(buf, "%lu\n", result);
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100361}
362
363static 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 Rui331e0ea2013-09-25 20:39:49 +0800368 struct ideapad_private *priv = dev_get_drvdata(dev);
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100369
370 if (!count)
371 return 0;
372 if (sscanf(buf, "%i", &state) != 1)
373 return -EINVAL;
Zhang Rui331e0ea2013-09-25 20:39:49 +0800374 ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_CAMERA, state);
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100375 if (ret < 0)
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +0800376 return -EIO;
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100377 return count;
378}
379
380static DEVICE_ATTR(camera_power, 0644, show_ideapad_cam, store_ideapad_cam);
381
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +0800382static ssize_t show_ideapad_fan(struct device *dev,
383 struct device_attribute *attr,
384 char *buf)
385{
386 unsigned long result;
Zhang Rui331e0ea2013-09-25 20:39:49 +0800387 struct ideapad_private *priv = dev_get_drvdata(dev);
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +0800388
Zhang Rui331e0ea2013-09-25 20:39:49 +0800389 if (read_ec_data(priv->adev->handle, VPCCMD_R_FAN, &result))
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +0800390 return sprintf(buf, "-1\n");
391 return sprintf(buf, "%lu\n", result);
392}
393
394static 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 Rui331e0ea2013-09-25 20:39:49 +0800399 struct ideapad_private *priv = dev_get_drvdata(dev);
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +0800400
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 Rui331e0ea2013-09-25 20:39:49 +0800407 ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_FAN, state);
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +0800408 if (ret < 0)
409 return -EIO;
410 return count;
411}
412
413static DEVICE_ATTR(fan_mode, 0644, show_ideapad_fan, store_ideapad_fan);
414
Ike Panhc3371f482011-06-30 19:50:40 +0800415static struct attribute *ideapad_attributes[] = {
416 &dev_attr_camera_power.attr,
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +0800417 &dev_attr_fan_mode.attr,
Ike Panhc3371f482011-06-30 19:50:40 +0800418 NULL
419};
420
Al Viro587a1f12011-07-23 23:11:19 -0400421static umode_t ideapad_is_visible(struct kobject *kobj,
Ike Panhca84511f2011-06-30 19:50:47 +0800422 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 Mikityanskiy0c7bbeb92012-07-06 16:08:11 +0800431 else if (attr == &dev_attr_fan_mode.attr) {
432 unsigned long value;
Zhang Rui331e0ea2013-09-25 20:39:49 +0800433 supported = !read_ec_data(priv->adev->handle, VPCCMD_R_FAN,
434 &value);
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +0800435 } else
Ike Panhca84511f2011-06-30 19:50:47 +0800436 supported = true;
437
438 return supported ? attr->mode : 0;
439}
440
Ike Panhc3371f482011-06-30 19:50:40 +0800441static struct attribute_group ideapad_attribute_group = {
Ike Panhca84511f2011-06-30 19:50:47 +0800442 .is_visible = ideapad_is_visible,
Ike Panhc3371f482011-06-30 19:50:40 +0800443 .attrs = ideapad_attributes
444};
445
Ike Panhca4b5a272010-12-13 18:00:48 +0800446/*
447 * Rfkill
448 */
Ike Panhcc1f73652010-12-13 18:01:12 +0800449struct ideapad_rfk_data {
450 char *name;
451 int cfgbit;
452 int opcode;
453 int type;
454};
455
456const struct ideapad_rfk_data ideapad_rfk_data[] = {
Ike Panhc2be1dc22011-09-06 02:31:53 +0800457 { "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 Panhcc1f73652010-12-13 18:01:12 +0800460};
461
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100462static int ideapad_rfk_set(void *data, bool blocked)
463{
Zhang Rui331e0ea2013-09-25 20:39:49 +0800464 struct ideapad_rfk_priv *priv = data;
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100465
Zhang Rui331e0ea2013-09-25 20:39:49 +0800466 return write_ec_cmd(priv->priv->adev->handle, priv->dev, !blocked);
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100467}
468
469static struct rfkill_ops ideapad_rfk_ops = {
470 .set_block = ideapad_rfk_set,
471};
472
Ike Panhc923de842011-09-06 02:32:01 +0800473static void ideapad_sync_rfk_state(struct ideapad_private *priv)
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100474{
Ike Panhc2b7266b2010-10-01 15:39:49 +0800475 unsigned long hw_blocked;
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100476 int i;
477
Zhang Rui331e0ea2013-09-25 20:39:49 +0800478 if (read_ec_data(priv->adev->handle, VPCCMD_R_RF, &hw_blocked))
Ike Panhc2b7266b2010-10-01 15:39:49 +0800479 return;
480 hw_blocked = !hw_blocked;
481
Ike Panhcc1f73652010-12-13 18:01:12 +0800482 for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
David Woodhousece326322010-08-11 17:59:35 +0100483 if (priv->rfk[i])
484 rfkill_set_hw_state(priv->rfk[i], hw_blocked);
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100485}
486
Zhang Rui75a11f12013-09-25 20:39:48 +0800487static int ideapad_register_rfkill(struct ideapad_private *priv, int dev)
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100488{
489 int ret;
Ike Panhc2b7266b2010-10-01 15:39:49 +0800490 unsigned long sw_blocked;
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100491
Ike Panhcbfa97b72010-10-01 15:40:22 +0800492 if (no_bt_rfkill &&
493 (ideapad_rfk_data[dev].type == RFKILL_TYPE_BLUETOOTH)) {
494 /* Force to enable bluetooth when no_bt_rfkill=1 */
Zhang Rui331e0ea2013-09-25 20:39:49 +0800495 write_ec_cmd(priv->adev->handle,
Ike Panhcbfa97b72010-10-01 15:40:22 +0800496 ideapad_rfk_data[dev].opcode, 1);
497 return 0;
498 }
Zhang Rui331e0ea2013-09-25 20:39:49 +0800499 priv->rfk_priv[dev].dev = dev;
500 priv->rfk_priv[dev].priv = priv;
Ike Panhcbfa97b72010-10-01 15:40:22 +0800501
Zhang Rui75a11f12013-09-25 20:39:48 +0800502 priv->rfk[dev] = rfkill_alloc(ideapad_rfk_data[dev].name,
Zhang Ruib5c37b72013-09-25 20:39:50 +0800503 &priv->platform_device->dev,
Zhang Rui75a11f12013-09-25 20:39:48 +0800504 ideapad_rfk_data[dev].type,
505 &ideapad_rfk_ops,
Zhang Rui331e0ea2013-09-25 20:39:49 +0800506 &priv->rfk_priv[dev]);
David Woodhousece326322010-08-11 17:59:35 +0100507 if (!priv->rfk[dev])
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100508 return -ENOMEM;
509
Zhang Rui331e0ea2013-09-25 20:39:49 +0800510 if (read_ec_data(priv->adev->handle, ideapad_rfk_data[dev].opcode-1,
Ike Panhc2b7266b2010-10-01 15:39:49 +0800511 &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 Woodhousece326322010-08-11 17:59:35 +0100518 ret = rfkill_register(priv->rfk[dev]);
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100519 if (ret) {
David Woodhousece326322010-08-11 17:59:35 +0100520 rfkill_destroy(priv->rfk[dev]);
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100521 return ret;
522 }
523 return 0;
524}
525
Zhang Rui75a11f12013-09-25 20:39:48 +0800526static void ideapad_unregister_rfkill(struct ideapad_private *priv, int dev)
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100527{
David Woodhousece326322010-08-11 17:59:35 +0100528 if (!priv->rfk[dev])
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100529 return;
530
David Woodhousece326322010-08-11 17:59:35 +0100531 rfkill_unregister(priv->rfk[dev]);
532 rfkill_destroy(priv->rfk[dev]);
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100533}
534
Ike Panhc98ee6912010-12-13 18:00:15 +0800535/*
536 * Platform device
537 */
Zhang Ruib5c37b72013-09-25 20:39:50 +0800538static int ideapad_sysfs_init(struct ideapad_private *priv)
Ike Panhc98ee6912010-12-13 18:00:15 +0800539{
Zhang Ruib5c37b72013-09-25 20:39:50 +0800540 return sysfs_create_group(&priv->platform_device->dev.kobj,
Ike Panhcc9f718d2010-12-13 18:00:27 +0800541 &ideapad_attribute_group);
Ike Panhc98ee6912010-12-13 18:00:15 +0800542}
543
Zhang Ruib5c37b72013-09-25 20:39:50 +0800544static void ideapad_sysfs_exit(struct ideapad_private *priv)
Ike Panhc98ee6912010-12-13 18:00:15 +0800545{
Ike Panhc8693ae82010-12-13 18:01:01 +0800546 sysfs_remove_group(&priv->platform_device->dev.kobj,
Ike Panhcc9f718d2010-12-13 18:00:27 +0800547 &ideapad_attribute_group);
Ike Panhc98ee6912010-12-13 18:00:15 +0800548}
Ike Panhc98ee6912010-12-13 18:00:15 +0800549
Ike Panhcf63409a2010-12-13 18:00:38 +0800550/*
551 * input device
552 */
553static const struct key_entry ideapad_keymap[] = {
Ike Panhcf43d9ec2011-09-06 02:32:10 +0800554 { KE_KEY, 6, { KEY_SWITCHVIDEOMODE } },
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +0800555 { KE_KEY, 7, { KEY_CAMERA } },
556 { KE_KEY, 11, { KEY_F16 } },
Ike Panhcf43d9ec2011-09-06 02:32:10 +0800557 { KE_KEY, 13, { KEY_WLAN } },
558 { KE_KEY, 16, { KEY_PROG1 } },
559 { KE_KEY, 17, { KEY_PROG2 } },
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +0800560 { KE_KEY, 64, { KEY_PROG3 } },
561 { KE_KEY, 65, { KEY_PROG4 } },
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +0800562 { KE_KEY, 66, { KEY_TOUCHPAD_OFF } },
563 { KE_KEY, 67, { KEY_TOUCHPAD_ON } },
Ike Panhcf63409a2010-12-13 18:00:38 +0800564 { KE_END, 0 },
565};
566
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -0800567static int ideapad_input_init(struct ideapad_private *priv)
Ike Panhcf63409a2010-12-13 18:00:38 +0800568{
569 struct input_dev *inputdev;
570 int error;
571
572 inputdev = input_allocate_device();
Joe Perchesb222cca2013-10-23 12:14:52 -0700573 if (!inputdev)
Ike Panhcf63409a2010-12-13 18:00:38 +0800574 return -ENOMEM;
Ike Panhcf63409a2010-12-13 18:00:38 +0800575
576 inputdev->name = "Ideapad extra buttons";
577 inputdev->phys = "ideapad/input0";
578 inputdev->id.bustype = BUS_HOST;
Ike Panhc8693ae82010-12-13 18:01:01 +0800579 inputdev->dev.parent = &priv->platform_device->dev;
Ike Panhcf63409a2010-12-13 18:00:38 +0800580
581 error = sparse_keymap_setup(inputdev, ideapad_keymap, NULL);
582 if (error) {
583 pr_err("Unable to setup input device keymap\n");
584 goto err_free_dev;
585 }
586
587 error = input_register_device(inputdev);
588 if (error) {
589 pr_err("Unable to register input device\n");
590 goto err_free_keymap;
591 }
592
Ike Panhc8693ae82010-12-13 18:01:01 +0800593 priv->inputdev = inputdev;
Ike Panhcf63409a2010-12-13 18:00:38 +0800594 return 0;
595
596err_free_keymap:
597 sparse_keymap_free(inputdev);
598err_free_dev:
599 input_free_device(inputdev);
600 return error;
601}
602
Axel Lin7451a552011-07-27 15:27:34 +0800603static void ideapad_input_exit(struct ideapad_private *priv)
Ike Panhcf63409a2010-12-13 18:00:38 +0800604{
Ike Panhc8693ae82010-12-13 18:01:01 +0800605 sparse_keymap_free(priv->inputdev);
606 input_unregister_device(priv->inputdev);
607 priv->inputdev = NULL;
Ike Panhcf63409a2010-12-13 18:00:38 +0800608}
609
Ike Panhc8693ae82010-12-13 18:01:01 +0800610static void ideapad_input_report(struct ideapad_private *priv,
611 unsigned long scancode)
Ike Panhcf63409a2010-12-13 18:00:38 +0800612{
Ike Panhc8693ae82010-12-13 18:01:01 +0800613 sparse_keymap_report_event(priv->inputdev, scancode, 1, true);
Ike Panhcf63409a2010-12-13 18:00:38 +0800614}
Ike Panhcf63409a2010-12-13 18:00:38 +0800615
Ike Panhcf43d9ec2011-09-06 02:32:10 +0800616static void ideapad_input_novokey(struct ideapad_private *priv)
617{
618 unsigned long long_pressed;
619
Zhang Rui331e0ea2013-09-25 20:39:49 +0800620 if (read_ec_data(priv->adev->handle, VPCCMD_R_NOVO, &long_pressed))
Ike Panhcf43d9ec2011-09-06 02:32:10 +0800621 return;
622 if (long_pressed)
623 ideapad_input_report(priv, 17);
624 else
625 ideapad_input_report(priv, 16);
626}
627
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +0800628static void ideapad_check_special_buttons(struct ideapad_private *priv)
629{
630 unsigned long bit, value;
631
Zhang Rui331e0ea2013-09-25 20:39:49 +0800632 read_ec_data(priv->adev->handle, VPCCMD_R_SPECIAL_BUTTONS, &value);
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +0800633
634 for (bit = 0; bit < 16; bit++) {
635 if (test_bit(bit, &value)) {
636 switch (bit) {
Maxim Mikityanskiya1ec56e2013-03-20 12:34:17 +0200637 case 0: /* Z580 */
638 case 6: /* Z570 */
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +0800639 /* Thermal Management button */
640 ideapad_input_report(priv, 65);
641 break;
642 case 1:
643 /* OneKey Theater button */
644 ideapad_input_report(priv, 64);
645 break;
Maxim Mikityanskiya1ec56e2013-03-20 12:34:17 +0200646 default:
647 pr_info("Unknown special button: %lu\n", bit);
648 break;
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +0800649 }
650 }
651 }
652}
653
Ike Panhca4b5a272010-12-13 18:00:48 +0800654/*
Ike Panhca4ecbb82011-06-30 19:50:52 +0800655 * backlight
656 */
657static int ideapad_backlight_get_brightness(struct backlight_device *blightdev)
658{
Zhang Rui331e0ea2013-09-25 20:39:49 +0800659 struct ideapad_private *priv = bl_get_data(blightdev);
Ike Panhca4ecbb82011-06-30 19:50:52 +0800660 unsigned long now;
661
Zhang Rui331e0ea2013-09-25 20:39:49 +0800662 if (!priv)
663 return -EINVAL;
664
665 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now))
Ike Panhca4ecbb82011-06-30 19:50:52 +0800666 return -EIO;
667 return now;
668}
669
670static int ideapad_backlight_update_status(struct backlight_device *blightdev)
671{
Zhang Rui331e0ea2013-09-25 20:39:49 +0800672 struct ideapad_private *priv = bl_get_data(blightdev);
673
674 if (!priv)
675 return -EINVAL;
676
677 if (write_ec_cmd(priv->adev->handle, VPCCMD_W_BL,
Ike Panhc2be1dc22011-09-06 02:31:53 +0800678 blightdev->props.brightness))
Ike Panhca4ecbb82011-06-30 19:50:52 +0800679 return -EIO;
Zhang Rui331e0ea2013-09-25 20:39:49 +0800680 if (write_ec_cmd(priv->adev->handle, VPCCMD_W_BL_POWER,
Ike Panhca4ecbb82011-06-30 19:50:52 +0800681 blightdev->props.power == FB_BLANK_POWERDOWN ? 0 : 1))
682 return -EIO;
683
684 return 0;
685}
686
687static const struct backlight_ops ideapad_backlight_ops = {
688 .get_brightness = ideapad_backlight_get_brightness,
689 .update_status = ideapad_backlight_update_status,
690};
691
692static int ideapad_backlight_init(struct ideapad_private *priv)
693{
694 struct backlight_device *blightdev;
695 struct backlight_properties props;
696 unsigned long max, now, power;
697
Zhang Rui331e0ea2013-09-25 20:39:49 +0800698 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &max))
Ike Panhca4ecbb82011-06-30 19:50:52 +0800699 return -EIO;
Zhang Rui331e0ea2013-09-25 20:39:49 +0800700 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now))
Ike Panhca4ecbb82011-06-30 19:50:52 +0800701 return -EIO;
Zhang Rui331e0ea2013-09-25 20:39:49 +0800702 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power))
Ike Panhca4ecbb82011-06-30 19:50:52 +0800703 return -EIO;
704
705 memset(&props, 0, sizeof(struct backlight_properties));
706 props.max_brightness = max;
707 props.type = BACKLIGHT_PLATFORM;
708 blightdev = backlight_device_register("ideapad",
709 &priv->platform_device->dev,
710 priv,
711 &ideapad_backlight_ops,
712 &props);
713 if (IS_ERR(blightdev)) {
714 pr_err("Could not register backlight device\n");
715 return PTR_ERR(blightdev);
716 }
717
718 priv->blightdev = blightdev;
719 blightdev->props.brightness = now;
720 blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
721 backlight_update_status(blightdev);
722
723 return 0;
724}
725
726static void ideapad_backlight_exit(struct ideapad_private *priv)
727{
728 if (priv->blightdev)
729 backlight_device_unregister(priv->blightdev);
730 priv->blightdev = NULL;
731}
732
733static void ideapad_backlight_notify_power(struct ideapad_private *priv)
734{
735 unsigned long power;
736 struct backlight_device *blightdev = priv->blightdev;
737
Rene Bollfordd4afc772011-10-23 09:56:42 +0200738 if (!blightdev)
739 return;
Zhang Rui331e0ea2013-09-25 20:39:49 +0800740 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power))
Ike Panhca4ecbb82011-06-30 19:50:52 +0800741 return;
742 blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
743}
744
745static void ideapad_backlight_notify_brightness(struct ideapad_private *priv)
746{
747 unsigned long now;
748
749 /* if we control brightness via acpi video driver */
750 if (priv->blightdev == NULL) {
Zhang Rui331e0ea2013-09-25 20:39:49 +0800751 read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now);
Ike Panhca4ecbb82011-06-30 19:50:52 +0800752 return;
753 }
754
755 backlight_force_update(priv->blightdev, BACKLIGHT_UPDATE_HOTKEY);
756}
757
758/*
Ike Panhca4b5a272010-12-13 18:00:48 +0800759 * module init/exit
760 */
Zhang Rui75a11f12013-09-25 20:39:48 +0800761static void ideapad_sync_touchpad_state(struct ideapad_private *priv)
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +0800762{
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +0800763 unsigned long value;
764
765 /* Without reading from EC touchpad LED doesn't switch state */
Zhang Rui75a11f12013-09-25 20:39:48 +0800766 if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value)) {
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +0800767 /* Some IdeaPads don't really turn off touchpad - they only
768 * switch the LED state. We (de)activate KBC AUX port to turn
769 * touchpad off and on. We send KEY_TOUCHPAD_OFF and
770 * KEY_TOUCHPAD_ON to not to get out of sync with LED */
771 unsigned char param;
772 i8042_command(&param, value ? I8042_CMD_AUX_ENABLE :
773 I8042_CMD_AUX_DISABLE);
774 ideapad_input_report(priv, value ? 67 : 66);
775 }
776}
777
Zhang Ruib5c37b72013-09-25 20:39:50 +0800778static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data)
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100779{
Zhang Ruib5c37b72013-09-25 20:39:50 +0800780 struct ideapad_private *priv = data;
Ike Panhc8e7d3542010-10-01 15:39:05 +0800781 unsigned long vpc1, vpc2, vpc_bit;
782
Ike Panhc2be1dc22011-09-06 02:31:53 +0800783 if (read_ec_data(handle, VPCCMD_R_VPC1, &vpc1))
Ike Panhc8e7d3542010-10-01 15:39:05 +0800784 return;
Ike Panhc2be1dc22011-09-06 02:31:53 +0800785 if (read_ec_data(handle, VPCCMD_R_VPC2, &vpc2))
Ike Panhc8e7d3542010-10-01 15:39:05 +0800786 return;
787
788 vpc1 = (vpc2 << 8) | vpc1;
789 for (vpc_bit = 0; vpc_bit < 16; vpc_bit++) {
790 if (test_bit(vpc_bit, &vpc1)) {
Ike Panhca4ecbb82011-06-30 19:50:52 +0800791 switch (vpc_bit) {
792 case 9:
Ike Panhc923de842011-09-06 02:32:01 +0800793 ideapad_sync_rfk_state(priv);
Ike Panhca4ecbb82011-06-30 19:50:52 +0800794 break;
Ike Panhc20a769c2012-05-03 17:38:46 +0800795 case 13:
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +0800796 case 11:
797 case 7:
Ike Panhc20a769c2012-05-03 17:38:46 +0800798 case 6:
799 ideapad_input_report(priv, vpc_bit);
800 break;
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +0800801 case 5:
Zhang Rui75a11f12013-09-25 20:39:48 +0800802 ideapad_sync_touchpad_state(priv);
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +0800803 break;
Ike Panhca4ecbb82011-06-30 19:50:52 +0800804 case 4:
805 ideapad_backlight_notify_brightness(priv);
806 break;
Ike Panhcf43d9ec2011-09-06 02:32:10 +0800807 case 3:
808 ideapad_input_novokey(priv);
809 break;
Ike Panhca4ecbb82011-06-30 19:50:52 +0800810 case 2:
811 ideapad_backlight_notify_power(priv);
812 break;
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +0800813 case 0:
814 ideapad_check_special_buttons(priv);
815 break;
Ike Panhca4ecbb82011-06-30 19:50:52 +0800816 default:
Ike Panhc20a769c2012-05-03 17:38:46 +0800817 pr_info("Unknown event: %lu\n", vpc_bit);
Ike Panhca4ecbb82011-06-30 19:50:52 +0800818 }
Ike Panhc8e7d3542010-10-01 15:39:05 +0800819 }
820 }
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100821}
822
Zhang Ruib5c37b72013-09-25 20:39:50 +0800823static int ideapad_acpi_add(struct platform_device *pdev)
824{
825 int ret, i;
826 int cfg;
827 struct ideapad_private *priv;
828 struct acpi_device *adev;
829
830 ret = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev);
831 if (ret)
832 return -ENODEV;
833
834 if (read_method_int(adev->handle, "_CFG", &cfg))
835 return -ENODEV;
836
837 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
838 if (!priv)
839 return -ENOMEM;
840
841 dev_set_drvdata(&pdev->dev, priv);
842 priv->cfg = cfg;
843 priv->adev = adev;
844 priv->platform_device = pdev;
845
846 ret = ideapad_sysfs_init(priv);
847 if (ret)
848 goto sysfs_failed;
849
850 ret = ideapad_debugfs_init(priv);
851 if (ret)
852 goto debugfs_failed;
853
854 ret = ideapad_input_init(priv);
855 if (ret)
856 goto input_failed;
857
858 for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) {
859 if (test_bit(ideapad_rfk_data[i].cfgbit, &priv->cfg))
860 ideapad_register_rfkill(priv, i);
861 else
862 priv->rfk[i] = NULL;
863 }
864 ideapad_sync_rfk_state(priv);
865 ideapad_sync_touchpad_state(priv);
866
867 if (!acpi_video_backlight_support()) {
868 ret = ideapad_backlight_init(priv);
869 if (ret && ret != -ENODEV)
870 goto backlight_failed;
871 }
872 ret = acpi_install_notify_handler(adev->handle,
873 ACPI_DEVICE_NOTIFY, ideapad_acpi_notify, priv);
874 if (ret)
875 goto notification_failed;
876
877 return 0;
878notification_failed:
879 ideapad_backlight_exit(priv);
880backlight_failed:
881 for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
882 ideapad_unregister_rfkill(priv, i);
883 ideapad_input_exit(priv);
884input_failed:
885 ideapad_debugfs_exit(priv);
886debugfs_failed:
887 ideapad_sysfs_exit(priv);
888sysfs_failed:
889 kfree(priv);
890 return ret;
891}
892
893static int ideapad_acpi_remove(struct platform_device *pdev)
894{
895 struct ideapad_private *priv = dev_get_drvdata(&pdev->dev);
896 int i;
897
898 acpi_remove_notify_handler(priv->adev->handle,
899 ACPI_DEVICE_NOTIFY, ideapad_acpi_notify);
900 ideapad_backlight_exit(priv);
901 for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
902 ideapad_unregister_rfkill(priv, i);
903 ideapad_input_exit(priv);
904 ideapad_debugfs_exit(priv);
905 ideapad_sysfs_exit(priv);
906 dev_set_drvdata(&pdev->dev, NULL);
907 kfree(priv);
908
909 return 0;
910}
911
Zhang Rui11fa8da2013-09-25 20:39:46 +0800912#ifdef CONFIG_PM_SLEEP
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +0800913static int ideapad_acpi_resume(struct device *device)
914{
Zhang Rui75a11f12013-09-25 20:39:48 +0800915 struct ideapad_private *priv;
916
917 if (!device)
918 return -EINVAL;
919 priv = dev_get_drvdata(device);
920
921 ideapad_sync_rfk_state(priv);
922 ideapad_sync_touchpad_state(priv);
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +0800923 return 0;
924}
Zhang Ruib5c37b72013-09-25 20:39:50 +0800925#endif
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +0800926static SIMPLE_DEV_PM_OPS(ideapad_pm, NULL, ideapad_acpi_resume);
927
Zhang Ruib5c37b72013-09-25 20:39:50 +0800928static const struct acpi_device_id ideapad_device_ids[] = {
929 { "VPC2004", 0},
930 { "", 0},
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100931};
Zhang Ruib5c37b72013-09-25 20:39:50 +0800932MODULE_DEVICE_TABLE(acpi, ideapad_device_ids);
933
934static struct platform_driver ideapad_acpi_driver = {
935 .probe = ideapad_acpi_add,
936 .remove = ideapad_acpi_remove,
937 .driver = {
938 .name = "ideapad_acpi",
939 .owner = THIS_MODULE,
940 .pm = &ideapad_pm,
941 .acpi_match_table = ACPI_PTR(ideapad_device_ids),
942 },
943};
944
945module_platform_driver(ideapad_acpi_driver);
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100946
947MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
948MODULE_DESCRIPTION("IdeaPad ACPI Extras");
949MODULE_LICENSE("GPL");