blob: 45b7cb01f4101ee8526ac5f4f7f86a626959f220 [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>
Lv Zheng8b484632013-12-03 08:49:16 +080029#include <linux/acpi.h>
David Woodhouse58ac7aa2010-08-10 23:44:05 +010030#include <linux/rfkill.h>
Ike Panhc98ee6912010-12-13 18:00:15 +080031#include <linux/platform_device.h>
Ike Panhcf63409a2010-12-13 18:00:38 +080032#include <linux/input.h>
33#include <linux/input/sparse-keymap.h>
Ike Panhca4ecbb82011-06-30 19:50:52 +080034#include <linux/backlight.h>
35#include <linux/fb.h>
Ike Panhc773e3202011-09-06 02:32:52 +080036#include <linux/debugfs.h>
37#include <linux/seq_file.h>
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +080038#include <linux/i8042.h>
Hans de Goede85093f72014-05-13 16:00:28 +020039#include <linux/dmi.h>
Himangi Saraogib3facd72014-06-09 17:46:50 -040040#include <linux/device.h>
Hans de Goede26bff5f2015-06-16 16:28:04 +020041#include <acpi/video.h>
David Woodhouse58ac7aa2010-08-10 23:44:05 +010042
Ike Panhcc1f73652010-12-13 18:01:12 +080043#define IDEAPAD_RFKILL_DEV_NUM (3)
David Woodhouse58ac7aa2010-08-10 23:44:05 +010044
Hao Wei Teeade50292017-08-15 00:13:51 +080045#define BM_CONSERVATION_BIT (5)
Oleg Keri40760712018-05-13 19:05:07 +030046#define HA_FNLOCK_BIT (10)
Hao Wei Teeade50292017-08-15 00:13:51 +080047
Ike Panhc3371f482011-06-30 19:50:40 +080048#define CFG_BT_BIT (16)
49#define CFG_3G_BIT (17)
50#define CFG_WIFI_BIT (18)
Ike Panhca84511f2011-06-30 19:50:47 +080051#define CFG_CAMERA_BIT (19)
Ike Panhc3371f482011-06-30 19:50:40 +080052
Arnd Bergmann74caab92015-11-06 22:28:49 +010053#if IS_ENABLED(CONFIG_ACPI_WMI)
Arnd Bergmann2d98e0b2016-05-09 23:49:21 +020054static const char *const ideapad_wmi_fnesc_events[] = {
55 "26CAB2E5-5CF1-46AE-AAC3-4A12B6BA50E6", /* Yoga 3 */
56 "56322276-8493-4CE8-A783-98C991274F5E", /* Yoga 700 */
57};
Arnd Bergmann74caab92015-11-06 22:28:49 +010058#endif
59
Ike Panhc2be1dc22011-09-06 02:31:53 +080060enum {
Hao Wei Teeade50292017-08-15 00:13:51 +080061 BMCMD_CONSERVATION_ON = 3,
62 BMCMD_CONSERVATION_OFF = 5,
Oleg Keri40760712018-05-13 19:05:07 +030063 HACMD_FNLOCK_ON = 0xe,
64 HACMD_FNLOCK_OFF = 0xf,
Hao Wei Teeade50292017-08-15 00:13:51 +080065};
66
67enum {
Ike Panhc2be1dc22011-09-06 02:31:53 +080068 VPCCMD_R_VPC1 = 0x10,
69 VPCCMD_R_BL_MAX,
70 VPCCMD_R_BL,
71 VPCCMD_W_BL,
72 VPCCMD_R_WIFI,
73 VPCCMD_W_WIFI,
74 VPCCMD_R_BT,
75 VPCCMD_W_BT,
76 VPCCMD_R_BL_POWER,
77 VPCCMD_R_NOVO,
78 VPCCMD_R_VPC2,
79 VPCCMD_R_TOUCHPAD,
80 VPCCMD_W_TOUCHPAD,
81 VPCCMD_R_CAMERA,
82 VPCCMD_W_CAMERA,
83 VPCCMD_R_3G,
84 VPCCMD_W_3G,
85 VPCCMD_R_ODD, /* 0x21 */
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +080086 VPCCMD_W_FAN,
87 VPCCMD_R_RF,
Ike Panhc2be1dc22011-09-06 02:31:53 +080088 VPCCMD_W_RF,
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +080089 VPCCMD_R_FAN = 0x2B,
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +080090 VPCCMD_R_SPECIAL_BUTTONS = 0x31,
Ike Panhc2be1dc22011-09-06 02:31:53 +080091 VPCCMD_W_BL_POWER = 0x33,
92};
93
Zhang Rui331e0ea2013-09-25 20:39:49 +080094struct ideapad_rfk_priv {
95 int dev;
96 struct ideapad_private *priv;
97};
98
David Woodhousece326322010-08-11 17:59:35 +010099struct ideapad_private {
Zhang Rui469f6432013-09-25 20:39:47 +0800100 struct acpi_device *adev;
Ike Panhcc1f73652010-12-13 18:01:12 +0800101 struct rfkill *rfk[IDEAPAD_RFKILL_DEV_NUM];
Zhang Rui331e0ea2013-09-25 20:39:49 +0800102 struct ideapad_rfk_priv rfk_priv[IDEAPAD_RFKILL_DEV_NUM];
Ike Panhc98ee6912010-12-13 18:00:15 +0800103 struct platform_device *platform_device;
Ike Panhcf63409a2010-12-13 18:00:38 +0800104 struct input_dev *inputdev;
Ike Panhca4ecbb82011-06-30 19:50:52 +0800105 struct backlight_device *blightdev;
Ike Panhc773e3202011-09-06 02:32:52 +0800106 struct dentry *debug;
Ike Panhc3371f482011-06-30 19:50:40 +0800107 unsigned long cfg;
Hans de Goedece363c22014-06-23 16:45:51 +0200108 bool has_hw_rfkill_switch;
Arnd Bergmann2d98e0b2016-05-09 23:49:21 +0200109 const char *fnesc_guid;
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100110};
111
Ike Panhcbfa97b72010-10-01 15:40:22 +0800112static bool no_bt_rfkill;
113module_param(no_bt_rfkill, bool, 0444);
114MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth.");
115
Ike Panhc6a09f212010-10-01 15:38:46 +0800116/*
117 * ACPI Helpers
118 */
Aaron Maed5b9ba2018-02-11 17:18:49 +0800119#define IDEAPAD_EC_TIMEOUT (200) /* in ms */
Ike Panhc6a09f212010-10-01 15:38:46 +0800120
121static int read_method_int(acpi_handle handle, const char *method, int *val)
122{
123 acpi_status status;
124 unsigned long long result;
125
126 status = acpi_evaluate_integer(handle, (char *)method, NULL, &result);
127 if (ACPI_FAILURE(status)) {
128 *val = -1;
129 return -1;
Ike Panhc6a09f212010-10-01 15:38:46 +0800130 }
Jiaxun Yangba3a3382017-12-02 21:45:31 +0800131 *val = result;
132 return 0;
133
Ike Panhc6a09f212010-10-01 15:38:46 +0800134}
135
Hao Wei Teeade50292017-08-15 00:13:51 +0800136static int method_gbmd(acpi_handle handle, unsigned long *ret)
137{
138 int result, val;
139
140 result = read_method_int(handle, "GBMD", &val);
141 *ret = val;
142 return result;
143}
144
Oleg Keri40760712018-05-13 19:05:07 +0300145static int method_int1(acpi_handle handle, char *method, int cmd)
Hao Wei Teeade50292017-08-15 00:13:51 +0800146{
147 acpi_status status;
148
Oleg Keri40760712018-05-13 19:05:07 +0300149 status = acpi_execute_simple_method(handle, method, cmd);
Hao Wei Teeade50292017-08-15 00:13:51 +0800150 return ACPI_FAILURE(status) ? -1 : 0;
151}
152
Ike Panhc6a09f212010-10-01 15:38:46 +0800153static int method_vpcr(acpi_handle handle, int cmd, int *ret)
154{
155 acpi_status status;
156 unsigned long long result;
157 struct acpi_object_list params;
158 union acpi_object in_obj;
159
160 params.count = 1;
161 params.pointer = &in_obj;
162 in_obj.type = ACPI_TYPE_INTEGER;
163 in_obj.integer.value = cmd;
164
165 status = acpi_evaluate_integer(handle, "VPCR", &params, &result);
166
167 if (ACPI_FAILURE(status)) {
168 *ret = -1;
169 return -1;
Ike Panhc6a09f212010-10-01 15:38:46 +0800170 }
Jiaxun Yangba3a3382017-12-02 21:45:31 +0800171 *ret = result;
172 return 0;
173
Ike Panhc6a09f212010-10-01 15:38:46 +0800174}
175
176static int method_vpcw(acpi_handle handle, int cmd, int data)
177{
178 struct acpi_object_list params;
179 union acpi_object in_obj[2];
180 acpi_status status;
181
182 params.count = 2;
183 params.pointer = in_obj;
184 in_obj[0].type = ACPI_TYPE_INTEGER;
185 in_obj[0].integer.value = cmd;
186 in_obj[1].type = ACPI_TYPE_INTEGER;
187 in_obj[1].integer.value = data;
188
189 status = acpi_evaluate_object(handle, "VPCW", &params, NULL);
190 if (status != AE_OK)
191 return -1;
192 return 0;
193}
194
195static int read_ec_data(acpi_handle handle, int cmd, unsigned long *data)
196{
197 int val;
198 unsigned long int end_jiffies;
199
200 if (method_vpcw(handle, 1, cmd))
201 return -1;
202
203 for (end_jiffies = jiffies+(HZ)*IDEAPAD_EC_TIMEOUT/1000+1;
204 time_before(jiffies, end_jiffies);) {
205 schedule();
206 if (method_vpcr(handle, 1, &val))
207 return -1;
208 if (val == 0) {
209 if (method_vpcr(handle, 0, &val))
210 return -1;
211 *data = val;
212 return 0;
213 }
214 }
215 pr_err("timeout in read_ec_cmd\n");
216 return -1;
217}
218
219static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data)
220{
221 int val;
222 unsigned long int end_jiffies;
223
224 if (method_vpcw(handle, 0, data))
225 return -1;
226 if (method_vpcw(handle, 1, cmd))
227 return -1;
228
229 for (end_jiffies = jiffies+(HZ)*IDEAPAD_EC_TIMEOUT/1000+1;
230 time_before(jiffies, end_jiffies);) {
231 schedule();
232 if (method_vpcr(handle, 1, &val))
233 return -1;
234 if (val == 0)
235 return 0;
236 }
Jiaxun Yangf1395ed2017-12-02 21:45:32 +0800237 pr_err("timeout in %s\n", __func__);
Ike Panhc6a09f212010-10-01 15:38:46 +0800238 return -1;
239}
Ike Panhc6a09f212010-10-01 15:38:46 +0800240
Ike Panhca4b5a272010-12-13 18:00:48 +0800241/*
Ike Panhc773e3202011-09-06 02:32:52 +0800242 * debugfs
243 */
Ike Panhc773e3202011-09-06 02:32:52 +0800244static int debugfs_status_show(struct seq_file *s, void *data)
245{
Zhang Rui331e0ea2013-09-25 20:39:49 +0800246 struct ideapad_private *priv = s->private;
Ike Panhc773e3202011-09-06 02:32:52 +0800247 unsigned long value;
248
Zhang Rui331e0ea2013-09-25 20:39:49 +0800249 if (!priv)
250 return -EINVAL;
251
252 if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &value))
Ike Panhc773e3202011-09-06 02:32:52 +0800253 seq_printf(s, "Backlight max:\t%lu\n", value);
Zhang Rui331e0ea2013-09-25 20:39:49 +0800254 if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL, &value))
Ike Panhc773e3202011-09-06 02:32:52 +0800255 seq_printf(s, "Backlight now:\t%lu\n", value);
Zhang Rui331e0ea2013-09-25 20:39:49 +0800256 if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &value))
Ike Panhc773e3202011-09-06 02:32:52 +0800257 seq_printf(s, "BL power value:\t%s\n", value ? "On" : "Off");
258 seq_printf(s, "=====================\n");
259
Zhang Rui331e0ea2013-09-25 20:39:49 +0800260 if (!read_ec_data(priv->adev->handle, VPCCMD_R_RF, &value))
Ike Panhc773e3202011-09-06 02:32:52 +0800261 seq_printf(s, "Radio status:\t%s(%lu)\n",
262 value ? "On" : "Off", value);
Zhang Rui331e0ea2013-09-25 20:39:49 +0800263 if (!read_ec_data(priv->adev->handle, VPCCMD_R_WIFI, &value))
Ike Panhc773e3202011-09-06 02:32:52 +0800264 seq_printf(s, "Wifi status:\t%s(%lu)\n",
265 value ? "On" : "Off", value);
Zhang Rui331e0ea2013-09-25 20:39:49 +0800266 if (!read_ec_data(priv->adev->handle, VPCCMD_R_BT, &value))
Ike Panhc773e3202011-09-06 02:32:52 +0800267 seq_printf(s, "BT status:\t%s(%lu)\n",
268 value ? "On" : "Off", value);
Zhang Rui331e0ea2013-09-25 20:39:49 +0800269 if (!read_ec_data(priv->adev->handle, VPCCMD_R_3G, &value))
Ike Panhc773e3202011-09-06 02:32:52 +0800270 seq_printf(s, "3G status:\t%s(%lu)\n",
271 value ? "On" : "Off", value);
272 seq_printf(s, "=====================\n");
273
Zhang Rui331e0ea2013-09-25 20:39:49 +0800274 if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value))
Ike Panhc773e3202011-09-06 02:32:52 +0800275 seq_printf(s, "Touchpad status:%s(%lu)\n",
276 value ? "On" : "Off", value);
Zhang Rui331e0ea2013-09-25 20:39:49 +0800277 if (!read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &value))
Ike Panhc773e3202011-09-06 02:32:52 +0800278 seq_printf(s, "Camera status:\t%s(%lu)\n",
279 value ? "On" : "Off", value);
Hao Wei Teeade50292017-08-15 00:13:51 +0800280 seq_puts(s, "=====================\n");
281
282 if (!method_gbmd(priv->adev->handle, &value)) {
283 seq_printf(s, "Conservation mode:\t%s(%lu)\n",
284 test_bit(BM_CONSERVATION_BIT, &value) ? "On" : "Off",
285 value);
286 }
Ike Panhc773e3202011-09-06 02:32:52 +0800287
288 return 0;
289}
Andy Shevchenko334c4ef2018-01-22 18:05:45 +0200290DEFINE_SHOW_ATTRIBUTE(debugfs_status);
Ike Panhc773e3202011-09-06 02:32:52 +0800291
292static int debugfs_cfg_show(struct seq_file *s, void *data)
293{
Zhang Rui331e0ea2013-09-25 20:39:49 +0800294 struct ideapad_private *priv = s->private;
295
296 if (!priv) {
Ike Panhc773e3202011-09-06 02:32:52 +0800297 seq_printf(s, "cfg: N/A\n");
298 } else {
299 seq_printf(s, "cfg: 0x%.8lX\n\nCapability: ",
Zhang Rui331e0ea2013-09-25 20:39:49 +0800300 priv->cfg);
301 if (test_bit(CFG_BT_BIT, &priv->cfg))
Ike Panhc773e3202011-09-06 02:32:52 +0800302 seq_printf(s, "Bluetooth ");
Zhang Rui331e0ea2013-09-25 20:39:49 +0800303 if (test_bit(CFG_3G_BIT, &priv->cfg))
Ike Panhc773e3202011-09-06 02:32:52 +0800304 seq_printf(s, "3G ");
Zhang Rui331e0ea2013-09-25 20:39:49 +0800305 if (test_bit(CFG_WIFI_BIT, &priv->cfg))
Ike Panhc773e3202011-09-06 02:32:52 +0800306 seq_printf(s, "Wireless ");
Zhang Rui331e0ea2013-09-25 20:39:49 +0800307 if (test_bit(CFG_CAMERA_BIT, &priv->cfg))
Ike Panhc773e3202011-09-06 02:32:52 +0800308 seq_printf(s, "Camera ");
309 seq_printf(s, "\nGraphic: ");
Zhang Rui331e0ea2013-09-25 20:39:49 +0800310 switch ((priv->cfg)&0x700) {
Ike Panhc773e3202011-09-06 02:32:52 +0800311 case 0x100:
312 seq_printf(s, "Intel");
313 break;
314 case 0x200:
315 seq_printf(s, "ATI");
316 break;
317 case 0x300:
318 seq_printf(s, "Nvidia");
319 break;
320 case 0x400:
321 seq_printf(s, "Intel and ATI");
322 break;
323 case 0x500:
324 seq_printf(s, "Intel and Nvidia");
325 break;
326 }
327 seq_printf(s, "\n");
328 }
329 return 0;
330}
Andy Shevchenko334c4ef2018-01-22 18:05:45 +0200331DEFINE_SHOW_ATTRIBUTE(debugfs_cfg);
Ike Panhc773e3202011-09-06 02:32:52 +0800332
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -0800333static int ideapad_debugfs_init(struct ideapad_private *priv)
Ike Panhc773e3202011-09-06 02:32:52 +0800334{
335 struct dentry *node;
336
337 priv->debug = debugfs_create_dir("ideapad", NULL);
338 if (priv->debug == NULL) {
339 pr_err("failed to create debugfs directory");
340 goto errout;
341 }
342
Zhang Rui331e0ea2013-09-25 20:39:49 +0800343 node = debugfs_create_file("cfg", S_IRUGO, priv->debug, priv,
Ike Panhc773e3202011-09-06 02:32:52 +0800344 &debugfs_cfg_fops);
345 if (!node) {
346 pr_err("failed to create cfg in debugfs");
347 goto errout;
348 }
349
Zhang Rui331e0ea2013-09-25 20:39:49 +0800350 node = debugfs_create_file("status", S_IRUGO, priv->debug, priv,
Ike Panhc773e3202011-09-06 02:32:52 +0800351 &debugfs_status_fops);
352 if (!node) {
Ike Panhca5c38922012-05-03 17:38:35 +0800353 pr_err("failed to create status in debugfs");
Ike Panhc773e3202011-09-06 02:32:52 +0800354 goto errout;
355 }
356
357 return 0;
358
359errout:
360 return -ENOMEM;
361}
362
363static void ideapad_debugfs_exit(struct ideapad_private *priv)
364{
365 debugfs_remove_recursive(priv->debug);
366 priv->debug = NULL;
367}
368
369/*
Ike Panhc3371f482011-06-30 19:50:40 +0800370 * sysfs
Ike Panhca4b5a272010-12-13 18:00:48 +0800371 */
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100372static ssize_t show_ideapad_cam(struct device *dev,
373 struct device_attribute *attr,
374 char *buf)
375{
Ike Panhc26c81d52010-10-01 15:39:40 +0800376 unsigned long result;
Zhang Rui331e0ea2013-09-25 20:39:49 +0800377 struct ideapad_private *priv = dev_get_drvdata(dev);
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100378
Zhang Rui331e0ea2013-09-25 20:39:49 +0800379 if (read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &result))
Ike Panhc26c81d52010-10-01 15:39:40 +0800380 return sprintf(buf, "-1\n");
381 return sprintf(buf, "%lu\n", result);
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100382}
383
384static ssize_t store_ideapad_cam(struct device *dev,
385 struct device_attribute *attr,
386 const char *buf, size_t count)
387{
388 int ret, state;
Zhang Rui331e0ea2013-09-25 20:39:49 +0800389 struct ideapad_private *priv = dev_get_drvdata(dev);
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100390
391 if (!count)
392 return 0;
393 if (sscanf(buf, "%i", &state) != 1)
394 return -EINVAL;
Zhang Rui331e0ea2013-09-25 20:39:49 +0800395 ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_CAMERA, state);
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100396 if (ret < 0)
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +0800397 return -EIO;
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100398 return count;
399}
400
401static DEVICE_ATTR(camera_power, 0644, show_ideapad_cam, store_ideapad_cam);
402
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +0800403static ssize_t show_ideapad_fan(struct device *dev,
404 struct device_attribute *attr,
405 char *buf)
406{
407 unsigned long result;
Zhang Rui331e0ea2013-09-25 20:39:49 +0800408 struct ideapad_private *priv = dev_get_drvdata(dev);
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +0800409
Zhang Rui331e0ea2013-09-25 20:39:49 +0800410 if (read_ec_data(priv->adev->handle, VPCCMD_R_FAN, &result))
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +0800411 return sprintf(buf, "-1\n");
412 return sprintf(buf, "%lu\n", result);
413}
414
415static ssize_t store_ideapad_fan(struct device *dev,
416 struct device_attribute *attr,
417 const char *buf, size_t count)
418{
419 int ret, state;
Zhang Rui331e0ea2013-09-25 20:39:49 +0800420 struct ideapad_private *priv = dev_get_drvdata(dev);
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +0800421
422 if (!count)
423 return 0;
424 if (sscanf(buf, "%i", &state) != 1)
425 return -EINVAL;
426 if (state < 0 || state > 4 || state == 3)
427 return -EINVAL;
Zhang Rui331e0ea2013-09-25 20:39:49 +0800428 ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_FAN, state);
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +0800429 if (ret < 0)
430 return -EIO;
431 return count;
432}
433
434static DEVICE_ATTR(fan_mode, 0644, show_ideapad_fan, store_ideapad_fan);
435
Ritesh Raj Sarraf36ac0d432017-02-18 00:17:56 +0530436static ssize_t touchpad_show(struct device *dev,
437 struct device_attribute *attr,
438 char *buf)
439{
440 struct ideapad_private *priv = dev_get_drvdata(dev);
441 unsigned long result;
442
443 if (read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &result))
444 return sprintf(buf, "-1\n");
445 return sprintf(buf, "%lu\n", result);
446}
447
Arnd Bergmann46936fd2017-05-22 15:07:03 +0200448/* Switch to RO for now: It might be revisited in the future */
449static ssize_t __maybe_unused touchpad_store(struct device *dev,
450 struct device_attribute *attr,
451 const char *buf, size_t count)
Ritesh Raj Sarraf36ac0d432017-02-18 00:17:56 +0530452{
453 struct ideapad_private *priv = dev_get_drvdata(dev);
454 bool state;
455 int ret;
456
457 ret = kstrtobool(buf, &state);
458 if (ret)
459 return ret;
460
461 ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_TOUCHPAD, state);
462 if (ret < 0)
463 return -EIO;
464 return count;
465}
466
Andy Shevchenko7f363142017-05-07 14:28:30 +0300467static DEVICE_ATTR_RO(touchpad);
Ritesh Raj Sarraf36ac0d432017-02-18 00:17:56 +0530468
Hao Wei Teeade50292017-08-15 00:13:51 +0800469static ssize_t conservation_mode_show(struct device *dev,
470 struct device_attribute *attr,
471 char *buf)
472{
473 struct ideapad_private *priv = dev_get_drvdata(dev);
474 unsigned long result;
475
476 if (method_gbmd(priv->adev->handle, &result))
477 return sprintf(buf, "-1\n");
478 return sprintf(buf, "%u\n", test_bit(BM_CONSERVATION_BIT, &result));
479}
480
481static ssize_t conservation_mode_store(struct device *dev,
482 struct device_attribute *attr,
483 const char *buf, size_t count)
484{
485 struct ideapad_private *priv = dev_get_drvdata(dev);
486 bool state;
487 int ret;
488
489 ret = kstrtobool(buf, &state);
490 if (ret)
491 return ret;
492
Oleg Keri40760712018-05-13 19:05:07 +0300493 ret = method_int1(priv->adev->handle, "SBMC", state ?
Hao Wei Teeade50292017-08-15 00:13:51 +0800494 BMCMD_CONSERVATION_ON :
495 BMCMD_CONSERVATION_OFF);
496 if (ret < 0)
497 return -EIO;
498 return count;
499}
500
501static DEVICE_ATTR_RW(conservation_mode);
502
Oleg Keri40760712018-05-13 19:05:07 +0300503static ssize_t fn_lock_show(struct device *dev,
504 struct device_attribute *attr,
505 char *buf)
506{
507 struct ideapad_private *priv = dev_get_drvdata(dev);
508 unsigned long result;
509 int hals;
510 int fail = read_method_int(priv->adev->handle, "HALS", &hals);
511
512 if (fail)
513 return sprintf(buf, "-1\n");
514
515 result = hals;
516 return sprintf(buf, "%u\n", test_bit(HA_FNLOCK_BIT, &result));
517}
518
519static ssize_t fn_lock_store(struct device *dev,
520 struct device_attribute *attr,
521 const char *buf, size_t count)
522{
523 struct ideapad_private *priv = dev_get_drvdata(dev);
524 bool state;
525 int ret;
526
527 ret = kstrtobool(buf, &state);
528 if (ret)
529 return ret;
530
531 ret = method_int1(priv->adev->handle, "SALS", state ?
532 HACMD_FNLOCK_ON :
533 HACMD_FNLOCK_OFF);
534 if (ret < 0)
535 return -EIO;
536 return count;
537}
538
539static DEVICE_ATTR_RW(fn_lock);
540
541
Ike Panhc3371f482011-06-30 19:50:40 +0800542static struct attribute *ideapad_attributes[] = {
543 &dev_attr_camera_power.attr,
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +0800544 &dev_attr_fan_mode.attr,
Ritesh Raj Sarraf36ac0d432017-02-18 00:17:56 +0530545 &dev_attr_touchpad.attr,
Hao Wei Teeade50292017-08-15 00:13:51 +0800546 &dev_attr_conservation_mode.attr,
Oleg Keri40760712018-05-13 19:05:07 +0300547 &dev_attr_fn_lock.attr,
Ike Panhc3371f482011-06-30 19:50:40 +0800548 NULL
549};
550
Al Viro587a1f12011-07-23 23:11:19 -0400551static umode_t ideapad_is_visible(struct kobject *kobj,
Ike Panhca84511f2011-06-30 19:50:47 +0800552 struct attribute *attr,
553 int idx)
554{
555 struct device *dev = container_of(kobj, struct device, kobj);
556 struct ideapad_private *priv = dev_get_drvdata(dev);
557 bool supported;
558
559 if (attr == &dev_attr_camera_power.attr)
560 supported = test_bit(CFG_CAMERA_BIT, &(priv->cfg));
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +0800561 else if (attr == &dev_attr_fan_mode.attr) {
562 unsigned long value;
Zhang Rui331e0ea2013-09-25 20:39:49 +0800563 supported = !read_ec_data(priv->adev->handle, VPCCMD_R_FAN,
564 &value);
Hao Wei Teeade50292017-08-15 00:13:51 +0800565 } else if (attr == &dev_attr_conservation_mode.attr) {
566 supported = acpi_has_method(priv->adev->handle, "GBMD") &&
567 acpi_has_method(priv->adev->handle, "SBMC");
Oleg Keri40760712018-05-13 19:05:07 +0300568 } else if (attr == &dev_attr_fn_lock.attr) {
569 supported = acpi_has_method(priv->adev->handle, "HALS") &&
570 acpi_has_method(priv->adev->handle, "SALS");
Maxim Mikityanskiy0c7bbeb92012-07-06 16:08:11 +0800571 } else
Ike Panhca84511f2011-06-30 19:50:47 +0800572 supported = true;
573
574 return supported ? attr->mode : 0;
575}
576
Mathias Krause49458e82014-07-16 19:43:15 +0200577static const struct attribute_group ideapad_attribute_group = {
Ike Panhca84511f2011-06-30 19:50:47 +0800578 .is_visible = ideapad_is_visible,
Ike Panhc3371f482011-06-30 19:50:40 +0800579 .attrs = ideapad_attributes
580};
581
Ike Panhca4b5a272010-12-13 18:00:48 +0800582/*
583 * Rfkill
584 */
Ike Panhcc1f73652010-12-13 18:01:12 +0800585struct ideapad_rfk_data {
586 char *name;
587 int cfgbit;
588 int opcode;
589 int type;
590};
591
Mathias Krauseb3d94d72014-08-28 13:02:49 +0200592static const struct ideapad_rfk_data ideapad_rfk_data[] = {
Ike Panhc2be1dc22011-09-06 02:31:53 +0800593 { "ideapad_wlan", CFG_WIFI_BIT, VPCCMD_W_WIFI, RFKILL_TYPE_WLAN },
594 { "ideapad_bluetooth", CFG_BT_BIT, VPCCMD_W_BT, RFKILL_TYPE_BLUETOOTH },
595 { "ideapad_3g", CFG_3G_BIT, VPCCMD_W_3G, RFKILL_TYPE_WWAN },
Ike Panhcc1f73652010-12-13 18:01:12 +0800596};
597
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100598static int ideapad_rfk_set(void *data, bool blocked)
599{
Zhang Rui331e0ea2013-09-25 20:39:49 +0800600 struct ideapad_rfk_priv *priv = data;
Arnd Bergmann4b200b42015-06-13 15:23:33 +0200601 int opcode = ideapad_rfk_data[priv->dev].opcode;
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100602
Arnd Bergmann4b200b42015-06-13 15:23:33 +0200603 return write_ec_cmd(priv->priv->adev->handle, opcode, !blocked);
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100604}
605
Bhumika Goyal3d59dfc2017-06-09 11:38:18 +0530606static const struct rfkill_ops ideapad_rfk_ops = {
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100607 .set_block = ideapad_rfk_set,
608};
609
Ike Panhc923de842011-09-06 02:32:01 +0800610static void ideapad_sync_rfk_state(struct ideapad_private *priv)
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100611{
Hans de Goedece363c22014-06-23 16:45:51 +0200612 unsigned long hw_blocked = 0;
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100613 int i;
614
Hans de Goedece363c22014-06-23 16:45:51 +0200615 if (priv->has_hw_rfkill_switch) {
616 if (read_ec_data(priv->adev->handle, VPCCMD_R_RF, &hw_blocked))
617 return;
618 hw_blocked = !hw_blocked;
619 }
Ike Panhc2b7266b2010-10-01 15:39:49 +0800620
Ike Panhcc1f73652010-12-13 18:01:12 +0800621 for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
David Woodhousece326322010-08-11 17:59:35 +0100622 if (priv->rfk[i])
623 rfkill_set_hw_state(priv->rfk[i], hw_blocked);
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100624}
625
Zhang Rui75a11f12013-09-25 20:39:48 +0800626static int ideapad_register_rfkill(struct ideapad_private *priv, int dev)
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100627{
628 int ret;
Ike Panhc2b7266b2010-10-01 15:39:49 +0800629 unsigned long sw_blocked;
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100630
Ike Panhcbfa97b72010-10-01 15:40:22 +0800631 if (no_bt_rfkill &&
632 (ideapad_rfk_data[dev].type == RFKILL_TYPE_BLUETOOTH)) {
633 /* Force to enable bluetooth when no_bt_rfkill=1 */
Zhang Rui331e0ea2013-09-25 20:39:49 +0800634 write_ec_cmd(priv->adev->handle,
Ike Panhcbfa97b72010-10-01 15:40:22 +0800635 ideapad_rfk_data[dev].opcode, 1);
636 return 0;
637 }
Zhang Rui331e0ea2013-09-25 20:39:49 +0800638 priv->rfk_priv[dev].dev = dev;
639 priv->rfk_priv[dev].priv = priv;
Ike Panhcbfa97b72010-10-01 15:40:22 +0800640
Zhang Rui75a11f12013-09-25 20:39:48 +0800641 priv->rfk[dev] = rfkill_alloc(ideapad_rfk_data[dev].name,
Zhang Ruib5c37b72013-09-25 20:39:50 +0800642 &priv->platform_device->dev,
Zhang Rui75a11f12013-09-25 20:39:48 +0800643 ideapad_rfk_data[dev].type,
644 &ideapad_rfk_ops,
Zhang Rui331e0ea2013-09-25 20:39:49 +0800645 &priv->rfk_priv[dev]);
David Woodhousece326322010-08-11 17:59:35 +0100646 if (!priv->rfk[dev])
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100647 return -ENOMEM;
648
Zhang Rui331e0ea2013-09-25 20:39:49 +0800649 if (read_ec_data(priv->adev->handle, ideapad_rfk_data[dev].opcode-1,
Ike Panhc2b7266b2010-10-01 15:39:49 +0800650 &sw_blocked)) {
651 rfkill_init_sw_state(priv->rfk[dev], 0);
652 } else {
653 sw_blocked = !sw_blocked;
654 rfkill_init_sw_state(priv->rfk[dev], sw_blocked);
655 }
656
David Woodhousece326322010-08-11 17:59:35 +0100657 ret = rfkill_register(priv->rfk[dev]);
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100658 if (ret) {
David Woodhousece326322010-08-11 17:59:35 +0100659 rfkill_destroy(priv->rfk[dev]);
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100660 return ret;
661 }
662 return 0;
663}
664
Zhang Rui75a11f12013-09-25 20:39:48 +0800665static void ideapad_unregister_rfkill(struct ideapad_private *priv, int dev)
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100666{
David Woodhousece326322010-08-11 17:59:35 +0100667 if (!priv->rfk[dev])
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100668 return;
669
David Woodhousece326322010-08-11 17:59:35 +0100670 rfkill_unregister(priv->rfk[dev]);
671 rfkill_destroy(priv->rfk[dev]);
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100672}
673
Ike Panhc98ee6912010-12-13 18:00:15 +0800674/*
675 * Platform device
676 */
Zhang Ruib5c37b72013-09-25 20:39:50 +0800677static int ideapad_sysfs_init(struct ideapad_private *priv)
Ike Panhc98ee6912010-12-13 18:00:15 +0800678{
Zhang Ruib5c37b72013-09-25 20:39:50 +0800679 return sysfs_create_group(&priv->platform_device->dev.kobj,
Ike Panhcc9f718d2010-12-13 18:00:27 +0800680 &ideapad_attribute_group);
Ike Panhc98ee6912010-12-13 18:00:15 +0800681}
682
Zhang Ruib5c37b72013-09-25 20:39:50 +0800683static void ideapad_sysfs_exit(struct ideapad_private *priv)
Ike Panhc98ee6912010-12-13 18:00:15 +0800684{
Ike Panhc8693ae82010-12-13 18:01:01 +0800685 sysfs_remove_group(&priv->platform_device->dev.kobj,
Ike Panhcc9f718d2010-12-13 18:00:27 +0800686 &ideapad_attribute_group);
Ike Panhc98ee6912010-12-13 18:00:15 +0800687}
Ike Panhc98ee6912010-12-13 18:00:15 +0800688
Ike Panhcf63409a2010-12-13 18:00:38 +0800689/*
690 * input device
691 */
692static const struct key_entry ideapad_keymap[] = {
Ike Panhcf43d9ec2011-09-06 02:32:10 +0800693 { KE_KEY, 6, { KEY_SWITCHVIDEOMODE } },
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +0800694 { KE_KEY, 7, { KEY_CAMERA } },
Alex Hung48f67d62016-06-06 09:46:11 +0800695 { KE_KEY, 8, { KEY_MICMUTE } },
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +0800696 { KE_KEY, 11, { KEY_F16 } },
Ike Panhcf43d9ec2011-09-06 02:32:10 +0800697 { KE_KEY, 13, { KEY_WLAN } },
698 { KE_KEY, 16, { KEY_PROG1 } },
699 { KE_KEY, 17, { KEY_PROG2 } },
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +0800700 { KE_KEY, 64, { KEY_PROG3 } },
701 { KE_KEY, 65, { KEY_PROG4 } },
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +0800702 { KE_KEY, 66, { KEY_TOUCHPAD_OFF } },
703 { KE_KEY, 67, { KEY_TOUCHPAD_ON } },
Arnd Bergmann74caab92015-11-06 22:28:49 +0100704 { KE_KEY, 128, { KEY_ESC } },
705
Ike Panhcf63409a2010-12-13 18:00:38 +0800706 { KE_END, 0 },
707};
708
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -0800709static int ideapad_input_init(struct ideapad_private *priv)
Ike Panhcf63409a2010-12-13 18:00:38 +0800710{
711 struct input_dev *inputdev;
712 int error;
713
714 inputdev = input_allocate_device();
Joe Perchesb222cca2013-10-23 12:14:52 -0700715 if (!inputdev)
Ike Panhcf63409a2010-12-13 18:00:38 +0800716 return -ENOMEM;
Ike Panhcf63409a2010-12-13 18:00:38 +0800717
718 inputdev->name = "Ideapad extra buttons";
719 inputdev->phys = "ideapad/input0";
720 inputdev->id.bustype = BUS_HOST;
Ike Panhc8693ae82010-12-13 18:01:01 +0800721 inputdev->dev.parent = &priv->platform_device->dev;
Ike Panhcf63409a2010-12-13 18:00:38 +0800722
723 error = sparse_keymap_setup(inputdev, ideapad_keymap, NULL);
724 if (error) {
725 pr_err("Unable to setup input device keymap\n");
726 goto err_free_dev;
727 }
728
729 error = input_register_device(inputdev);
730 if (error) {
731 pr_err("Unable to register input device\n");
Michał Kępieńc973d4b2017-03-09 13:11:44 +0100732 goto err_free_dev;
Ike Panhcf63409a2010-12-13 18:00:38 +0800733 }
734
Ike Panhc8693ae82010-12-13 18:01:01 +0800735 priv->inputdev = inputdev;
Ike Panhcf63409a2010-12-13 18:00:38 +0800736 return 0;
737
Ike Panhcf63409a2010-12-13 18:00:38 +0800738err_free_dev:
739 input_free_device(inputdev);
740 return error;
741}
742
Axel Lin7451a552011-07-27 15:27:34 +0800743static void ideapad_input_exit(struct ideapad_private *priv)
Ike Panhcf63409a2010-12-13 18:00:38 +0800744{
Ike Panhc8693ae82010-12-13 18:01:01 +0800745 input_unregister_device(priv->inputdev);
746 priv->inputdev = NULL;
Ike Panhcf63409a2010-12-13 18:00:38 +0800747}
748
Ike Panhc8693ae82010-12-13 18:01:01 +0800749static void ideapad_input_report(struct ideapad_private *priv,
750 unsigned long scancode)
Ike Panhcf63409a2010-12-13 18:00:38 +0800751{
Ike Panhc8693ae82010-12-13 18:01:01 +0800752 sparse_keymap_report_event(priv->inputdev, scancode, 1, true);
Ike Panhcf63409a2010-12-13 18:00:38 +0800753}
Ike Panhcf63409a2010-12-13 18:00:38 +0800754
Ike Panhcf43d9ec2011-09-06 02:32:10 +0800755static void ideapad_input_novokey(struct ideapad_private *priv)
756{
757 unsigned long long_pressed;
758
Zhang Rui331e0ea2013-09-25 20:39:49 +0800759 if (read_ec_data(priv->adev->handle, VPCCMD_R_NOVO, &long_pressed))
Ike Panhcf43d9ec2011-09-06 02:32:10 +0800760 return;
761 if (long_pressed)
762 ideapad_input_report(priv, 17);
763 else
764 ideapad_input_report(priv, 16);
765}
766
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +0800767static void ideapad_check_special_buttons(struct ideapad_private *priv)
768{
769 unsigned long bit, value;
770
Zhang Rui331e0ea2013-09-25 20:39:49 +0800771 read_ec_data(priv->adev->handle, VPCCMD_R_SPECIAL_BUTTONS, &value);
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +0800772
773 for (bit = 0; bit < 16; bit++) {
774 if (test_bit(bit, &value)) {
775 switch (bit) {
Maxim Mikityanskiya1ec56e2013-03-20 12:34:17 +0200776 case 0: /* Z580 */
777 case 6: /* Z570 */
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +0800778 /* Thermal Management button */
779 ideapad_input_report(priv, 65);
780 break;
781 case 1:
782 /* OneKey Theater button */
783 ideapad_input_report(priv, 64);
784 break;
Maxim Mikityanskiya1ec56e2013-03-20 12:34:17 +0200785 default:
786 pr_info("Unknown special button: %lu\n", bit);
787 break;
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +0800788 }
789 }
790 }
791}
792
Ike Panhca4b5a272010-12-13 18:00:48 +0800793/*
Ike Panhca4ecbb82011-06-30 19:50:52 +0800794 * backlight
795 */
796static int ideapad_backlight_get_brightness(struct backlight_device *blightdev)
797{
Zhang Rui331e0ea2013-09-25 20:39:49 +0800798 struct ideapad_private *priv = bl_get_data(blightdev);
Ike Panhca4ecbb82011-06-30 19:50:52 +0800799 unsigned long now;
800
Zhang Rui331e0ea2013-09-25 20:39:49 +0800801 if (!priv)
802 return -EINVAL;
803
804 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now))
Ike Panhca4ecbb82011-06-30 19:50:52 +0800805 return -EIO;
806 return now;
807}
808
809static int ideapad_backlight_update_status(struct backlight_device *blightdev)
810{
Zhang Rui331e0ea2013-09-25 20:39:49 +0800811 struct ideapad_private *priv = bl_get_data(blightdev);
812
813 if (!priv)
814 return -EINVAL;
815
816 if (write_ec_cmd(priv->adev->handle, VPCCMD_W_BL,
Ike Panhc2be1dc22011-09-06 02:31:53 +0800817 blightdev->props.brightness))
Ike Panhca4ecbb82011-06-30 19:50:52 +0800818 return -EIO;
Zhang Rui331e0ea2013-09-25 20:39:49 +0800819 if (write_ec_cmd(priv->adev->handle, VPCCMD_W_BL_POWER,
Ike Panhca4ecbb82011-06-30 19:50:52 +0800820 blightdev->props.power == FB_BLANK_POWERDOWN ? 0 : 1))
821 return -EIO;
822
823 return 0;
824}
825
826static const struct backlight_ops ideapad_backlight_ops = {
827 .get_brightness = ideapad_backlight_get_brightness,
828 .update_status = ideapad_backlight_update_status,
829};
830
831static int ideapad_backlight_init(struct ideapad_private *priv)
832{
833 struct backlight_device *blightdev;
834 struct backlight_properties props;
835 unsigned long max, now, power;
836
Zhang Rui331e0ea2013-09-25 20:39:49 +0800837 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &max))
Ike Panhca4ecbb82011-06-30 19:50:52 +0800838 return -EIO;
Zhang Rui331e0ea2013-09-25 20:39:49 +0800839 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now))
Ike Panhca4ecbb82011-06-30 19:50:52 +0800840 return -EIO;
Zhang Rui331e0ea2013-09-25 20:39:49 +0800841 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power))
Ike Panhca4ecbb82011-06-30 19:50:52 +0800842 return -EIO;
843
844 memset(&props, 0, sizeof(struct backlight_properties));
845 props.max_brightness = max;
846 props.type = BACKLIGHT_PLATFORM;
847 blightdev = backlight_device_register("ideapad",
848 &priv->platform_device->dev,
849 priv,
850 &ideapad_backlight_ops,
851 &props);
852 if (IS_ERR(blightdev)) {
853 pr_err("Could not register backlight device\n");
854 return PTR_ERR(blightdev);
855 }
856
857 priv->blightdev = blightdev;
858 blightdev->props.brightness = now;
859 blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
860 backlight_update_status(blightdev);
861
862 return 0;
863}
864
865static void ideapad_backlight_exit(struct ideapad_private *priv)
866{
Markus Elfring00981812014-11-24 20:30:29 +0100867 backlight_device_unregister(priv->blightdev);
Ike Panhca4ecbb82011-06-30 19:50:52 +0800868 priv->blightdev = NULL;
869}
870
871static void ideapad_backlight_notify_power(struct ideapad_private *priv)
872{
873 unsigned long power;
874 struct backlight_device *blightdev = priv->blightdev;
875
Rene Bollfordd4afc772011-10-23 09:56:42 +0200876 if (!blightdev)
877 return;
Zhang Rui331e0ea2013-09-25 20:39:49 +0800878 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power))
Ike Panhca4ecbb82011-06-30 19:50:52 +0800879 return;
880 blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
881}
882
883static void ideapad_backlight_notify_brightness(struct ideapad_private *priv)
884{
885 unsigned long now;
886
887 /* if we control brightness via acpi video driver */
888 if (priv->blightdev == NULL) {
Zhang Rui331e0ea2013-09-25 20:39:49 +0800889 read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now);
Ike Panhca4ecbb82011-06-30 19:50:52 +0800890 return;
891 }
892
893 backlight_force_update(priv->blightdev, BACKLIGHT_UPDATE_HOTKEY);
894}
895
896/*
Ike Panhca4b5a272010-12-13 18:00:48 +0800897 * module init/exit
898 */
Zhang Rui75a11f12013-09-25 20:39:48 +0800899static void ideapad_sync_touchpad_state(struct ideapad_private *priv)
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +0800900{
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +0800901 unsigned long value;
902
903 /* Without reading from EC touchpad LED doesn't switch state */
Zhang Rui75a11f12013-09-25 20:39:48 +0800904 if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value)) {
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +0800905 /* Some IdeaPads don't really turn off touchpad - they only
906 * switch the LED state. We (de)activate KBC AUX port to turn
907 * touchpad off and on. We send KEY_TOUCHPAD_OFF and
908 * KEY_TOUCHPAD_ON to not to get out of sync with LED */
909 unsigned char param;
910 i8042_command(&param, value ? I8042_CMD_AUX_ENABLE :
911 I8042_CMD_AUX_DISABLE);
912 ideapad_input_report(priv, value ? 67 : 66);
913 }
914}
915
Zhang Ruib5c37b72013-09-25 20:39:50 +0800916static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data)
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100917{
Zhang Ruib5c37b72013-09-25 20:39:50 +0800918 struct ideapad_private *priv = data;
Ike Panhc8e7d3542010-10-01 15:39:05 +0800919 unsigned long vpc1, vpc2, vpc_bit;
920
Ike Panhc2be1dc22011-09-06 02:31:53 +0800921 if (read_ec_data(handle, VPCCMD_R_VPC1, &vpc1))
Ike Panhc8e7d3542010-10-01 15:39:05 +0800922 return;
Ike Panhc2be1dc22011-09-06 02:31:53 +0800923 if (read_ec_data(handle, VPCCMD_R_VPC2, &vpc2))
Ike Panhc8e7d3542010-10-01 15:39:05 +0800924 return;
925
926 vpc1 = (vpc2 << 8) | vpc1;
927 for (vpc_bit = 0; vpc_bit < 16; vpc_bit++) {
928 if (test_bit(vpc_bit, &vpc1)) {
Ike Panhca4ecbb82011-06-30 19:50:52 +0800929 switch (vpc_bit) {
930 case 9:
Ike Panhc923de842011-09-06 02:32:01 +0800931 ideapad_sync_rfk_state(priv);
Ike Panhca4ecbb82011-06-30 19:50:52 +0800932 break;
Ike Panhc20a769c2012-05-03 17:38:46 +0800933 case 13:
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +0800934 case 11:
Alex Hung48f67d62016-06-06 09:46:11 +0800935 case 8:
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +0800936 case 7:
Ike Panhc20a769c2012-05-03 17:38:46 +0800937 case 6:
938 ideapad_input_report(priv, vpc_bit);
939 break;
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +0800940 case 5:
Zhang Rui75a11f12013-09-25 20:39:48 +0800941 ideapad_sync_touchpad_state(priv);
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +0800942 break;
Ike Panhca4ecbb82011-06-30 19:50:52 +0800943 case 4:
944 ideapad_backlight_notify_brightness(priv);
945 break;
Ike Panhcf43d9ec2011-09-06 02:32:10 +0800946 case 3:
947 ideapad_input_novokey(priv);
948 break;
Ike Panhca4ecbb82011-06-30 19:50:52 +0800949 case 2:
950 ideapad_backlight_notify_power(priv);
951 break;
Maxim Mikityanskiy296f9fe2012-07-06 16:07:50 +0800952 case 0:
953 ideapad_check_special_buttons(priv);
954 break;
Hao Wei Tee3cfd9562017-05-22 18:38:55 +0800955 case 1:
956 /* Some IdeaPads report event 1 every ~20
957 * seconds while on battery power; some
958 * report this when changing to/from tablet
959 * mode. Squelch this event.
960 */
961 break;
Ike Panhca4ecbb82011-06-30 19:50:52 +0800962 default:
Ike Panhc20a769c2012-05-03 17:38:46 +0800963 pr_info("Unknown event: %lu\n", vpc_bit);
Ike Panhca4ecbb82011-06-30 19:50:52 +0800964 }
Ike Panhc8e7d3542010-10-01 15:39:05 +0800965 }
966 }
David Woodhouse58ac7aa2010-08-10 23:44:05 +0100967}
968
Arnd Bergmann74caab92015-11-06 22:28:49 +0100969#if IS_ENABLED(CONFIG_ACPI_WMI)
970static void ideapad_wmi_notify(u32 value, void *context)
971{
972 switch (value) {
973 case 128:
974 ideapad_input_report(context, value);
975 break;
976 default:
977 pr_info("Unknown WMI event %u\n", value);
978 }
979}
980#endif
981
Hans de Goedece363c22014-06-23 16:45:51 +0200982/*
983 * Some ideapads don't have a hardware rfkill switch, reading VPCCMD_R_RF
984 * always results in 0 on these models, causing ideapad_laptop to wrongly
985 * report all radios as hardware-blocked.
986 */
Mathias Krauseb3d94d72014-08-28 13:02:49 +0200987static const struct dmi_system_id no_hw_rfkill_list[] = {
Hans de Goede85093f72014-05-13 16:00:28 +0200988 {
Jiaxun Yangae7c8cb2017-12-02 21:45:34 +0800989 .ident = "Lenovo RESCUER R720-15IKBN",
990 .matches = {
991 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
992 DMI_MATCH(DMI_BOARD_NAME, "80WW"),
993 },
994 },
995 {
Philippe Coval9b071a42015-05-02 15:14:08 +0200996 .ident = "Lenovo G40-30",
997 .matches = {
998 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
999 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo G40-30"),
1000 },
1001 },
1002 {
Dmitry Tunin4fa9dab2015-01-18 15:44:40 +03001003 .ident = "Lenovo G50-30",
1004 .matches = {
1005 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1006 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo G50-30"),
1007 },
1008 },
1009 {
Yang Jiaxun710c0592017-07-04 14:39:19 +00001010 .ident = "Lenovo V310-14IKB",
1011 .matches = {
1012 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1013 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo V310-14IKB"),
1014 },
1015 },
1016 {
1017 .ident = "Lenovo V310-14ISK",
1018 .matches = {
1019 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1020 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo V310-14ISK"),
1021 },
1022 },
1023 {
1024 .ident = "Lenovo V310-15IKB",
1025 .matches = {
1026 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1027 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo V310-15IKB"),
1028 },
1029 },
1030 {
Andy Shevchenkoccc71792017-02-21 20:53:48 +01001031 .ident = "Lenovo V310-15ISK",
1032 .matches = {
Andy Shevchenko5e8f42a2017-07-04 18:34:39 +03001033 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1034 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo V310-15ISK"),
Andy Shevchenkoccc71792017-02-21 20:53:48 +01001035 },
1036 },
1037 {
Sven Eckelmann0df4b802017-07-01 08:20:18 +02001038 .ident = "Lenovo V510-15IKB",
1039 .matches = {
1040 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1041 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo V510-15IKB"),
1042 },
1043 },
1044 {
Yang Jiaxun710c0592017-07-04 14:39:19 +00001045 .ident = "Lenovo ideapad 300-15IBR",
1046 .matches = {
1047 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1048 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad 300-15IBR"),
1049 },
1050 },
1051 {
1052 .ident = "Lenovo ideapad 300-15IKB",
1053 .matches = {
1054 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1055 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad 300-15IKB"),
1056 },
1057 },
1058 {
1059 .ident = "Lenovo ideapad 300S-11IBR",
1060 .matches = {
1061 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1062 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad 300S-11BR"),
1063 },
1064 },
1065 {
1066 .ident = "Lenovo ideapad 310-15ABR",
1067 .matches = {
1068 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1069 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad 310-15ABR"),
1070 },
1071 },
1072 {
1073 .ident = "Lenovo ideapad 310-15IAP",
1074 .matches = {
1075 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1076 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad 310-15IAP"),
1077 },
1078 },
1079 {
Sven Rebhan1f3bc532017-02-21 20:53:48 +01001080 .ident = "Lenovo ideapad 310-15IKB",
1081 .matches = {
Andy Shevchenko5e8f42a2017-07-04 18:34:39 +03001082 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1083 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad 310-15IKB"),
Sven Rebhan1f3bc532017-02-21 20:53:48 +01001084 },
1085 },
1086 {
Yang Jiaxun710c0592017-07-04 14:39:19 +00001087 .ident = "Lenovo ideapad 310-15ISK",
1088 .matches = {
1089 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1090 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad 310-15ISK"),
1091 },
1092 },
1093 {
1094 .ident = "Lenovo ideapad Y700-14ISK",
1095 .matches = {
1096 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1097 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad Y700-14ISK"),
1098 },
1099 },
1100 {
velemase2970462016-12-06 22:17:43 +03001101 .ident = "Lenovo ideapad Y700-15ACZ",
1102 .matches = {
1103 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1104 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad Y700-15ACZ"),
1105 },
1106 },
1107 {
John Dahlstrom4db96752016-02-27 00:09:58 -06001108 .ident = "Lenovo ideapad Y700-15ISK",
1109 .matches = {
1110 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1111 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad Y700-15ISK"),
1112 },
1113 },
1114 {
1115 .ident = "Lenovo ideapad Y700 Touch-15ISK",
1116 .matches = {
1117 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1118 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad Y700 Touch-15ISK"),
1119 },
1120 },
1121 {
Josh Boyeredde3162015-12-09 21:12:52 -05001122 .ident = "Lenovo ideapad Y700-17ISK",
1123 .matches = {
1124 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1125 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad Y700-17ISK"),
1126 },
1127 },
1128 {
Takashi Iwai7caf0c12018-05-14 15:31:28 +02001129 .ident = "Lenovo ideapad MIIX 720-12IKB",
1130 .matches = {
1131 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1132 DMI_MATCH(DMI_PRODUCT_VERSION, "MIIX 720-12IKB"),
1133 },
1134 },
1135 {
Olle Liljenzin5d9f40b2017-06-18 13:09:31 +02001136 .ident = "Lenovo Legion Y520-15IKBN",
1137 .matches = {
1138 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1139 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Y520-15IKBN"),
1140 },
1141 },
1142 {
Olle Liljenzin28d71ae2018-01-07 20:53:12 +01001143 .ident = "Lenovo Legion Y720-15IKB",
1144 .matches = {
1145 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1146 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Y720-15IKB"),
1147 },
1148 },
1149 {
Olle Liljenzinb2f2fe22017-06-18 14:37:58 +02001150 .ident = "Lenovo Legion Y720-15IKBN",
1151 .matches = {
1152 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1153 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Y720-15IKBN"),
1154 },
1155 },
1156 {
Hans de Goedece363c22014-06-23 16:45:51 +02001157 .ident = "Lenovo Yoga 2 11 / 13 / Pro",
Hans de Goede85093f72014-05-13 16:00:28 +02001158 .matches = {
1159 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
Hans de Goedece363c22014-06-23 16:45:51 +02001160 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Yoga 2"),
Hans de Goede85093f72014-05-13 16:00:28 +02001161 },
1162 },
Stephan Mueller725c7f62014-10-27 04:09:50 +01001163 {
Sebastian Krzyszkowiak6d212b82015-07-19 01:10:21 +02001164 .ident = "Lenovo Yoga 2 11 / 13 / Pro",
1165 .matches = {
1166 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1167 DMI_MATCH(DMI_BOARD_NAME, "Yoga2"),
1168 },
1169 },
1170 {
Arnd Bergmannc789fff2015-11-06 23:26:59 +01001171 .ident = "Lenovo Yoga 3 1170 / 1470",
1172 .matches = {
1173 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1174 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Yoga 3"),
1175 },
1176 },
1177 {
Stephan Mueller725c7f62014-10-27 04:09:50 +01001178 .ident = "Lenovo Yoga 3 Pro 1370",
1179 .matches = {
1180 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
Arnd Bergmannc789fff2015-11-06 23:26:59 +01001181 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo YOGA 3"),
Stephan Mueller725c7f62014-10-27 04:09:50 +01001182 },
1183 },
Hans de Goedef71c8822015-11-09 17:09:05 +01001184 {
Josh Boyer6b31de32016-01-24 10:46:42 -05001185 .ident = "Lenovo Yoga 700",
1186 .matches = {
1187 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1188 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo YOGA 700"),
1189 },
1190 },
1191 {
Hans de Goedef71c8822015-11-09 17:09:05 +01001192 .ident = "Lenovo Yoga 900",
1193 .matches = {
1194 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1195 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo YOGA 900"),
1196 },
1197 },
Brian Masney40c30bb2016-10-11 19:28:02 -04001198 {
Mika Westerberg446647d2016-10-19 13:27:40 +03001199 .ident = "Lenovo Yoga 900",
1200 .matches = {
1201 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1202 DMI_MATCH(DMI_BOARD_NAME, "VIUU4"),
1203 },
1204 },
1205 {
Brian Masney40c30bb2016-10-11 19:28:02 -04001206 .ident = "Lenovo YOGA 910-13IKB",
1207 .matches = {
1208 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1209 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo YOGA 910-13IKB"),
1210 },
1211 },
Philipp Hugb231669c2017-10-24 16:32:22 +02001212 {
1213 .ident = "Lenovo YOGA 920-13IKB",
1214 .matches = {
1215 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1216 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo YOGA 920-13IKB"),
1217 },
1218 },
dylanchu12625162018-05-28 19:44:48 +08001219 {
1220 .ident = "Lenovo Zhaoyang E42-80",
1221 .matches = {
1222 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1223 DMI_MATCH(DMI_PRODUCT_VERSION, "ZHAOYANG E42-80"),
1224 },
1225 },
Hans de Goede85093f72014-05-13 16:00:28 +02001226 {}
1227};
1228
Zhang Ruib5c37b72013-09-25 20:39:50 +08001229static int ideapad_acpi_add(struct platform_device *pdev)
1230{
1231 int ret, i;
1232 int cfg;
1233 struct ideapad_private *priv;
1234 struct acpi_device *adev;
1235
1236 ret = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev);
1237 if (ret)
1238 return -ENODEV;
1239
1240 if (read_method_int(adev->handle, "_CFG", &cfg))
1241 return -ENODEV;
1242
Himangi Saraogib3facd72014-06-09 17:46:50 -04001243 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
Zhang Ruib5c37b72013-09-25 20:39:50 +08001244 if (!priv)
1245 return -ENOMEM;
1246
1247 dev_set_drvdata(&pdev->dev, priv);
1248 priv->cfg = cfg;
1249 priv->adev = adev;
1250 priv->platform_device = pdev;
Hans de Goedece363c22014-06-23 16:45:51 +02001251 priv->has_hw_rfkill_switch = !dmi_check_system(no_hw_rfkill_list);
Zhang Ruib5c37b72013-09-25 20:39:50 +08001252
1253 ret = ideapad_sysfs_init(priv);
1254 if (ret)
Himangi Saraogib3facd72014-06-09 17:46:50 -04001255 return ret;
Zhang Ruib5c37b72013-09-25 20:39:50 +08001256
1257 ret = ideapad_debugfs_init(priv);
1258 if (ret)
1259 goto debugfs_failed;
1260
1261 ret = ideapad_input_init(priv);
1262 if (ret)
1263 goto input_failed;
1264
Hans de Goedece363c22014-06-23 16:45:51 +02001265 /*
1266 * On some models without a hw-switch (the yoga 2 13 at least)
1267 * VPCCMD_W_RF must be explicitly set to 1 for the wifi to work.
1268 */
1269 if (!priv->has_hw_rfkill_switch)
1270 write_ec_cmd(priv->adev->handle, VPCCMD_W_RF, 1);
1271
1272 for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
1273 if (test_bit(ideapad_rfk_data[i].cfgbit, &priv->cfg))
1274 ideapad_register_rfkill(priv, i);
1275
Zhang Ruib5c37b72013-09-25 20:39:50 +08001276 ideapad_sync_rfk_state(priv);
1277 ideapad_sync_touchpad_state(priv);
1278
Hans de Goede26bff5f2015-06-16 16:28:04 +02001279 if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
Zhang Ruib5c37b72013-09-25 20:39:50 +08001280 ret = ideapad_backlight_init(priv);
1281 if (ret && ret != -ENODEV)
1282 goto backlight_failed;
1283 }
1284 ret = acpi_install_notify_handler(adev->handle,
1285 ACPI_DEVICE_NOTIFY, ideapad_acpi_notify, priv);
1286 if (ret)
1287 goto notification_failed;
Arnd Bergmann2d98e0b2016-05-09 23:49:21 +02001288
Arnd Bergmann74caab92015-11-06 22:28:49 +01001289#if IS_ENABLED(CONFIG_ACPI_WMI)
Arnd Bergmann2d98e0b2016-05-09 23:49:21 +02001290 for (i = 0; i < ARRAY_SIZE(ideapad_wmi_fnesc_events); i++) {
1291 ret = wmi_install_notify_handler(ideapad_wmi_fnesc_events[i],
1292 ideapad_wmi_notify, priv);
1293 if (ret == AE_OK) {
1294 priv->fnesc_guid = ideapad_wmi_fnesc_events[i];
1295 break;
1296 }
1297 }
Arnd Bergmann74caab92015-11-06 22:28:49 +01001298 if (ret != AE_OK && ret != AE_NOT_EXIST)
1299 goto notification_failed_wmi;
1300#endif
Zhang Ruib5c37b72013-09-25 20:39:50 +08001301
1302 return 0;
Arnd Bergmann74caab92015-11-06 22:28:49 +01001303#if IS_ENABLED(CONFIG_ACPI_WMI)
1304notification_failed_wmi:
1305 acpi_remove_notify_handler(priv->adev->handle,
1306 ACPI_DEVICE_NOTIFY, ideapad_acpi_notify);
1307#endif
Zhang Ruib5c37b72013-09-25 20:39:50 +08001308notification_failed:
1309 ideapad_backlight_exit(priv);
1310backlight_failed:
1311 for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
1312 ideapad_unregister_rfkill(priv, i);
1313 ideapad_input_exit(priv);
1314input_failed:
1315 ideapad_debugfs_exit(priv);
1316debugfs_failed:
1317 ideapad_sysfs_exit(priv);
Zhang Ruib5c37b72013-09-25 20:39:50 +08001318 return ret;
1319}
1320
1321static int ideapad_acpi_remove(struct platform_device *pdev)
1322{
1323 struct ideapad_private *priv = dev_get_drvdata(&pdev->dev);
1324 int i;
1325
Arnd Bergmann74caab92015-11-06 22:28:49 +01001326#if IS_ENABLED(CONFIG_ACPI_WMI)
Arnd Bergmann2d98e0b2016-05-09 23:49:21 +02001327 if (priv->fnesc_guid)
1328 wmi_remove_notify_handler(priv->fnesc_guid);
Arnd Bergmann74caab92015-11-06 22:28:49 +01001329#endif
Zhang Ruib5c37b72013-09-25 20:39:50 +08001330 acpi_remove_notify_handler(priv->adev->handle,
1331 ACPI_DEVICE_NOTIFY, ideapad_acpi_notify);
1332 ideapad_backlight_exit(priv);
1333 for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
1334 ideapad_unregister_rfkill(priv, i);
1335 ideapad_input_exit(priv);
1336 ideapad_debugfs_exit(priv);
1337 ideapad_sysfs_exit(priv);
1338 dev_set_drvdata(&pdev->dev, NULL);
Zhang Ruib5c37b72013-09-25 20:39:50 +08001339
1340 return 0;
1341}
1342
Zhang Rui11fa8da2013-09-25 20:39:46 +08001343#ifdef CONFIG_PM_SLEEP
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +08001344static int ideapad_acpi_resume(struct device *device)
1345{
Zhang Rui75a11f12013-09-25 20:39:48 +08001346 struct ideapad_private *priv;
1347
1348 if (!device)
1349 return -EINVAL;
1350 priv = dev_get_drvdata(device);
1351
1352 ideapad_sync_rfk_state(priv);
1353 ideapad_sync_touchpad_state(priv);
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +08001354 return 0;
1355}
Zhang Ruib5c37b72013-09-25 20:39:50 +08001356#endif
Maxim Mikityanskiy07a4a4f2012-07-06 16:08:00 +08001357static SIMPLE_DEV_PM_OPS(ideapad_pm, NULL, ideapad_acpi_resume);
1358
Zhang Ruib5c37b72013-09-25 20:39:50 +08001359static const struct acpi_device_id ideapad_device_ids[] = {
1360 { "VPC2004", 0},
1361 { "", 0},
David Woodhouse58ac7aa2010-08-10 23:44:05 +01001362};
Zhang Ruib5c37b72013-09-25 20:39:50 +08001363MODULE_DEVICE_TABLE(acpi, ideapad_device_ids);
1364
1365static struct platform_driver ideapad_acpi_driver = {
1366 .probe = ideapad_acpi_add,
1367 .remove = ideapad_acpi_remove,
1368 .driver = {
1369 .name = "ideapad_acpi",
Zhang Ruib5c37b72013-09-25 20:39:50 +08001370 .pm = &ideapad_pm,
1371 .acpi_match_table = ACPI_PTR(ideapad_device_ids),
1372 },
1373};
1374
1375module_platform_driver(ideapad_acpi_driver);
David Woodhouse58ac7aa2010-08-10 23:44:05 +01001376
1377MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
1378MODULE_DESCRIPTION("IdeaPad ACPI Extras");
1379MODULE_LICENSE("GPL");