2 * ideapad-laptop.c - Lenovo IdeaPad ACPI Extras
4 * Copyright © 2010 Intel Corporation
5 * Copyright © 2010 David Woodhouse <dwmw2@infradead.org>
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 ideapad_wmi_fnesc_event
[] = "26CAB2E5-5CF1-46AE-AAC3-4A12B6BA50E6";
72 VPCCMD_R_ODD
, /* 0x21 */
77 VPCCMD_R_SPECIAL_BUTTONS
= 0x31,
78 VPCCMD_W_BL_POWER
= 0x33,
81 struct ideapad_rfk_priv
{
83 struct ideapad_private
*priv
;
86 struct ideapad_private
{
87 struct acpi_device
*adev
;
88 struct rfkill
*rfk
[IDEAPAD_RFKILL_DEV_NUM
];
89 struct ideapad_rfk_priv rfk_priv
[IDEAPAD_RFKILL_DEV_NUM
];
90 struct platform_device
*platform_device
;
91 struct input_dev
*inputdev
;
92 struct backlight_device
*blightdev
;
95 bool has_hw_rfkill_switch
;
98 static bool no_bt_rfkill
;
99 module_param(no_bt_rfkill
, bool, 0444);
100 MODULE_PARM_DESC(no_bt_rfkill
, "No rfkill for bluetooth.");
105 #define IDEAPAD_EC_TIMEOUT (100) /* in ms */
107 static int read_method_int(acpi_handle handle
, const char *method
, int *val
)
110 unsigned long long result
;
112 status
= acpi_evaluate_integer(handle
, (char *)method
, NULL
, &result
);
113 if (ACPI_FAILURE(status
)) {
122 static int method_vpcr(acpi_handle handle
, int cmd
, int *ret
)
125 unsigned long long result
;
126 struct acpi_object_list params
;
127 union acpi_object in_obj
;
130 params
.pointer
= &in_obj
;
131 in_obj
.type
= ACPI_TYPE_INTEGER
;
132 in_obj
.integer
.value
= cmd
;
134 status
= acpi_evaluate_integer(handle
, "VPCR", ¶ms
, &result
);
136 if (ACPI_FAILURE(status
)) {
145 static int method_vpcw(acpi_handle handle
, int cmd
, int data
)
147 struct acpi_object_list params
;
148 union acpi_object in_obj
[2];
152 params
.pointer
= in_obj
;
153 in_obj
[0].type
= ACPI_TYPE_INTEGER
;
154 in_obj
[0].integer
.value
= cmd
;
155 in_obj
[1].type
= ACPI_TYPE_INTEGER
;
156 in_obj
[1].integer
.value
= data
;
158 status
= acpi_evaluate_object(handle
, "VPCW", ¶ms
, NULL
);
164 static int read_ec_data(acpi_handle handle
, int cmd
, unsigned long *data
)
167 unsigned long int end_jiffies
;
169 if (method_vpcw(handle
, 1, cmd
))
172 for (end_jiffies
= jiffies
+(HZ
)*IDEAPAD_EC_TIMEOUT
/1000+1;
173 time_before(jiffies
, end_jiffies
);) {
175 if (method_vpcr(handle
, 1, &val
))
178 if (method_vpcr(handle
, 0, &val
))
184 pr_err("timeout in read_ec_cmd\n");
188 static int write_ec_cmd(acpi_handle handle
, int cmd
, unsigned long data
)
191 unsigned long int end_jiffies
;
193 if (method_vpcw(handle
, 0, data
))
195 if (method_vpcw(handle
, 1, cmd
))
198 for (end_jiffies
= jiffies
+(HZ
)*IDEAPAD_EC_TIMEOUT
/1000+1;
199 time_before(jiffies
, end_jiffies
);) {
201 if (method_vpcr(handle
, 1, &val
))
206 pr_err("timeout in write_ec_cmd\n");
213 static int debugfs_status_show(struct seq_file
*s
, void *data
)
215 struct ideapad_private
*priv
= s
->private;
221 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_BL_MAX
, &value
))
222 seq_printf(s
, "Backlight max:\t%lu\n", value
);
223 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_BL
, &value
))
224 seq_printf(s
, "Backlight now:\t%lu\n", value
);
225 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_BL_POWER
, &value
))
226 seq_printf(s
, "BL power value:\t%s\n", value
? "On" : "Off");
227 seq_printf(s
, "=====================\n");
229 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_RF
, &value
))
230 seq_printf(s
, "Radio status:\t%s(%lu)\n",
231 value
? "On" : "Off", value
);
232 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_WIFI
, &value
))
233 seq_printf(s
, "Wifi status:\t%s(%lu)\n",
234 value
? "On" : "Off", value
);
235 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_BT
, &value
))
236 seq_printf(s
, "BT status:\t%s(%lu)\n",
237 value
? "On" : "Off", value
);
238 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_3G
, &value
))
239 seq_printf(s
, "3G status:\t%s(%lu)\n",
240 value
? "On" : "Off", value
);
241 seq_printf(s
, "=====================\n");
243 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_TOUCHPAD
, &value
))
244 seq_printf(s
, "Touchpad status:%s(%lu)\n",
245 value
? "On" : "Off", value
);
246 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_CAMERA
, &value
))
247 seq_printf(s
, "Camera status:\t%s(%lu)\n",
248 value
? "On" : "Off", value
);
253 static int debugfs_status_open(struct inode
*inode
, struct file
*file
)
255 return single_open(file
, debugfs_status_show
, inode
->i_private
);
258 static const struct file_operations debugfs_status_fops
= {
259 .owner
= THIS_MODULE
,
260 .open
= debugfs_status_open
,
263 .release
= single_release
,
266 static int debugfs_cfg_show(struct seq_file
*s
, void *data
)
268 struct ideapad_private
*priv
= s
->private;
271 seq_printf(s
, "cfg: N/A\n");
273 seq_printf(s
, "cfg: 0x%.8lX\n\nCapability: ",
275 if (test_bit(CFG_BT_BIT
, &priv
->cfg
))
276 seq_printf(s
, "Bluetooth ");
277 if (test_bit(CFG_3G_BIT
, &priv
->cfg
))
278 seq_printf(s
, "3G ");
279 if (test_bit(CFG_WIFI_BIT
, &priv
->cfg
))
280 seq_printf(s
, "Wireless ");
281 if (test_bit(CFG_CAMERA_BIT
, &priv
->cfg
))
282 seq_printf(s
, "Camera ");
283 seq_printf(s
, "\nGraphic: ");
284 switch ((priv
->cfg
)&0x700) {
286 seq_printf(s
, "Intel");
289 seq_printf(s
, "ATI");
292 seq_printf(s
, "Nvidia");
295 seq_printf(s
, "Intel and ATI");
298 seq_printf(s
, "Intel and Nvidia");
306 static int debugfs_cfg_open(struct inode
*inode
, struct file
*file
)
308 return single_open(file
, debugfs_cfg_show
, inode
->i_private
);
311 static const struct file_operations debugfs_cfg_fops
= {
312 .owner
= THIS_MODULE
,
313 .open
= debugfs_cfg_open
,
316 .release
= single_release
,
319 static int ideapad_debugfs_init(struct ideapad_private
*priv
)
323 priv
->debug
= debugfs_create_dir("ideapad", NULL
);
324 if (priv
->debug
== NULL
) {
325 pr_err("failed to create debugfs directory");
329 node
= debugfs_create_file("cfg", S_IRUGO
, priv
->debug
, priv
,
332 pr_err("failed to create cfg in debugfs");
336 node
= debugfs_create_file("status", S_IRUGO
, priv
->debug
, priv
,
337 &debugfs_status_fops
);
339 pr_err("failed to create status in debugfs");
349 static void ideapad_debugfs_exit(struct ideapad_private
*priv
)
351 debugfs_remove_recursive(priv
->debug
);
358 static ssize_t
show_ideapad_cam(struct device
*dev
,
359 struct device_attribute
*attr
,
362 unsigned long result
;
363 struct ideapad_private
*priv
= dev_get_drvdata(dev
);
365 if (read_ec_data(priv
->adev
->handle
, VPCCMD_R_CAMERA
, &result
))
366 return sprintf(buf
, "-1\n");
367 return sprintf(buf
, "%lu\n", result
);
370 static ssize_t
store_ideapad_cam(struct device
*dev
,
371 struct device_attribute
*attr
,
372 const char *buf
, size_t count
)
375 struct ideapad_private
*priv
= dev_get_drvdata(dev
);
379 if (sscanf(buf
, "%i", &state
) != 1)
381 ret
= write_ec_cmd(priv
->adev
->handle
, VPCCMD_W_CAMERA
, state
);
387 static DEVICE_ATTR(camera_power
, 0644, show_ideapad_cam
, store_ideapad_cam
);
389 static ssize_t
show_ideapad_fan(struct device
*dev
,
390 struct device_attribute
*attr
,
393 unsigned long result
;
394 struct ideapad_private
*priv
= dev_get_drvdata(dev
);
396 if (read_ec_data(priv
->adev
->handle
, VPCCMD_R_FAN
, &result
))
397 return sprintf(buf
, "-1\n");
398 return sprintf(buf
, "%lu\n", result
);
401 static ssize_t
store_ideapad_fan(struct device
*dev
,
402 struct device_attribute
*attr
,
403 const char *buf
, size_t count
)
406 struct ideapad_private
*priv
= dev_get_drvdata(dev
);
410 if (sscanf(buf
, "%i", &state
) != 1)
412 if (state
< 0 || state
> 4 || state
== 3)
414 ret
= write_ec_cmd(priv
->adev
->handle
, VPCCMD_W_FAN
, state
);
420 static DEVICE_ATTR(fan_mode
, 0644, show_ideapad_fan
, store_ideapad_fan
);
422 static struct attribute
*ideapad_attributes
[] = {
423 &dev_attr_camera_power
.attr
,
424 &dev_attr_fan_mode
.attr
,
428 static umode_t
ideapad_is_visible(struct kobject
*kobj
,
429 struct attribute
*attr
,
432 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
433 struct ideapad_private
*priv
= dev_get_drvdata(dev
);
436 if (attr
== &dev_attr_camera_power
.attr
)
437 supported
= test_bit(CFG_CAMERA_BIT
, &(priv
->cfg
));
438 else if (attr
== &dev_attr_fan_mode
.attr
) {
440 supported
= !read_ec_data(priv
->adev
->handle
, VPCCMD_R_FAN
,
445 return supported
? attr
->mode
: 0;
448 static const struct attribute_group ideapad_attribute_group
= {
449 .is_visible
= ideapad_is_visible
,
450 .attrs
= ideapad_attributes
456 struct ideapad_rfk_data
{
463 static const struct ideapad_rfk_data ideapad_rfk_data
[] = {
464 { "ideapad_wlan", CFG_WIFI_BIT
, VPCCMD_W_WIFI
, RFKILL_TYPE_WLAN
},
465 { "ideapad_bluetooth", CFG_BT_BIT
, VPCCMD_W_BT
, RFKILL_TYPE_BLUETOOTH
},
466 { "ideapad_3g", CFG_3G_BIT
, VPCCMD_W_3G
, RFKILL_TYPE_WWAN
},
469 static int ideapad_rfk_set(void *data
, bool blocked
)
471 struct ideapad_rfk_priv
*priv
= data
;
472 int opcode
= ideapad_rfk_data
[priv
->dev
].opcode
;
474 return write_ec_cmd(priv
->priv
->adev
->handle
, opcode
, !blocked
);
477 static struct rfkill_ops ideapad_rfk_ops
= {
478 .set_block
= ideapad_rfk_set
,
481 static void ideapad_sync_rfk_state(struct ideapad_private
*priv
)
483 unsigned long hw_blocked
= 0;
486 if (priv
->has_hw_rfkill_switch
) {
487 if (read_ec_data(priv
->adev
->handle
, VPCCMD_R_RF
, &hw_blocked
))
489 hw_blocked
= !hw_blocked
;
492 for (i
= 0; i
< IDEAPAD_RFKILL_DEV_NUM
; i
++)
494 rfkill_set_hw_state(priv
->rfk
[i
], hw_blocked
);
497 static int ideapad_register_rfkill(struct ideapad_private
*priv
, int dev
)
500 unsigned long sw_blocked
;
503 (ideapad_rfk_data
[dev
].type
== RFKILL_TYPE_BLUETOOTH
)) {
504 /* Force to enable bluetooth when no_bt_rfkill=1 */
505 write_ec_cmd(priv
->adev
->handle
,
506 ideapad_rfk_data
[dev
].opcode
, 1);
509 priv
->rfk_priv
[dev
].dev
= dev
;
510 priv
->rfk_priv
[dev
].priv
= priv
;
512 priv
->rfk
[dev
] = rfkill_alloc(ideapad_rfk_data
[dev
].name
,
513 &priv
->platform_device
->dev
,
514 ideapad_rfk_data
[dev
].type
,
516 &priv
->rfk_priv
[dev
]);
520 if (read_ec_data(priv
->adev
->handle
, ideapad_rfk_data
[dev
].opcode
-1,
522 rfkill_init_sw_state(priv
->rfk
[dev
], 0);
524 sw_blocked
= !sw_blocked
;
525 rfkill_init_sw_state(priv
->rfk
[dev
], sw_blocked
);
528 ret
= rfkill_register(priv
->rfk
[dev
]);
530 rfkill_destroy(priv
->rfk
[dev
]);
536 static void ideapad_unregister_rfkill(struct ideapad_private
*priv
, int dev
)
541 rfkill_unregister(priv
->rfk
[dev
]);
542 rfkill_destroy(priv
->rfk
[dev
]);
548 static int ideapad_sysfs_init(struct ideapad_private
*priv
)
550 return sysfs_create_group(&priv
->platform_device
->dev
.kobj
,
551 &ideapad_attribute_group
);
554 static void ideapad_sysfs_exit(struct ideapad_private
*priv
)
556 sysfs_remove_group(&priv
->platform_device
->dev
.kobj
,
557 &ideapad_attribute_group
);
563 static const struct key_entry ideapad_keymap
[] = {
564 { KE_KEY
, 6, { KEY_SWITCHVIDEOMODE
} },
565 { KE_KEY
, 7, { KEY_CAMERA
} },
566 { KE_KEY
, 11, { KEY_F16
} },
567 { KE_KEY
, 13, { KEY_WLAN
} },
568 { KE_KEY
, 16, { KEY_PROG1
} },
569 { KE_KEY
, 17, { KEY_PROG2
} },
570 { KE_KEY
, 64, { KEY_PROG3
} },
571 { KE_KEY
, 65, { KEY_PROG4
} },
572 { KE_KEY
, 66, { KEY_TOUCHPAD_OFF
} },
573 { KE_KEY
, 67, { KEY_TOUCHPAD_ON
} },
574 { KE_KEY
, 128, { KEY_ESC
} },
579 static int ideapad_input_init(struct ideapad_private
*priv
)
581 struct input_dev
*inputdev
;
584 inputdev
= input_allocate_device();
588 inputdev
->name
= "Ideapad extra buttons";
589 inputdev
->phys
= "ideapad/input0";
590 inputdev
->id
.bustype
= BUS_HOST
;
591 inputdev
->dev
.parent
= &priv
->platform_device
->dev
;
593 error
= sparse_keymap_setup(inputdev
, ideapad_keymap
, NULL
);
595 pr_err("Unable to setup input device keymap\n");
599 error
= input_register_device(inputdev
);
601 pr_err("Unable to register input device\n");
602 goto err_free_keymap
;
605 priv
->inputdev
= inputdev
;
609 sparse_keymap_free(inputdev
);
611 input_free_device(inputdev
);
615 static void ideapad_input_exit(struct ideapad_private
*priv
)
617 sparse_keymap_free(priv
->inputdev
);
618 input_unregister_device(priv
->inputdev
);
619 priv
->inputdev
= NULL
;
622 static void ideapad_input_report(struct ideapad_private
*priv
,
623 unsigned long scancode
)
625 sparse_keymap_report_event(priv
->inputdev
, scancode
, 1, true);
628 static void ideapad_input_novokey(struct ideapad_private
*priv
)
630 unsigned long long_pressed
;
632 if (read_ec_data(priv
->adev
->handle
, VPCCMD_R_NOVO
, &long_pressed
))
635 ideapad_input_report(priv
, 17);
637 ideapad_input_report(priv
, 16);
640 static void ideapad_check_special_buttons(struct ideapad_private
*priv
)
642 unsigned long bit
, value
;
644 read_ec_data(priv
->adev
->handle
, VPCCMD_R_SPECIAL_BUTTONS
, &value
);
646 for (bit
= 0; bit
< 16; bit
++) {
647 if (test_bit(bit
, &value
)) {
651 /* Thermal Management button */
652 ideapad_input_report(priv
, 65);
655 /* OneKey Theater button */
656 ideapad_input_report(priv
, 64);
659 pr_info("Unknown special button: %lu\n", bit
);
669 static int ideapad_backlight_get_brightness(struct backlight_device
*blightdev
)
671 struct ideapad_private
*priv
= bl_get_data(blightdev
);
677 if (read_ec_data(priv
->adev
->handle
, VPCCMD_R_BL
, &now
))
682 static int ideapad_backlight_update_status(struct backlight_device
*blightdev
)
684 struct ideapad_private
*priv
= bl_get_data(blightdev
);
689 if (write_ec_cmd(priv
->adev
->handle
, VPCCMD_W_BL
,
690 blightdev
->props
.brightness
))
692 if (write_ec_cmd(priv
->adev
->handle
, VPCCMD_W_BL_POWER
,
693 blightdev
->props
.power
== FB_BLANK_POWERDOWN
? 0 : 1))
699 static const struct backlight_ops ideapad_backlight_ops
= {
700 .get_brightness
= ideapad_backlight_get_brightness
,
701 .update_status
= ideapad_backlight_update_status
,
704 static int ideapad_backlight_init(struct ideapad_private
*priv
)
706 struct backlight_device
*blightdev
;
707 struct backlight_properties props
;
708 unsigned long max
, now
, power
;
710 if (read_ec_data(priv
->adev
->handle
, VPCCMD_R_BL_MAX
, &max
))
712 if (read_ec_data(priv
->adev
->handle
, VPCCMD_R_BL
, &now
))
714 if (read_ec_data(priv
->adev
->handle
, VPCCMD_R_BL_POWER
, &power
))
717 memset(&props
, 0, sizeof(struct backlight_properties
));
718 props
.max_brightness
= max
;
719 props
.type
= BACKLIGHT_PLATFORM
;
720 blightdev
= backlight_device_register("ideapad",
721 &priv
->platform_device
->dev
,
723 &ideapad_backlight_ops
,
725 if (IS_ERR(blightdev
)) {
726 pr_err("Could not register backlight device\n");
727 return PTR_ERR(blightdev
);
730 priv
->blightdev
= blightdev
;
731 blightdev
->props
.brightness
= now
;
732 blightdev
->props
.power
= power
? FB_BLANK_UNBLANK
: FB_BLANK_POWERDOWN
;
733 backlight_update_status(blightdev
);
738 static void ideapad_backlight_exit(struct ideapad_private
*priv
)
740 backlight_device_unregister(priv
->blightdev
);
741 priv
->blightdev
= NULL
;
744 static void ideapad_backlight_notify_power(struct ideapad_private
*priv
)
747 struct backlight_device
*blightdev
= priv
->blightdev
;
751 if (read_ec_data(priv
->adev
->handle
, VPCCMD_R_BL_POWER
, &power
))
753 blightdev
->props
.power
= power
? FB_BLANK_UNBLANK
: FB_BLANK_POWERDOWN
;
756 static void ideapad_backlight_notify_brightness(struct ideapad_private
*priv
)
760 /* if we control brightness via acpi video driver */
761 if (priv
->blightdev
== NULL
) {
762 read_ec_data(priv
->adev
->handle
, VPCCMD_R_BL
, &now
);
766 backlight_force_update(priv
->blightdev
, BACKLIGHT_UPDATE_HOTKEY
);
772 static void ideapad_sync_touchpad_state(struct ideapad_private
*priv
)
776 /* Without reading from EC touchpad LED doesn't switch state */
777 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_TOUCHPAD
, &value
)) {
778 /* Some IdeaPads don't really turn off touchpad - they only
779 * switch the LED state. We (de)activate KBC AUX port to turn
780 * touchpad off and on. We send KEY_TOUCHPAD_OFF and
781 * KEY_TOUCHPAD_ON to not to get out of sync with LED */
783 i8042_command(¶m
, value
? I8042_CMD_AUX_ENABLE
:
784 I8042_CMD_AUX_DISABLE
);
785 ideapad_input_report(priv
, value
? 67 : 66);
789 static void ideapad_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
791 struct ideapad_private
*priv
= data
;
792 unsigned long vpc1
, vpc2
, vpc_bit
;
794 if (read_ec_data(handle
, VPCCMD_R_VPC1
, &vpc1
))
796 if (read_ec_data(handle
, VPCCMD_R_VPC2
, &vpc2
))
799 vpc1
= (vpc2
<< 8) | vpc1
;
800 for (vpc_bit
= 0; vpc_bit
< 16; vpc_bit
++) {
801 if (test_bit(vpc_bit
, &vpc1
)) {
804 ideapad_sync_rfk_state(priv
);
811 ideapad_input_report(priv
, vpc_bit
);
814 ideapad_sync_touchpad_state(priv
);
817 ideapad_backlight_notify_brightness(priv
);
820 ideapad_input_novokey(priv
);
823 ideapad_backlight_notify_power(priv
);
826 ideapad_check_special_buttons(priv
);
829 pr_info("Unknown event: %lu\n", vpc_bit
);
835 #if IS_ENABLED(CONFIG_ACPI_WMI)
836 static void ideapad_wmi_notify(u32 value
, void *context
)
840 ideapad_input_report(context
, value
);
843 pr_info("Unknown WMI event %u\n", value
);
849 * Some ideapads don't have a hardware rfkill switch, reading VPCCMD_R_RF
850 * always results in 0 on these models, causing ideapad_laptop to wrongly
851 * report all radios as hardware-blocked.
853 static const struct dmi_system_id no_hw_rfkill_list
[] = {
855 .ident
= "Lenovo G40-30",
857 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
858 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo G40-30"),
862 .ident
= "Lenovo G50-30",
864 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
865 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo G50-30"),
869 .ident
= "Lenovo ideapad Y700-15ISK",
871 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
872 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo ideapad Y700-15ISK"),
876 .ident
= "Lenovo ideapad Y700 Touch-15ISK",
878 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
879 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo ideapad Y700 Touch-15ISK"),
883 .ident
= "Lenovo ideapad Y700-17ISK",
885 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
886 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo ideapad Y700-17ISK"),
890 .ident
= "Lenovo Yoga 2 11 / 13 / Pro",
892 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
893 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo Yoga 2"),
897 .ident
= "Lenovo Yoga 2 11 / 13 / Pro",
899 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
900 DMI_MATCH(DMI_BOARD_NAME
, "Yoga2"),
904 .ident
= "Lenovo Yoga 3 1170 / 1470",
906 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
907 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo Yoga 3"),
911 .ident
= "Lenovo Yoga 3 Pro 1370",
913 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
914 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo YOGA 3"),
918 .ident
= "Lenovo Yoga 700",
920 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
921 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo YOGA 700"),
925 .ident
= "Lenovo Yoga 900",
927 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
928 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo YOGA 900"),
934 static int ideapad_acpi_add(struct platform_device
*pdev
)
938 struct ideapad_private
*priv
;
939 struct acpi_device
*adev
;
941 ret
= acpi_bus_get_device(ACPI_HANDLE(&pdev
->dev
), &adev
);
945 if (read_method_int(adev
->handle
, "_CFG", &cfg
))
948 priv
= devm_kzalloc(&pdev
->dev
, sizeof(*priv
), GFP_KERNEL
);
952 dev_set_drvdata(&pdev
->dev
, priv
);
955 priv
->platform_device
= pdev
;
956 priv
->has_hw_rfkill_switch
= !dmi_check_system(no_hw_rfkill_list
);
958 ret
= ideapad_sysfs_init(priv
);
962 ret
= ideapad_debugfs_init(priv
);
966 ret
= ideapad_input_init(priv
);
971 * On some models without a hw-switch (the yoga 2 13 at least)
972 * VPCCMD_W_RF must be explicitly set to 1 for the wifi to work.
974 if (!priv
->has_hw_rfkill_switch
)
975 write_ec_cmd(priv
->adev
->handle
, VPCCMD_W_RF
, 1);
977 for (i
= 0; i
< IDEAPAD_RFKILL_DEV_NUM
; i
++)
978 if (test_bit(ideapad_rfk_data
[i
].cfgbit
, &priv
->cfg
))
979 ideapad_register_rfkill(priv
, i
);
981 ideapad_sync_rfk_state(priv
);
982 ideapad_sync_touchpad_state(priv
);
984 if (acpi_video_get_backlight_type() == acpi_backlight_vendor
) {
985 ret
= ideapad_backlight_init(priv
);
986 if (ret
&& ret
!= -ENODEV
)
987 goto backlight_failed
;
989 ret
= acpi_install_notify_handler(adev
->handle
,
990 ACPI_DEVICE_NOTIFY
, ideapad_acpi_notify
, priv
);
992 goto notification_failed
;
993 #if IS_ENABLED(CONFIG_ACPI_WMI)
994 ret
= wmi_install_notify_handler(ideapad_wmi_fnesc_event
, ideapad_wmi_notify
, priv
);
995 if (ret
!= AE_OK
&& ret
!= AE_NOT_EXIST
)
996 goto notification_failed_wmi
;
1000 #if IS_ENABLED(CONFIG_ACPI_WMI)
1001 notification_failed_wmi
:
1002 acpi_remove_notify_handler(priv
->adev
->handle
,
1003 ACPI_DEVICE_NOTIFY
, ideapad_acpi_notify
);
1005 notification_failed
:
1006 ideapad_backlight_exit(priv
);
1008 for (i
= 0; i
< IDEAPAD_RFKILL_DEV_NUM
; i
++)
1009 ideapad_unregister_rfkill(priv
, i
);
1010 ideapad_input_exit(priv
);
1012 ideapad_debugfs_exit(priv
);
1014 ideapad_sysfs_exit(priv
);
1018 static int ideapad_acpi_remove(struct platform_device
*pdev
)
1020 struct ideapad_private
*priv
= dev_get_drvdata(&pdev
->dev
);
1023 #if IS_ENABLED(CONFIG_ACPI_WMI)
1024 wmi_remove_notify_handler(ideapad_wmi_fnesc_event
);
1026 acpi_remove_notify_handler(priv
->adev
->handle
,
1027 ACPI_DEVICE_NOTIFY
, ideapad_acpi_notify
);
1028 ideapad_backlight_exit(priv
);
1029 for (i
= 0; i
< IDEAPAD_RFKILL_DEV_NUM
; i
++)
1030 ideapad_unregister_rfkill(priv
, i
);
1031 ideapad_input_exit(priv
);
1032 ideapad_debugfs_exit(priv
);
1033 ideapad_sysfs_exit(priv
);
1034 dev_set_drvdata(&pdev
->dev
, NULL
);
1039 #ifdef CONFIG_PM_SLEEP
1040 static int ideapad_acpi_resume(struct device
*device
)
1042 struct ideapad_private
*priv
;
1046 priv
= dev_get_drvdata(device
);
1048 ideapad_sync_rfk_state(priv
);
1049 ideapad_sync_touchpad_state(priv
);
1053 static SIMPLE_DEV_PM_OPS(ideapad_pm
, NULL
, ideapad_acpi_resume
);
1055 static const struct acpi_device_id ideapad_device_ids
[] = {
1059 MODULE_DEVICE_TABLE(acpi
, ideapad_device_ids
);
1061 static struct platform_driver ideapad_acpi_driver
= {
1062 .probe
= ideapad_acpi_add
,
1063 .remove
= ideapad_acpi_remove
,
1065 .name
= "ideapad_acpi",
1067 .acpi_match_table
= ACPI_PTR(ideapad_device_ids
),
1071 module_platform_driver(ideapad_acpi_driver
);
1073 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
1074 MODULE_DESCRIPTION("IdeaPad ACPI Extras");
1075 MODULE_LICENSE("GPL");