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 BM_CONSERVATION_BIT (5)
47 #define CFG_BT_BIT (16)
48 #define CFG_3G_BIT (17)
49 #define CFG_WIFI_BIT (18)
50 #define CFG_CAMERA_BIT (19)
52 #if IS_ENABLED(CONFIG_ACPI_WMI)
53 static const char *const ideapad_wmi_fnesc_events
[] = {
54 "26CAB2E5-5CF1-46AE-AAC3-4A12B6BA50E6", /* Yoga 3 */
55 "56322276-8493-4CE8-A783-98C991274F5E", /* Yoga 700 */
60 BMCMD_CONSERVATION_ON
= 3,
61 BMCMD_CONSERVATION_OFF
= 5,
82 VPCCMD_R_ODD
, /* 0x21 */
87 VPCCMD_R_SPECIAL_BUTTONS
= 0x31,
88 VPCCMD_W_BL_POWER
= 0x33,
91 struct ideapad_rfk_priv
{
93 struct ideapad_private
*priv
;
96 struct ideapad_private
{
97 struct acpi_device
*adev
;
98 struct rfkill
*rfk
[IDEAPAD_RFKILL_DEV_NUM
];
99 struct ideapad_rfk_priv rfk_priv
[IDEAPAD_RFKILL_DEV_NUM
];
100 struct platform_device
*platform_device
;
101 struct input_dev
*inputdev
;
102 struct backlight_device
*blightdev
;
103 struct dentry
*debug
;
105 bool has_hw_rfkill_switch
;
106 const char *fnesc_guid
;
109 static bool no_bt_rfkill
;
110 module_param(no_bt_rfkill
, bool, 0444);
111 MODULE_PARM_DESC(no_bt_rfkill
, "No rfkill for bluetooth.");
116 #define IDEAPAD_EC_TIMEOUT (100) /* in ms */
118 static int read_method_int(acpi_handle handle
, const char *method
, int *val
)
121 unsigned long long result
;
123 status
= acpi_evaluate_integer(handle
, (char *)method
, NULL
, &result
);
124 if (ACPI_FAILURE(status
)) {
133 static int method_gbmd(acpi_handle handle
, unsigned long *ret
)
137 result
= read_method_int(handle
, "GBMD", &val
);
142 static int method_sbmc(acpi_handle handle
, int cmd
)
146 status
= acpi_execute_simple_method(handle
, "SBMC", cmd
);
147 return ACPI_FAILURE(status
) ? -1 : 0;
150 static int method_vpcr(acpi_handle handle
, int cmd
, int *ret
)
153 unsigned long long result
;
154 struct acpi_object_list params
;
155 union acpi_object in_obj
;
158 params
.pointer
= &in_obj
;
159 in_obj
.type
= ACPI_TYPE_INTEGER
;
160 in_obj
.integer
.value
= cmd
;
162 status
= acpi_evaluate_integer(handle
, "VPCR", ¶ms
, &result
);
164 if (ACPI_FAILURE(status
)) {
173 static int method_vpcw(acpi_handle handle
, int cmd
, int data
)
175 struct acpi_object_list params
;
176 union acpi_object in_obj
[2];
180 params
.pointer
= in_obj
;
181 in_obj
[0].type
= ACPI_TYPE_INTEGER
;
182 in_obj
[0].integer
.value
= cmd
;
183 in_obj
[1].type
= ACPI_TYPE_INTEGER
;
184 in_obj
[1].integer
.value
= data
;
186 status
= acpi_evaluate_object(handle
, "VPCW", ¶ms
, NULL
);
192 static int read_ec_data(acpi_handle handle
, int cmd
, unsigned long *data
)
195 unsigned long int end_jiffies
;
197 if (method_vpcw(handle
, 1, cmd
))
200 for (end_jiffies
= jiffies
+(HZ
)*IDEAPAD_EC_TIMEOUT
/1000+1;
201 time_before(jiffies
, end_jiffies
);) {
203 if (method_vpcr(handle
, 1, &val
))
206 if (method_vpcr(handle
, 0, &val
))
212 pr_err("timeout in read_ec_cmd\n");
216 static int write_ec_cmd(acpi_handle handle
, int cmd
, unsigned long data
)
219 unsigned long int end_jiffies
;
221 if (method_vpcw(handle
, 0, data
))
223 if (method_vpcw(handle
, 1, cmd
))
226 for (end_jiffies
= jiffies
+(HZ
)*IDEAPAD_EC_TIMEOUT
/1000+1;
227 time_before(jiffies
, end_jiffies
);) {
229 if (method_vpcr(handle
, 1, &val
))
234 pr_err("timeout in write_ec_cmd\n");
241 static int debugfs_status_show(struct seq_file
*s
, void *data
)
243 struct ideapad_private
*priv
= s
->private;
249 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_BL_MAX
, &value
))
250 seq_printf(s
, "Backlight max:\t%lu\n", value
);
251 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_BL
, &value
))
252 seq_printf(s
, "Backlight now:\t%lu\n", value
);
253 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_BL_POWER
, &value
))
254 seq_printf(s
, "BL power value:\t%s\n", value
? "On" : "Off");
255 seq_printf(s
, "=====================\n");
257 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_RF
, &value
))
258 seq_printf(s
, "Radio status:\t%s(%lu)\n",
259 value
? "On" : "Off", value
);
260 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_WIFI
, &value
))
261 seq_printf(s
, "Wifi status:\t%s(%lu)\n",
262 value
? "On" : "Off", value
);
263 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_BT
, &value
))
264 seq_printf(s
, "BT status:\t%s(%lu)\n",
265 value
? "On" : "Off", value
);
266 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_3G
, &value
))
267 seq_printf(s
, "3G status:\t%s(%lu)\n",
268 value
? "On" : "Off", value
);
269 seq_printf(s
, "=====================\n");
271 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_TOUCHPAD
, &value
))
272 seq_printf(s
, "Touchpad status:%s(%lu)\n",
273 value
? "On" : "Off", value
);
274 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_CAMERA
, &value
))
275 seq_printf(s
, "Camera status:\t%s(%lu)\n",
276 value
? "On" : "Off", value
);
277 seq_puts(s
, "=====================\n");
279 if (!method_gbmd(priv
->adev
->handle
, &value
)) {
280 seq_printf(s
, "Conservation mode:\t%s(%lu)\n",
281 test_bit(BM_CONSERVATION_BIT
, &value
) ? "On" : "Off",
288 static int debugfs_status_open(struct inode
*inode
, struct file
*file
)
290 return single_open(file
, debugfs_status_show
, inode
->i_private
);
293 static const struct file_operations debugfs_status_fops
= {
294 .owner
= THIS_MODULE
,
295 .open
= debugfs_status_open
,
298 .release
= single_release
,
301 static int debugfs_cfg_show(struct seq_file
*s
, void *data
)
303 struct ideapad_private
*priv
= s
->private;
306 seq_printf(s
, "cfg: N/A\n");
308 seq_printf(s
, "cfg: 0x%.8lX\n\nCapability: ",
310 if (test_bit(CFG_BT_BIT
, &priv
->cfg
))
311 seq_printf(s
, "Bluetooth ");
312 if (test_bit(CFG_3G_BIT
, &priv
->cfg
))
313 seq_printf(s
, "3G ");
314 if (test_bit(CFG_WIFI_BIT
, &priv
->cfg
))
315 seq_printf(s
, "Wireless ");
316 if (test_bit(CFG_CAMERA_BIT
, &priv
->cfg
))
317 seq_printf(s
, "Camera ");
318 seq_printf(s
, "\nGraphic: ");
319 switch ((priv
->cfg
)&0x700) {
321 seq_printf(s
, "Intel");
324 seq_printf(s
, "ATI");
327 seq_printf(s
, "Nvidia");
330 seq_printf(s
, "Intel and ATI");
333 seq_printf(s
, "Intel and Nvidia");
341 static int debugfs_cfg_open(struct inode
*inode
, struct file
*file
)
343 return single_open(file
, debugfs_cfg_show
, inode
->i_private
);
346 static const struct file_operations debugfs_cfg_fops
= {
347 .owner
= THIS_MODULE
,
348 .open
= debugfs_cfg_open
,
351 .release
= single_release
,
354 static int ideapad_debugfs_init(struct ideapad_private
*priv
)
358 priv
->debug
= debugfs_create_dir("ideapad", NULL
);
359 if (priv
->debug
== NULL
) {
360 pr_err("failed to create debugfs directory");
364 node
= debugfs_create_file("cfg", S_IRUGO
, priv
->debug
, priv
,
367 pr_err("failed to create cfg in debugfs");
371 node
= debugfs_create_file("status", S_IRUGO
, priv
->debug
, priv
,
372 &debugfs_status_fops
);
374 pr_err("failed to create status in debugfs");
384 static void ideapad_debugfs_exit(struct ideapad_private
*priv
)
386 debugfs_remove_recursive(priv
->debug
);
393 static ssize_t
show_ideapad_cam(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_CAMERA
, &result
))
401 return sprintf(buf
, "-1\n");
402 return sprintf(buf
, "%lu\n", result
);
405 static ssize_t
store_ideapad_cam(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 ret
= write_ec_cmd(priv
->adev
->handle
, VPCCMD_W_CAMERA
, state
);
422 static DEVICE_ATTR(camera_power
, 0644, show_ideapad_cam
, store_ideapad_cam
);
424 static ssize_t
show_ideapad_fan(struct device
*dev
,
425 struct device_attribute
*attr
,
428 unsigned long result
;
429 struct ideapad_private
*priv
= dev_get_drvdata(dev
);
431 if (read_ec_data(priv
->adev
->handle
, VPCCMD_R_FAN
, &result
))
432 return sprintf(buf
, "-1\n");
433 return sprintf(buf
, "%lu\n", result
);
436 static ssize_t
store_ideapad_fan(struct device
*dev
,
437 struct device_attribute
*attr
,
438 const char *buf
, size_t count
)
441 struct ideapad_private
*priv
= dev_get_drvdata(dev
);
445 if (sscanf(buf
, "%i", &state
) != 1)
447 if (state
< 0 || state
> 4 || state
== 3)
449 ret
= write_ec_cmd(priv
->adev
->handle
, VPCCMD_W_FAN
, state
);
455 static DEVICE_ATTR(fan_mode
, 0644, show_ideapad_fan
, store_ideapad_fan
);
457 static ssize_t
touchpad_show(struct device
*dev
,
458 struct device_attribute
*attr
,
461 struct ideapad_private
*priv
= dev_get_drvdata(dev
);
462 unsigned long result
;
464 if (read_ec_data(priv
->adev
->handle
, VPCCMD_R_TOUCHPAD
, &result
))
465 return sprintf(buf
, "-1\n");
466 return sprintf(buf
, "%lu\n", result
);
469 /* Switch to RO for now: It might be revisited in the future */
470 static ssize_t __maybe_unused
touchpad_store(struct device
*dev
,
471 struct device_attribute
*attr
,
472 const char *buf
, size_t count
)
474 struct ideapad_private
*priv
= dev_get_drvdata(dev
);
478 ret
= kstrtobool(buf
, &state
);
482 ret
= write_ec_cmd(priv
->adev
->handle
, VPCCMD_W_TOUCHPAD
, state
);
488 static DEVICE_ATTR_RO(touchpad
);
490 static ssize_t
conservation_mode_show(struct device
*dev
,
491 struct device_attribute
*attr
,
494 struct ideapad_private
*priv
= dev_get_drvdata(dev
);
495 unsigned long result
;
497 if (method_gbmd(priv
->adev
->handle
, &result
))
498 return sprintf(buf
, "-1\n");
499 return sprintf(buf
, "%u\n", test_bit(BM_CONSERVATION_BIT
, &result
));
502 static ssize_t
conservation_mode_store(struct device
*dev
,
503 struct device_attribute
*attr
,
504 const char *buf
, size_t count
)
506 struct ideapad_private
*priv
= dev_get_drvdata(dev
);
510 ret
= kstrtobool(buf
, &state
);
514 ret
= method_sbmc(priv
->adev
->handle
, state
?
515 BMCMD_CONSERVATION_ON
:
516 BMCMD_CONSERVATION_OFF
);
522 static DEVICE_ATTR_RW(conservation_mode
);
524 static struct attribute
*ideapad_attributes
[] = {
525 &dev_attr_camera_power
.attr
,
526 &dev_attr_fan_mode
.attr
,
527 &dev_attr_touchpad
.attr
,
528 &dev_attr_conservation_mode
.attr
,
532 static umode_t
ideapad_is_visible(struct kobject
*kobj
,
533 struct attribute
*attr
,
536 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
537 struct ideapad_private
*priv
= dev_get_drvdata(dev
);
540 if (attr
== &dev_attr_camera_power
.attr
)
541 supported
= test_bit(CFG_CAMERA_BIT
, &(priv
->cfg
));
542 else if (attr
== &dev_attr_fan_mode
.attr
) {
544 supported
= !read_ec_data(priv
->adev
->handle
, VPCCMD_R_FAN
,
546 } else if (attr
== &dev_attr_conservation_mode
.attr
) {
547 supported
= acpi_has_method(priv
->adev
->handle
, "GBMD") &&
548 acpi_has_method(priv
->adev
->handle
, "SBMC");
552 return supported
? attr
->mode
: 0;
555 static const struct attribute_group ideapad_attribute_group
= {
556 .is_visible
= ideapad_is_visible
,
557 .attrs
= ideapad_attributes
563 struct ideapad_rfk_data
{
570 static const struct ideapad_rfk_data ideapad_rfk_data
[] = {
571 { "ideapad_wlan", CFG_WIFI_BIT
, VPCCMD_W_WIFI
, RFKILL_TYPE_WLAN
},
572 { "ideapad_bluetooth", CFG_BT_BIT
, VPCCMD_W_BT
, RFKILL_TYPE_BLUETOOTH
},
573 { "ideapad_3g", CFG_3G_BIT
, VPCCMD_W_3G
, RFKILL_TYPE_WWAN
},
576 static int ideapad_rfk_set(void *data
, bool blocked
)
578 struct ideapad_rfk_priv
*priv
= data
;
579 int opcode
= ideapad_rfk_data
[priv
->dev
].opcode
;
581 return write_ec_cmd(priv
->priv
->adev
->handle
, opcode
, !blocked
);
584 static const struct rfkill_ops ideapad_rfk_ops
= {
585 .set_block
= ideapad_rfk_set
,
588 static void ideapad_sync_rfk_state(struct ideapad_private
*priv
)
590 unsigned long hw_blocked
= 0;
593 if (priv
->has_hw_rfkill_switch
) {
594 if (read_ec_data(priv
->adev
->handle
, VPCCMD_R_RF
, &hw_blocked
))
596 hw_blocked
= !hw_blocked
;
599 for (i
= 0; i
< IDEAPAD_RFKILL_DEV_NUM
; i
++)
601 rfkill_set_hw_state(priv
->rfk
[i
], hw_blocked
);
604 static int ideapad_register_rfkill(struct ideapad_private
*priv
, int dev
)
607 unsigned long sw_blocked
;
610 (ideapad_rfk_data
[dev
].type
== RFKILL_TYPE_BLUETOOTH
)) {
611 /* Force to enable bluetooth when no_bt_rfkill=1 */
612 write_ec_cmd(priv
->adev
->handle
,
613 ideapad_rfk_data
[dev
].opcode
, 1);
616 priv
->rfk_priv
[dev
].dev
= dev
;
617 priv
->rfk_priv
[dev
].priv
= priv
;
619 priv
->rfk
[dev
] = rfkill_alloc(ideapad_rfk_data
[dev
].name
,
620 &priv
->platform_device
->dev
,
621 ideapad_rfk_data
[dev
].type
,
623 &priv
->rfk_priv
[dev
]);
627 if (read_ec_data(priv
->adev
->handle
, ideapad_rfk_data
[dev
].opcode
-1,
629 rfkill_init_sw_state(priv
->rfk
[dev
], 0);
631 sw_blocked
= !sw_blocked
;
632 rfkill_init_sw_state(priv
->rfk
[dev
], sw_blocked
);
635 ret
= rfkill_register(priv
->rfk
[dev
]);
637 rfkill_destroy(priv
->rfk
[dev
]);
643 static void ideapad_unregister_rfkill(struct ideapad_private
*priv
, int dev
)
648 rfkill_unregister(priv
->rfk
[dev
]);
649 rfkill_destroy(priv
->rfk
[dev
]);
655 static int ideapad_sysfs_init(struct ideapad_private
*priv
)
657 return sysfs_create_group(&priv
->platform_device
->dev
.kobj
,
658 &ideapad_attribute_group
);
661 static void ideapad_sysfs_exit(struct ideapad_private
*priv
)
663 sysfs_remove_group(&priv
->platform_device
->dev
.kobj
,
664 &ideapad_attribute_group
);
670 static const struct key_entry ideapad_keymap
[] = {
671 { KE_KEY
, 6, { KEY_SWITCHVIDEOMODE
} },
672 { KE_KEY
, 7, { KEY_CAMERA
} },
673 { KE_KEY
, 8, { KEY_MICMUTE
} },
674 { KE_KEY
, 11, { KEY_F16
} },
675 { KE_KEY
, 13, { KEY_WLAN
} },
676 { KE_KEY
, 16, { KEY_PROG1
} },
677 { KE_KEY
, 17, { KEY_PROG2
} },
678 { KE_KEY
, 64, { KEY_PROG3
} },
679 { KE_KEY
, 65, { KEY_PROG4
} },
680 { KE_KEY
, 66, { KEY_TOUCHPAD_OFF
} },
681 { KE_KEY
, 67, { KEY_TOUCHPAD_ON
} },
682 { KE_KEY
, 128, { KEY_ESC
} },
687 static int ideapad_input_init(struct ideapad_private
*priv
)
689 struct input_dev
*inputdev
;
692 inputdev
= input_allocate_device();
696 inputdev
->name
= "Ideapad extra buttons";
697 inputdev
->phys
= "ideapad/input0";
698 inputdev
->id
.bustype
= BUS_HOST
;
699 inputdev
->dev
.parent
= &priv
->platform_device
->dev
;
701 error
= sparse_keymap_setup(inputdev
, ideapad_keymap
, NULL
);
703 pr_err("Unable to setup input device keymap\n");
707 error
= input_register_device(inputdev
);
709 pr_err("Unable to register input device\n");
713 priv
->inputdev
= inputdev
;
717 input_free_device(inputdev
);
721 static void ideapad_input_exit(struct ideapad_private
*priv
)
723 input_unregister_device(priv
->inputdev
);
724 priv
->inputdev
= NULL
;
727 static void ideapad_input_report(struct ideapad_private
*priv
,
728 unsigned long scancode
)
730 sparse_keymap_report_event(priv
->inputdev
, scancode
, 1, true);
733 static void ideapad_input_novokey(struct ideapad_private
*priv
)
735 unsigned long long_pressed
;
737 if (read_ec_data(priv
->adev
->handle
, VPCCMD_R_NOVO
, &long_pressed
))
740 ideapad_input_report(priv
, 17);
742 ideapad_input_report(priv
, 16);
745 static void ideapad_check_special_buttons(struct ideapad_private
*priv
)
747 unsigned long bit
, value
;
749 read_ec_data(priv
->adev
->handle
, VPCCMD_R_SPECIAL_BUTTONS
, &value
);
751 for (bit
= 0; bit
< 16; bit
++) {
752 if (test_bit(bit
, &value
)) {
756 /* Thermal Management button */
757 ideapad_input_report(priv
, 65);
760 /* OneKey Theater button */
761 ideapad_input_report(priv
, 64);
764 pr_info("Unknown special button: %lu\n", bit
);
774 static int ideapad_backlight_get_brightness(struct backlight_device
*blightdev
)
776 struct ideapad_private
*priv
= bl_get_data(blightdev
);
782 if (read_ec_data(priv
->adev
->handle
, VPCCMD_R_BL
, &now
))
787 static int ideapad_backlight_update_status(struct backlight_device
*blightdev
)
789 struct ideapad_private
*priv
= bl_get_data(blightdev
);
794 if (write_ec_cmd(priv
->adev
->handle
, VPCCMD_W_BL
,
795 blightdev
->props
.brightness
))
797 if (write_ec_cmd(priv
->adev
->handle
, VPCCMD_W_BL_POWER
,
798 blightdev
->props
.power
== FB_BLANK_POWERDOWN
? 0 : 1))
804 static const struct backlight_ops ideapad_backlight_ops
= {
805 .get_brightness
= ideapad_backlight_get_brightness
,
806 .update_status
= ideapad_backlight_update_status
,
809 static int ideapad_backlight_init(struct ideapad_private
*priv
)
811 struct backlight_device
*blightdev
;
812 struct backlight_properties props
;
813 unsigned long max
, now
, power
;
815 if (read_ec_data(priv
->adev
->handle
, VPCCMD_R_BL_MAX
, &max
))
817 if (read_ec_data(priv
->adev
->handle
, VPCCMD_R_BL
, &now
))
819 if (read_ec_data(priv
->adev
->handle
, VPCCMD_R_BL_POWER
, &power
))
822 memset(&props
, 0, sizeof(struct backlight_properties
));
823 props
.max_brightness
= max
;
824 props
.type
= BACKLIGHT_PLATFORM
;
825 blightdev
= backlight_device_register("ideapad",
826 &priv
->platform_device
->dev
,
828 &ideapad_backlight_ops
,
830 if (IS_ERR(blightdev
)) {
831 pr_err("Could not register backlight device\n");
832 return PTR_ERR(blightdev
);
835 priv
->blightdev
= blightdev
;
836 blightdev
->props
.brightness
= now
;
837 blightdev
->props
.power
= power
? FB_BLANK_UNBLANK
: FB_BLANK_POWERDOWN
;
838 backlight_update_status(blightdev
);
843 static void ideapad_backlight_exit(struct ideapad_private
*priv
)
845 backlight_device_unregister(priv
->blightdev
);
846 priv
->blightdev
= NULL
;
849 static void ideapad_backlight_notify_power(struct ideapad_private
*priv
)
852 struct backlight_device
*blightdev
= priv
->blightdev
;
856 if (read_ec_data(priv
->adev
->handle
, VPCCMD_R_BL_POWER
, &power
))
858 blightdev
->props
.power
= power
? FB_BLANK_UNBLANK
: FB_BLANK_POWERDOWN
;
861 static void ideapad_backlight_notify_brightness(struct ideapad_private
*priv
)
865 /* if we control brightness via acpi video driver */
866 if (priv
->blightdev
== NULL
) {
867 read_ec_data(priv
->adev
->handle
, VPCCMD_R_BL
, &now
);
871 backlight_force_update(priv
->blightdev
, BACKLIGHT_UPDATE_HOTKEY
);
877 static void ideapad_sync_touchpad_state(struct ideapad_private
*priv
)
881 /* Without reading from EC touchpad LED doesn't switch state */
882 if (!read_ec_data(priv
->adev
->handle
, VPCCMD_R_TOUCHPAD
, &value
)) {
883 /* Some IdeaPads don't really turn off touchpad - they only
884 * switch the LED state. We (de)activate KBC AUX port to turn
885 * touchpad off and on. We send KEY_TOUCHPAD_OFF and
886 * KEY_TOUCHPAD_ON to not to get out of sync with LED */
888 i8042_command(¶m
, value
? I8042_CMD_AUX_ENABLE
:
889 I8042_CMD_AUX_DISABLE
);
890 ideapad_input_report(priv
, value
? 67 : 66);
894 static void ideapad_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
896 struct ideapad_private
*priv
= data
;
897 unsigned long vpc1
, vpc2
, vpc_bit
;
899 if (read_ec_data(handle
, VPCCMD_R_VPC1
, &vpc1
))
901 if (read_ec_data(handle
, VPCCMD_R_VPC2
, &vpc2
))
904 vpc1
= (vpc2
<< 8) | vpc1
;
905 for (vpc_bit
= 0; vpc_bit
< 16; vpc_bit
++) {
906 if (test_bit(vpc_bit
, &vpc1
)) {
909 ideapad_sync_rfk_state(priv
);
916 ideapad_input_report(priv
, vpc_bit
);
919 ideapad_sync_touchpad_state(priv
);
922 ideapad_backlight_notify_brightness(priv
);
925 ideapad_input_novokey(priv
);
928 ideapad_backlight_notify_power(priv
);
931 ideapad_check_special_buttons(priv
);
934 /* Some IdeaPads report event 1 every ~20
935 * seconds while on battery power; some
936 * report this when changing to/from tablet
937 * mode. Squelch this event.
941 pr_info("Unknown event: %lu\n", vpc_bit
);
947 #if IS_ENABLED(CONFIG_ACPI_WMI)
948 static void ideapad_wmi_notify(u32 value
, void *context
)
952 ideapad_input_report(context
, value
);
955 pr_info("Unknown WMI event %u\n", value
);
961 * Some ideapads don't have a hardware rfkill switch, reading VPCCMD_R_RF
962 * always results in 0 on these models, causing ideapad_laptop to wrongly
963 * report all radios as hardware-blocked.
965 static const struct dmi_system_id no_hw_rfkill_list
[] = {
967 .ident
= "Lenovo G40-30",
969 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
970 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo G40-30"),
974 .ident
= "Lenovo G50-30",
976 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
977 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo G50-30"),
981 .ident
= "Lenovo V310-14IKB",
983 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
984 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo V310-14IKB"),
988 .ident
= "Lenovo V310-14ISK",
990 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
991 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo V310-14ISK"),
995 .ident
= "Lenovo V310-15IKB",
997 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
998 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo V310-15IKB"),
1002 .ident
= "Lenovo V310-15ISK",
1004 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1005 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo V310-15ISK"),
1009 .ident
= "Lenovo V510-15IKB",
1011 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1012 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo V510-15IKB"),
1016 .ident
= "Lenovo ideapad 300-15IBR",
1018 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1019 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo ideapad 300-15IBR"),
1023 .ident
= "Lenovo ideapad 300-15IKB",
1025 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1026 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo ideapad 300-15IKB"),
1030 .ident
= "Lenovo ideapad 300S-11IBR",
1032 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1033 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo ideapad 300S-11BR"),
1037 .ident
= "Lenovo ideapad 310-15ABR",
1039 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1040 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo ideapad 310-15ABR"),
1044 .ident
= "Lenovo ideapad 310-15IAP",
1046 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1047 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo ideapad 310-15IAP"),
1051 .ident
= "Lenovo ideapad 310-15IKB",
1053 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1054 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo ideapad 310-15IKB"),
1058 .ident
= "Lenovo ideapad 310-15ISK",
1060 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1061 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo ideapad 310-15ISK"),
1065 .ident
= "Lenovo ideapad Y700-14ISK",
1067 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1068 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo ideapad Y700-14ISK"),
1072 .ident
= "Lenovo ideapad Y700-15ACZ",
1074 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1075 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo ideapad Y700-15ACZ"),
1079 .ident
= "Lenovo ideapad Y700-15ISK",
1081 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1082 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo ideapad Y700-15ISK"),
1086 .ident
= "Lenovo ideapad Y700 Touch-15ISK",
1088 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1089 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo ideapad Y700 Touch-15ISK"),
1093 .ident
= "Lenovo ideapad Y700-17ISK",
1095 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1096 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo ideapad Y700-17ISK"),
1100 .ident
= "Lenovo Legion Y520-15IKBN",
1102 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1103 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo Y520-15IKBN"),
1107 .ident
= "Lenovo Legion Y720-15IKBN",
1109 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1110 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo Y720-15IKBN"),
1114 .ident
= "Lenovo Yoga 2 11 / 13 / Pro",
1116 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1117 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo Yoga 2"),
1121 .ident
= "Lenovo Yoga 2 11 / 13 / Pro",
1123 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1124 DMI_MATCH(DMI_BOARD_NAME
, "Yoga2"),
1128 .ident
= "Lenovo Yoga 3 1170 / 1470",
1130 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1131 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo Yoga 3"),
1135 .ident
= "Lenovo Yoga 3 Pro 1370",
1137 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1138 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo YOGA 3"),
1142 .ident
= "Lenovo Yoga 700",
1144 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1145 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo YOGA 700"),
1149 .ident
= "Lenovo Yoga 900",
1151 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1152 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo YOGA 900"),
1156 .ident
= "Lenovo Yoga 900",
1158 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1159 DMI_MATCH(DMI_BOARD_NAME
, "VIUU4"),
1163 .ident
= "Lenovo YOGA 910-13IKB",
1165 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
1166 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo YOGA 910-13IKB"),
1172 static int ideapad_acpi_add(struct platform_device
*pdev
)
1176 struct ideapad_private
*priv
;
1177 struct acpi_device
*adev
;
1179 ret
= acpi_bus_get_device(ACPI_HANDLE(&pdev
->dev
), &adev
);
1183 if (read_method_int(adev
->handle
, "_CFG", &cfg
))
1186 priv
= devm_kzalloc(&pdev
->dev
, sizeof(*priv
), GFP_KERNEL
);
1190 dev_set_drvdata(&pdev
->dev
, priv
);
1193 priv
->platform_device
= pdev
;
1194 priv
->has_hw_rfkill_switch
= !dmi_check_system(no_hw_rfkill_list
);
1196 ret
= ideapad_sysfs_init(priv
);
1200 ret
= ideapad_debugfs_init(priv
);
1202 goto debugfs_failed
;
1204 ret
= ideapad_input_init(priv
);
1209 * On some models without a hw-switch (the yoga 2 13 at least)
1210 * VPCCMD_W_RF must be explicitly set to 1 for the wifi to work.
1212 if (!priv
->has_hw_rfkill_switch
)
1213 write_ec_cmd(priv
->adev
->handle
, VPCCMD_W_RF
, 1);
1215 for (i
= 0; i
< IDEAPAD_RFKILL_DEV_NUM
; i
++)
1216 if (test_bit(ideapad_rfk_data
[i
].cfgbit
, &priv
->cfg
))
1217 ideapad_register_rfkill(priv
, i
);
1219 ideapad_sync_rfk_state(priv
);
1220 ideapad_sync_touchpad_state(priv
);
1222 if (acpi_video_get_backlight_type() == acpi_backlight_vendor
) {
1223 ret
= ideapad_backlight_init(priv
);
1224 if (ret
&& ret
!= -ENODEV
)
1225 goto backlight_failed
;
1227 ret
= acpi_install_notify_handler(adev
->handle
,
1228 ACPI_DEVICE_NOTIFY
, ideapad_acpi_notify
, priv
);
1230 goto notification_failed
;
1232 #if IS_ENABLED(CONFIG_ACPI_WMI)
1233 for (i
= 0; i
< ARRAY_SIZE(ideapad_wmi_fnesc_events
); i
++) {
1234 ret
= wmi_install_notify_handler(ideapad_wmi_fnesc_events
[i
],
1235 ideapad_wmi_notify
, priv
);
1237 priv
->fnesc_guid
= ideapad_wmi_fnesc_events
[i
];
1241 if (ret
!= AE_OK
&& ret
!= AE_NOT_EXIST
)
1242 goto notification_failed_wmi
;
1246 #if IS_ENABLED(CONFIG_ACPI_WMI)
1247 notification_failed_wmi
:
1248 acpi_remove_notify_handler(priv
->adev
->handle
,
1249 ACPI_DEVICE_NOTIFY
, ideapad_acpi_notify
);
1251 notification_failed
:
1252 ideapad_backlight_exit(priv
);
1254 for (i
= 0; i
< IDEAPAD_RFKILL_DEV_NUM
; i
++)
1255 ideapad_unregister_rfkill(priv
, i
);
1256 ideapad_input_exit(priv
);
1258 ideapad_debugfs_exit(priv
);
1260 ideapad_sysfs_exit(priv
);
1264 static int ideapad_acpi_remove(struct platform_device
*pdev
)
1266 struct ideapad_private
*priv
= dev_get_drvdata(&pdev
->dev
);
1269 #if IS_ENABLED(CONFIG_ACPI_WMI)
1270 if (priv
->fnesc_guid
)
1271 wmi_remove_notify_handler(priv
->fnesc_guid
);
1273 acpi_remove_notify_handler(priv
->adev
->handle
,
1274 ACPI_DEVICE_NOTIFY
, ideapad_acpi_notify
);
1275 ideapad_backlight_exit(priv
);
1276 for (i
= 0; i
< IDEAPAD_RFKILL_DEV_NUM
; i
++)
1277 ideapad_unregister_rfkill(priv
, i
);
1278 ideapad_input_exit(priv
);
1279 ideapad_debugfs_exit(priv
);
1280 ideapad_sysfs_exit(priv
);
1281 dev_set_drvdata(&pdev
->dev
, NULL
);
1286 #ifdef CONFIG_PM_SLEEP
1287 static int ideapad_acpi_resume(struct device
*device
)
1289 struct ideapad_private
*priv
;
1293 priv
= dev_get_drvdata(device
);
1295 ideapad_sync_rfk_state(priv
);
1296 ideapad_sync_touchpad_state(priv
);
1300 static SIMPLE_DEV_PM_OPS(ideapad_pm
, NULL
, ideapad_acpi_resume
);
1302 static const struct acpi_device_id ideapad_device_ids
[] = {
1306 MODULE_DEVICE_TABLE(acpi
, ideapad_device_ids
);
1308 static struct platform_driver ideapad_acpi_driver
= {
1309 .probe
= ideapad_acpi_add
,
1310 .remove
= ideapad_acpi_remove
,
1312 .name
= "ideapad_acpi",
1314 .acpi_match_table
= ACPI_PTR(ideapad_device_ids
),
1318 module_platform_driver(ideapad_acpi_driver
);
1320 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
1321 MODULE_DESCRIPTION("IdeaPad ACPI Extras");
1322 MODULE_LICENSE("GPL");