2 * ideapad-laptop.c - Lenovo IdeaPad ACPI Extras
4 * Copyright © 2010 Intel Corporation
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.
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.
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
23 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/init.h>
28 #include <linux/types.h>
29 #include <linux/acpi.h>
30 #include <linux/rfkill.h>
31 #include <linux/platform_device.h>
32 #include <linux/input.h>
33 #include <linux/input/sparse-keymap.h>
34 #include <linux/backlight.h>
36 #include <linux/debugfs.h>
37 #include <linux/seq_file.h>
38 #include <linux/i8042.h>
39 #include <linux/dmi.h>
40 #include <linux/device.h>
41 #include <acpi/video.h>
43 #define IDEAPAD_RFKILL_DEV_NUM (3)
45 #define CFG_BT_BIT (16)
46 #define CFG_3G_BIT (17)
47 #define CFG_WIFI_BIT (18)
48 #define CFG_CAMERA_BIT (19)
50 #if IS_ENABLED(CONFIG_ACPI_WMI)
51 static const char *const ideapad_wmi_fnesc_events[] = {
52 "26CAB2E5-5CF1-46AE-AAC3-4A12B6BA50E6", /* Yoga 3 */
53 "56322276-8493-4CE8-A783-98C991274F5E", /* Yoga 700 */
75 VPCCMD_R_ODD, /* 0x21 */
80 VPCCMD_R_SPECIAL_BUTTONS = 0x31,
81 VPCCMD_W_BL_POWER = 0x33,
84 struct ideapad_rfk_priv {
86 struct ideapad_private *priv;
89 struct ideapad_private {
90 struct acpi_device *adev;
91 struct rfkill *rfk[IDEAPAD_RFKILL_DEV_NUM];
92 struct ideapad_rfk_priv rfk_priv[IDEAPAD_RFKILL_DEV_NUM];
93 struct platform_device *platform_device;
94 struct input_dev *inputdev;
95 struct backlight_device *blightdev;
98 bool has_hw_rfkill_switch;
99 const char *fnesc_guid;
102 static bool no_bt_rfkill;
103 module_param(no_bt_rfkill, bool, 0444);
104 MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth.");
109 #define IDEAPAD_EC_TIMEOUT (100) /* in ms */
111 static int read_method_int(acpi_handle handle, const char *method, int *val)
114 unsigned long long result;
116 status = acpi_evaluate_integer(handle, (char *)method, NULL, &result);
117 if (ACPI_FAILURE(status)) {
126 static int method_vpcr(acpi_handle handle, int cmd, int *ret)
129 unsigned long long result;
130 struct acpi_object_list params;
131 union acpi_object in_obj;
134 params.pointer = &in_obj;
135 in_obj.type = ACPI_TYPE_INTEGER;
136 in_obj.integer.value = cmd;
138 status = acpi_evaluate_integer(handle, "VPCR", ¶ms, &result);
140 if (ACPI_FAILURE(status)) {
149 static int method_vpcw(acpi_handle handle, int cmd, int data)
151 struct acpi_object_list params;
152 union acpi_object in_obj[2];
156 params.pointer = in_obj;
157 in_obj[0].type = ACPI_TYPE_INTEGER;
158 in_obj[0].integer.value = cmd;
159 in_obj[1].type = ACPI_TYPE_INTEGER;
160 in_obj[1].integer.value = data;
162 status = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL);
168 static int read_ec_data(acpi_handle handle, int cmd, unsigned long *data)
171 unsigned long int end_jiffies;
173 if (method_vpcw(handle, 1, cmd))
176 for (end_jiffies = jiffies+(HZ)*IDEAPAD_EC_TIMEOUT/1000+1;
177 time_before(jiffies, end_jiffies);) {
179 if (method_vpcr(handle, 1, &val))
182 if (method_vpcr(handle, 0, &val))
188 pr_err("timeout in read_ec_cmd\n");
192 static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data)
195 unsigned long int end_jiffies;
197 if (method_vpcw(handle, 0, data))
199 if (method_vpcw(handle, 1, cmd))
202 for (end_jiffies = jiffies+(HZ)*IDEAPAD_EC_TIMEOUT/1000+1;
203 time_before(jiffies, end_jiffies);) {
205 if (method_vpcr(handle, 1, &val))
210 pr_err("timeout in write_ec_cmd\n");
217 static int debugfs_status_show(struct seq_file *s, void *data)
219 struct ideapad_private *priv = s->private;
225 if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &value))
226 seq_printf(s, "Backlight max:\t%lu\n", value);
227 if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL, &value))
228 seq_printf(s, "Backlight now:\t%lu\n", value);
229 if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &value))
230 seq_printf(s, "BL power value:\t%s\n", value ? "On" : "Off");
231 seq_printf(s, "=====================\n");
233 if (!read_ec_data(priv->adev->handle, VPCCMD_R_RF, &value))
234 seq_printf(s, "Radio status:\t%s(%lu)\n",
235 value ? "On" : "Off", value);
236 if (!read_ec_data(priv->adev->handle, VPCCMD_R_WIFI, &value))
237 seq_printf(s, "Wifi status:\t%s(%lu)\n",
238 value ? "On" : "Off", value);
239 if (!read_ec_data(priv->adev->handle, VPCCMD_R_BT, &value))
240 seq_printf(s, "BT status:\t%s(%lu)\n",
241 value ? "On" : "Off", value);
242 if (!read_ec_data(priv->adev->handle, VPCCMD_R_3G, &value))
243 seq_printf(s, "3G status:\t%s(%lu)\n",
244 value ? "On" : "Off", value);
245 seq_printf(s, "=====================\n");
247 if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value))
248 seq_printf(s, "Touchpad status:%s(%lu)\n",
249 value ? "On" : "Off", value);
250 if (!read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &value))
251 seq_printf(s, "Camera status:\t%s(%lu)\n",
252 value ? "On" : "Off", value);
257 static int debugfs_status_open(struct inode *inode, struct file *file)
259 return single_open(file, debugfs_status_show, inode->i_private);
262 static const struct file_operations debugfs_status_fops = {
263 .owner = THIS_MODULE,
264 .open = debugfs_status_open,
267 .release = single_release,
270 static int debugfs_cfg_show(struct seq_file *s, void *data)
272 struct ideapad_private *priv = s->private;
275 seq_printf(s, "cfg: N/A\n");
277 seq_printf(s, "cfg: 0x%.8lX\n\nCapability: ",
279 if (test_bit(CFG_BT_BIT, &priv->cfg))
280 seq_printf(s, "Bluetooth ");
281 if (test_bit(CFG_3G_BIT, &priv->cfg))
282 seq_printf(s, "3G ");
283 if (test_bit(CFG_WIFI_BIT, &priv->cfg))
284 seq_printf(s, "Wireless ");
285 if (test_bit(CFG_CAMERA_BIT, &priv->cfg))
286 seq_printf(s, "Camera ");
287 seq_printf(s, "\nGraphic: ");
288 switch ((priv->cfg)&0x700) {
290 seq_printf(s, "Intel");
293 seq_printf(s, "ATI");
296 seq_printf(s, "Nvidia");
299 seq_printf(s, "Intel and ATI");
302 seq_printf(s, "Intel and Nvidia");
310 static int debugfs_cfg_open(struct inode *inode, struct file *file)
312 return single_open(file, debugfs_cfg_show, inode->i_private);
315 static const struct file_operations debugfs_cfg_fops = {
316 .owner = THIS_MODULE,
317 .open = debugfs_cfg_open,
320 .release = single_release,
323 static int ideapad_debugfs_init(struct ideapad_private *priv)
327 priv->debug = debugfs_create_dir("ideapad", NULL);
328 if (priv->debug == NULL) {
329 pr_err("failed to create debugfs directory");
333 node = debugfs_create_file("cfg", S_IRUGO, priv->debug, priv,
336 pr_err("failed to create cfg in debugfs");
340 node = debugfs_create_file("status", S_IRUGO, priv->debug, priv,
341 &debugfs_status_fops);
343 pr_err("failed to create status in debugfs");
353 static void ideapad_debugfs_exit(struct ideapad_private *priv)
355 debugfs_remove_recursive(priv->debug);
362 static ssize_t show_ideapad_cam(struct device *dev,
363 struct device_attribute *attr,
366 unsigned long result;
367 struct ideapad_private *priv = dev_get_drvdata(dev);
369 if (read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &result))
370 return sprintf(buf, "-1\n");
371 return sprintf(buf, "%lu\n", result);
374 static ssize_t store_ideapad_cam(struct device *dev,
375 struct device_attribute *attr,
376 const char *buf, size_t count)
379 struct ideapad_private *priv = dev_get_drvdata(dev);
383 if (sscanf(buf, "%i", &state) != 1)
385 ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_CAMERA, state);
391 static DEVICE_ATTR(camera_power, 0644, show_ideapad_cam, store_ideapad_cam);
393 static ssize_t show_ideapad_fan(struct device *dev,
394 struct device_attribute *attr,
397 unsigned long result;
398 struct ideapad_private *priv = dev_get_drvdata(dev);
400 if (read_ec_data(priv->adev->handle, VPCCMD_R_FAN, &result))
401 return sprintf(buf, "-1\n");
402 return sprintf(buf, "%lu\n", result);
405 static ssize_t store_ideapad_fan(struct device *dev,
406 struct device_attribute *attr,
407 const char *buf, size_t count)
410 struct ideapad_private *priv = dev_get_drvdata(dev);
414 if (sscanf(buf, "%i", &state) != 1)
416 if (state < 0 || state > 4 || state == 3)
418 ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_FAN, state);
424 static DEVICE_ATTR(fan_mode, 0644, show_ideapad_fan, store_ideapad_fan);
426 static ssize_t touchpad_show(struct device *dev,
427 struct device_attribute *attr,
430 struct ideapad_private *priv = dev_get_drvdata(dev);
431 unsigned long result;
433 if (read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &result))
434 return sprintf(buf, "-1\n");
435 return sprintf(buf, "%lu\n", result);
438 /* Switch to RO for now: It might be revisited in the future */
439 static ssize_t __maybe_unused touchpad_store(struct device *dev,
440 struct device_attribute *attr,
441 const char *buf, size_t count)
443 struct ideapad_private *priv = dev_get_drvdata(dev);
447 ret = kstrtobool(buf, &state);
451 ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_TOUCHPAD, state);
457 static DEVICE_ATTR_RO(touchpad);
459 static struct attribute *ideapad_attributes[] = {
460 &dev_attr_camera_power.attr,
461 &dev_attr_fan_mode.attr,
462 &dev_attr_touchpad.attr,
466 static umode_t ideapad_is_visible(struct kobject *kobj,
467 struct attribute *attr,
470 struct device *dev = container_of(kobj, struct device, kobj);
471 struct ideapad_private *priv = dev_get_drvdata(dev);
474 if (attr == &dev_attr_camera_power.attr)
475 supported = test_bit(CFG_CAMERA_BIT, &(priv->cfg));
476 else if (attr == &dev_attr_fan_mode.attr) {
478 supported = !read_ec_data(priv->adev->handle, VPCCMD_R_FAN,
483 return supported ? attr->mode : 0;
486 static const struct attribute_group ideapad_attribute_group = {
487 .is_visible = ideapad_is_visible,
488 .attrs = ideapad_attributes
494 struct ideapad_rfk_data {
501 static const struct ideapad_rfk_data ideapad_rfk_data[] = {
502 { "ideapad_wlan", CFG_WIFI_BIT, VPCCMD_W_WIFI, RFKILL_TYPE_WLAN },
503 { "ideapad_bluetooth", CFG_BT_BIT, VPCCMD_W_BT, RFKILL_TYPE_BLUETOOTH },
504 { "ideapad_3g", CFG_3G_BIT, VPCCMD_W_3G, RFKILL_TYPE_WWAN },
507 static int ideapad_rfk_set(void *data, bool blocked)
509 struct ideapad_rfk_priv *priv = data;
510 int opcode = ideapad_rfk_data[priv->dev].opcode;
512 return write_ec_cmd(priv->priv->adev->handle, opcode, !blocked);
515 static const struct rfkill_ops ideapad_rfk_ops = {
516 .set_block = ideapad_rfk_set,
519 static void ideapad_sync_rfk_state(struct ideapad_private *priv)
521 unsigned long hw_blocked = 0;
524 if (priv->has_hw_rfkill_switch) {
525 if (read_ec_data(priv->adev->handle, VPCCMD_R_RF, &hw_blocked))
527 hw_blocked = !hw_blocked;
530 for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
532 rfkill_set_hw_state(priv->rfk[i], hw_blocked);
535 static int ideapad_register_rfkill(struct ideapad_private *priv, int dev)
538 unsigned long sw_blocked;
541 (ideapad_rfk_data[dev].type == RFKILL_TYPE_BLUETOOTH)) {
542 /* Force to enable bluetooth when no_bt_rfkill=1 */
543 write_ec_cmd(priv->adev->handle,
544 ideapad_rfk_data[dev].opcode, 1);
547 priv->rfk_priv[dev].dev = dev;
548 priv->rfk_priv[dev].priv = priv;
550 priv->rfk[dev] = rfkill_alloc(ideapad_rfk_data[dev].name,
551 &priv->platform_device->dev,
552 ideapad_rfk_data[dev].type,
554 &priv->rfk_priv[dev]);
558 if (read_ec_data(priv->adev->handle, ideapad_rfk_data[dev].opcode-1,
560 rfkill_init_sw_state(priv->rfk[dev], 0);
562 sw_blocked = !sw_blocked;
563 rfkill_init_sw_state(priv->rfk[dev], sw_blocked);
566 ret = rfkill_register(priv->rfk[dev]);
568 rfkill_destroy(priv->rfk[dev]);
574 static void ideapad_unregister_rfkill(struct ideapad_private *priv, int dev)
579 rfkill_unregister(priv->rfk[dev]);
580 rfkill_destroy(priv->rfk[dev]);
586 static int ideapad_sysfs_init(struct ideapad_private *priv)
588 return sysfs_create_group(&priv->platform_device->dev.kobj,
589 &ideapad_attribute_group);
592 static void ideapad_sysfs_exit(struct ideapad_private *priv)
594 sysfs_remove_group(&priv->platform_device->dev.kobj,
595 &ideapad_attribute_group);
601 static const struct key_entry ideapad_keymap[] = {
602 { KE_KEY, 6, { KEY_SWITCHVIDEOMODE } },
603 { KE_KEY, 7, { KEY_CAMERA } },
604 { KE_KEY, 8, { KEY_MICMUTE } },
605 { KE_KEY, 11, { KEY_F16 } },
606 { KE_KEY, 13, { KEY_WLAN } },
607 { KE_KEY, 16, { KEY_PROG1 } },
608 { KE_KEY, 17, { KEY_PROG2 } },
609 { KE_KEY, 64, { KEY_PROG3 } },
610 { KE_KEY, 65, { KEY_PROG4 } },
611 { KE_KEY, 66, { KEY_TOUCHPAD_OFF } },
612 { KE_KEY, 67, { KEY_TOUCHPAD_ON } },
613 { KE_KEY, 128, { KEY_ESC } },
618 static int ideapad_input_init(struct ideapad_private *priv)
620 struct input_dev *inputdev;
623 inputdev = input_allocate_device();
627 inputdev->name = "Ideapad extra buttons";
628 inputdev->phys = "ideapad/input0";
629 inputdev->id.bustype = BUS_HOST;
630 inputdev->dev.parent = &priv->platform_device->dev;
632 error = sparse_keymap_setup(inputdev, ideapad_keymap, NULL);
634 pr_err("Unable to setup input device keymap\n");
638 error = input_register_device(inputdev);
640 pr_err("Unable to register input device\n");
644 priv->inputdev = inputdev;
648 input_free_device(inputdev);
652 static void ideapad_input_exit(struct ideapad_private *priv)
654 input_unregister_device(priv->inputdev);
655 priv->inputdev = NULL;
658 static void ideapad_input_report(struct ideapad_private *priv,
659 unsigned long scancode)
661 sparse_keymap_report_event(priv->inputdev, scancode, 1, true);
664 static void ideapad_input_novokey(struct ideapad_private *priv)
666 unsigned long long_pressed;
668 if (read_ec_data(priv->adev->handle, VPCCMD_R_NOVO, &long_pressed))
671 ideapad_input_report(priv, 17);
673 ideapad_input_report(priv, 16);
676 static void ideapad_check_special_buttons(struct ideapad_private *priv)
678 unsigned long bit, value;
680 read_ec_data(priv->adev->handle, VPCCMD_R_SPECIAL_BUTTONS, &value);
682 for (bit = 0; bit < 16; bit++) {
683 if (test_bit(bit, &value)) {
687 /* Thermal Management button */
688 ideapad_input_report(priv, 65);
691 /* OneKey Theater button */
692 ideapad_input_report(priv, 64);
695 pr_info("Unknown special button: %lu\n", bit);
705 static int ideapad_backlight_get_brightness(struct backlight_device *blightdev)
707 struct ideapad_private *priv = bl_get_data(blightdev);
713 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now))
718 static int ideapad_backlight_update_status(struct backlight_device *blightdev)
720 struct ideapad_private *priv = bl_get_data(blightdev);
725 if (write_ec_cmd(priv->adev->handle, VPCCMD_W_BL,
726 blightdev->props.brightness))
728 if (write_ec_cmd(priv->adev->handle, VPCCMD_W_BL_POWER,
729 blightdev->props.power == FB_BLANK_POWERDOWN ? 0 : 1))
735 static const struct backlight_ops ideapad_backlight_ops = {
736 .get_brightness = ideapad_backlight_get_brightness,
737 .update_status = ideapad_backlight_update_status,
740 static int ideapad_backlight_init(struct ideapad_private *priv)
742 struct backlight_device *blightdev;
743 struct backlight_properties props;
744 unsigned long max, now, power;
746 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &max))
748 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now))
750 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power))
753 memset(&props, 0, sizeof(struct backlight_properties));
754 props.max_brightness = max;
755 props.type = BACKLIGHT_PLATFORM;
756 blightdev = backlight_device_register("ideapad",
757 &priv->platform_device->dev,
759 &ideapad_backlight_ops,
761 if (IS_ERR(blightdev)) {
762 pr_err("Could not register backlight device\n");
763 return PTR_ERR(blightdev);
766 priv->blightdev = blightdev;
767 blightdev->props.brightness = now;
768 blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
769 backlight_update_status(blightdev);
774 static void ideapad_backlight_exit(struct ideapad_private *priv)
776 backlight_device_unregister(priv->blightdev);
777 priv->blightdev = NULL;
780 static void ideapad_backlight_notify_power(struct ideapad_private *priv)
783 struct backlight_device *blightdev = priv->blightdev;
787 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power))
789 blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
792 static void ideapad_backlight_notify_brightness(struct ideapad_private *priv)
796 /* if we control brightness via acpi video driver */
797 if (priv->blightdev == NULL) {
798 read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now);
802 backlight_force_update(priv->blightdev, BACKLIGHT_UPDATE_HOTKEY);
808 static void ideapad_sync_touchpad_state(struct ideapad_private *priv)
812 /* Without reading from EC touchpad LED doesn't switch state */
813 if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value)) {
814 /* Some IdeaPads don't really turn off touchpad - they only
815 * switch the LED state. We (de)activate KBC AUX port to turn
816 * touchpad off and on. We send KEY_TOUCHPAD_OFF and
817 * KEY_TOUCHPAD_ON to not to get out of sync with LED */
819 i8042_command(¶m, value ? I8042_CMD_AUX_ENABLE :
820 I8042_CMD_AUX_DISABLE);
821 ideapad_input_report(priv, value ? 67 : 66);
825 static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data)
827 struct ideapad_private *priv = data;
828 unsigned long vpc1, vpc2, vpc_bit;
830 if (read_ec_data(handle, VPCCMD_R_VPC1, &vpc1))
832 if (read_ec_data(handle, VPCCMD_R_VPC2, &vpc2))
835 vpc1 = (vpc2 << 8) | vpc1;
836 for (vpc_bit = 0; vpc_bit < 16; vpc_bit++) {
837 if (test_bit(vpc_bit, &vpc1)) {
840 ideapad_sync_rfk_state(priv);
847 ideapad_input_report(priv, vpc_bit);
850 ideapad_sync_touchpad_state(priv);
853 ideapad_backlight_notify_brightness(priv);
856 ideapad_input_novokey(priv);
859 ideapad_backlight_notify_power(priv);
862 ideapad_check_special_buttons(priv);
865 /* Some IdeaPads report event 1 every ~20
866 * seconds while on battery power; some
867 * report this when changing to/from tablet
868 * mode. Squelch this event.
872 pr_info("Unknown event: %lu\n", vpc_bit);
878 #if IS_ENABLED(CONFIG_ACPI_WMI)
879 static void ideapad_wmi_notify(u32 value, void *context)
883 ideapad_input_report(context, value);
886 pr_info("Unknown WMI event %u\n", value);
892 * Some ideapads don't have a hardware rfkill switch, reading VPCCMD_R_RF
893 * always results in 0 on these models, causing ideapad_laptop to wrongly
894 * report all radios as hardware-blocked.
896 static const struct dmi_system_id no_hw_rfkill_list[] = {
898 .ident = "Lenovo G40-30",
900 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
901 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo G40-30"),
905 .ident = "Lenovo G50-30",
907 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
908 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo G50-30"),
912 .ident = "Lenovo V310-14IKB",
914 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
915 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo V310-14IKB"),
919 .ident = "Lenovo V310-14ISK",
921 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
922 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo V310-14ISK"),
926 .ident = "Lenovo V310-15IKB",
928 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
929 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo V310-15IKB"),
933 .ident = "Lenovo V310-15ISK",
935 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
936 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo V310-15ISK"),
940 .ident = "Lenovo V510-15IKB",
942 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
943 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo V510-15IKB"),
947 .ident = "Lenovo ideapad 300-15IBR",
949 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
950 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad 300-15IBR"),
954 .ident = "Lenovo ideapad 300-15IKB",
956 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
957 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad 300-15IKB"),
961 .ident = "Lenovo ideapad 300S-11IBR",
963 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
964 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad 300S-11BR"),
968 .ident = "Lenovo ideapad 310-15ABR",
970 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
971 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad 310-15ABR"),
975 .ident = "Lenovo ideapad 310-15IAP",
977 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
978 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad 310-15IAP"),
982 .ident = "Lenovo ideapad 310-15IKB",
984 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
985 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad 310-15IKB"),
989 .ident = "Lenovo ideapad 310-15ISK",
991 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
992 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad 310-15ISK"),
996 .ident = "Lenovo ideapad Y700-14ISK",
998 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
999 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad Y700-14ISK"),
1003 .ident = "Lenovo ideapad Y700-15ACZ",
1005 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1006 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad Y700-15ACZ"),
1010 .ident = "Lenovo ideapad Y700-15ISK",
1012 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1013 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad Y700-15ISK"),
1017 .ident = "Lenovo ideapad Y700 Touch-15ISK",
1019 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1020 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad Y700 Touch-15ISK"),
1024 .ident = "Lenovo ideapad Y700-17ISK",
1026 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1027 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad Y700-17ISK"),
1031 .ident = "Lenovo Legion Y520-15IKBN",
1033 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1034 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Y520-15IKBN"),
1038 .ident = "Lenovo Legion Y720-15IKBN",
1040 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1041 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Y720-15IKBN"),
1045 .ident = "Lenovo Yoga 2 11 / 13 / Pro",
1047 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1048 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Yoga 2"),
1052 .ident = "Lenovo Yoga 2 11 / 13 / Pro",
1054 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1055 DMI_MATCH(DMI_BOARD_NAME, "Yoga2"),
1059 .ident = "Lenovo Yoga 3 1170 / 1470",
1061 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1062 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Yoga 3"),
1066 .ident = "Lenovo Yoga 3 Pro 1370",
1068 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1069 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo YOGA 3"),
1073 .ident = "Lenovo Yoga 700",
1075 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1076 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo YOGA 700"),
1080 .ident = "Lenovo Yoga 900",
1082 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1083 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo YOGA 900"),
1087 .ident = "Lenovo Yoga 900",
1089 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1090 DMI_MATCH(DMI_BOARD_NAME, "VIUU4"),
1094 .ident = "Lenovo YOGA 910-13IKB",
1096 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1097 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo YOGA 910-13IKB"),
1103 static int ideapad_acpi_add(struct platform_device *pdev)
1107 struct ideapad_private *priv;
1108 struct acpi_device *adev;
1110 ret = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev);
1114 if (read_method_int(adev->handle, "_CFG", &cfg))
1117 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
1121 dev_set_drvdata(&pdev->dev, priv);
1124 priv->platform_device = pdev;
1125 priv->has_hw_rfkill_switch = !dmi_check_system(no_hw_rfkill_list);
1127 ret = ideapad_sysfs_init(priv);
1131 ret = ideapad_debugfs_init(priv);
1133 goto debugfs_failed;
1135 ret = ideapad_input_init(priv);
1140 * On some models without a hw-switch (the yoga 2 13 at least)
1141 * VPCCMD_W_RF must be explicitly set to 1 for the wifi to work.
1143 if (!priv->has_hw_rfkill_switch)
1144 write_ec_cmd(priv->adev->handle, VPCCMD_W_RF, 1);
1146 for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
1147 if (test_bit(ideapad_rfk_data[i].cfgbit, &priv->cfg))
1148 ideapad_register_rfkill(priv, i);
1150 ideapad_sync_rfk_state(priv);
1151 ideapad_sync_touchpad_state(priv);
1153 if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
1154 ret = ideapad_backlight_init(priv);
1155 if (ret && ret != -ENODEV)
1156 goto backlight_failed;
1158 ret = acpi_install_notify_handler(adev->handle,
1159 ACPI_DEVICE_NOTIFY, ideapad_acpi_notify, priv);
1161 goto notification_failed;
1163 #if IS_ENABLED(CONFIG_ACPI_WMI)
1164 for (i = 0; i < ARRAY_SIZE(ideapad_wmi_fnesc_events); i++) {
1165 ret = wmi_install_notify_handler(ideapad_wmi_fnesc_events[i],
1166 ideapad_wmi_notify, priv);
1168 priv->fnesc_guid = ideapad_wmi_fnesc_events[i];
1172 if (ret != AE_OK && ret != AE_NOT_EXIST)
1173 goto notification_failed_wmi;
1177 #if IS_ENABLED(CONFIG_ACPI_WMI)
1178 notification_failed_wmi:
1179 acpi_remove_notify_handler(priv->adev->handle,
1180 ACPI_DEVICE_NOTIFY, ideapad_acpi_notify);
1182 notification_failed:
1183 ideapad_backlight_exit(priv);
1185 for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
1186 ideapad_unregister_rfkill(priv, i);
1187 ideapad_input_exit(priv);
1189 ideapad_debugfs_exit(priv);
1191 ideapad_sysfs_exit(priv);
1195 static int ideapad_acpi_remove(struct platform_device *pdev)
1197 struct ideapad_private *priv = dev_get_drvdata(&pdev->dev);
1200 #if IS_ENABLED(CONFIG_ACPI_WMI)
1201 if (priv->fnesc_guid)
1202 wmi_remove_notify_handler(priv->fnesc_guid);
1204 acpi_remove_notify_handler(priv->adev->handle,
1205 ACPI_DEVICE_NOTIFY, ideapad_acpi_notify);
1206 ideapad_backlight_exit(priv);
1207 for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
1208 ideapad_unregister_rfkill(priv, i);
1209 ideapad_input_exit(priv);
1210 ideapad_debugfs_exit(priv);
1211 ideapad_sysfs_exit(priv);
1212 dev_set_drvdata(&pdev->dev, NULL);
1217 #ifdef CONFIG_PM_SLEEP
1218 static int ideapad_acpi_resume(struct device *device)
1220 struct ideapad_private *priv;
1224 priv = dev_get_drvdata(device);
1226 ideapad_sync_rfk_state(priv);
1227 ideapad_sync_touchpad_state(priv);
1231 static SIMPLE_DEV_PM_OPS(ideapad_pm, NULL, ideapad_acpi_resume);
1233 static const struct acpi_device_id ideapad_device_ids[] = {
1237 MODULE_DEVICE_TABLE(acpi, ideapad_device_ids);
1239 static struct platform_driver ideapad_acpi_driver = {
1240 .probe = ideapad_acpi_add,
1241 .remove = ideapad_acpi_remove,
1243 .name = "ideapad_acpi",
1245 .acpi_match_table = ACPI_PTR(ideapad_device_ids),
1249 module_platform_driver(ideapad_acpi_driver);
1252 MODULE_DESCRIPTION("IdeaPad ACPI Extras");
1253 MODULE_LICENSE("GPL");