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)
68 VPCCMD_R_ODD, /* 0x21 */
73 VPCCMD_R_SPECIAL_BUTTONS = 0x31,
74 VPCCMD_W_BL_POWER = 0x33,
77 struct ideapad_rfk_priv {
79 struct ideapad_private *priv;
82 struct ideapad_private {
83 struct acpi_device *adev;
84 struct rfkill *rfk[IDEAPAD_RFKILL_DEV_NUM];
85 struct ideapad_rfk_priv rfk_priv[IDEAPAD_RFKILL_DEV_NUM];
86 struct platform_device *platform_device;
87 struct input_dev *inputdev;
88 struct backlight_device *blightdev;
91 bool has_hw_rfkill_switch;
94 static bool no_bt_rfkill;
95 module_param(no_bt_rfkill, bool, 0444);
96 MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth.");
101 #define IDEAPAD_EC_TIMEOUT (100) /* in ms */
103 static int read_method_int(acpi_handle handle, const char *method, int *val)
106 unsigned long long result;
108 status = acpi_evaluate_integer(handle, (char *)method, NULL, &result);
109 if (ACPI_FAILURE(status)) {
118 static int method_vpcr(acpi_handle handle, int cmd, int *ret)
121 unsigned long long result;
122 struct acpi_object_list params;
123 union acpi_object in_obj;
126 params.pointer = &in_obj;
127 in_obj.type = ACPI_TYPE_INTEGER;
128 in_obj.integer.value = cmd;
130 status = acpi_evaluate_integer(handle, "VPCR", ¶ms, &result);
132 if (ACPI_FAILURE(status)) {
141 static int method_vpcw(acpi_handle handle, int cmd, int data)
143 struct acpi_object_list params;
144 union acpi_object in_obj[2];
148 params.pointer = in_obj;
149 in_obj[0].type = ACPI_TYPE_INTEGER;
150 in_obj[0].integer.value = cmd;
151 in_obj[1].type = ACPI_TYPE_INTEGER;
152 in_obj[1].integer.value = data;
154 status = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL);
160 static int read_ec_data(acpi_handle handle, int cmd, unsigned long *data)
163 unsigned long int end_jiffies;
165 if (method_vpcw(handle, 1, cmd))
168 for (end_jiffies = jiffies+(HZ)*IDEAPAD_EC_TIMEOUT/1000+1;
169 time_before(jiffies, end_jiffies);) {
171 if (method_vpcr(handle, 1, &val))
174 if (method_vpcr(handle, 0, &val))
180 pr_err("timeout in read_ec_cmd\n");
184 static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data)
187 unsigned long int end_jiffies;
189 if (method_vpcw(handle, 0, data))
191 if (method_vpcw(handle, 1, cmd))
194 for (end_jiffies = jiffies+(HZ)*IDEAPAD_EC_TIMEOUT/1000+1;
195 time_before(jiffies, end_jiffies);) {
197 if (method_vpcr(handle, 1, &val))
202 pr_err("timeout in write_ec_cmd\n");
209 static int debugfs_status_show(struct seq_file *s, void *data)
211 struct ideapad_private *priv = s->private;
217 if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &value))
218 seq_printf(s, "Backlight max:\t%lu\n", value);
219 if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL, &value))
220 seq_printf(s, "Backlight now:\t%lu\n", value);
221 if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &value))
222 seq_printf(s, "BL power value:\t%s\n", value ? "On" : "Off");
223 seq_printf(s, "=====================\n");
225 if (!read_ec_data(priv->adev->handle, VPCCMD_R_RF, &value))
226 seq_printf(s, "Radio status:\t%s(%lu)\n",
227 value ? "On" : "Off", value);
228 if (!read_ec_data(priv->adev->handle, VPCCMD_R_WIFI, &value))
229 seq_printf(s, "Wifi status:\t%s(%lu)\n",
230 value ? "On" : "Off", value);
231 if (!read_ec_data(priv->adev->handle, VPCCMD_R_BT, &value))
232 seq_printf(s, "BT status:\t%s(%lu)\n",
233 value ? "On" : "Off", value);
234 if (!read_ec_data(priv->adev->handle, VPCCMD_R_3G, &value))
235 seq_printf(s, "3G status:\t%s(%lu)\n",
236 value ? "On" : "Off", value);
237 seq_printf(s, "=====================\n");
239 if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value))
240 seq_printf(s, "Touchpad status:%s(%lu)\n",
241 value ? "On" : "Off", value);
242 if (!read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &value))
243 seq_printf(s, "Camera status:\t%s(%lu)\n",
244 value ? "On" : "Off", value);
249 static int debugfs_status_open(struct inode *inode, struct file *file)
251 return single_open(file, debugfs_status_show, inode->i_private);
254 static const struct file_operations debugfs_status_fops = {
255 .owner = THIS_MODULE,
256 .open = debugfs_status_open,
259 .release = single_release,
262 static int debugfs_cfg_show(struct seq_file *s, void *data)
264 struct ideapad_private *priv = s->private;
267 seq_printf(s, "cfg: N/A\n");
269 seq_printf(s, "cfg: 0x%.8lX\n\nCapability: ",
271 if (test_bit(CFG_BT_BIT, &priv->cfg))
272 seq_printf(s, "Bluetooth ");
273 if (test_bit(CFG_3G_BIT, &priv->cfg))
274 seq_printf(s, "3G ");
275 if (test_bit(CFG_WIFI_BIT, &priv->cfg))
276 seq_printf(s, "Wireless ");
277 if (test_bit(CFG_CAMERA_BIT, &priv->cfg))
278 seq_printf(s, "Camera ");
279 seq_printf(s, "\nGraphic: ");
280 switch ((priv->cfg)&0x700) {
282 seq_printf(s, "Intel");
285 seq_printf(s, "ATI");
288 seq_printf(s, "Nvidia");
291 seq_printf(s, "Intel and ATI");
294 seq_printf(s, "Intel and Nvidia");
302 static int debugfs_cfg_open(struct inode *inode, struct file *file)
304 return single_open(file, debugfs_cfg_show, inode->i_private);
307 static const struct file_operations debugfs_cfg_fops = {
308 .owner = THIS_MODULE,
309 .open = debugfs_cfg_open,
312 .release = single_release,
315 static int ideapad_debugfs_init(struct ideapad_private *priv)
319 priv->debug = debugfs_create_dir("ideapad", NULL);
320 if (priv->debug == NULL) {
321 pr_err("failed to create debugfs directory");
325 node = debugfs_create_file("cfg", S_IRUGO, priv->debug, priv,
328 pr_err("failed to create cfg in debugfs");
332 node = debugfs_create_file("status", S_IRUGO, priv->debug, priv,
333 &debugfs_status_fops);
335 pr_err("failed to create status in debugfs");
345 static void ideapad_debugfs_exit(struct ideapad_private *priv)
347 debugfs_remove_recursive(priv->debug);
354 static ssize_t show_ideapad_cam(struct device *dev,
355 struct device_attribute *attr,
358 unsigned long result;
359 struct ideapad_private *priv = dev_get_drvdata(dev);
361 if (read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &result))
362 return sprintf(buf, "-1\n");
363 return sprintf(buf, "%lu\n", result);
366 static ssize_t store_ideapad_cam(struct device *dev,
367 struct device_attribute *attr,
368 const char *buf, size_t count)
371 struct ideapad_private *priv = dev_get_drvdata(dev);
375 if (sscanf(buf, "%i", &state) != 1)
377 ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_CAMERA, state);
383 static DEVICE_ATTR(camera_power, 0644, show_ideapad_cam, store_ideapad_cam);
385 static ssize_t show_ideapad_fan(struct device *dev,
386 struct device_attribute *attr,
389 unsigned long result;
390 struct ideapad_private *priv = dev_get_drvdata(dev);
392 if (read_ec_data(priv->adev->handle, VPCCMD_R_FAN, &result))
393 return sprintf(buf, "-1\n");
394 return sprintf(buf, "%lu\n", result);
397 static ssize_t store_ideapad_fan(struct device *dev,
398 struct device_attribute *attr,
399 const char *buf, size_t count)
402 struct ideapad_private *priv = dev_get_drvdata(dev);
406 if (sscanf(buf, "%i", &state) != 1)
408 if (state < 0 || state > 4 || state == 3)
410 ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_FAN, state);
416 static DEVICE_ATTR(fan_mode, 0644, show_ideapad_fan, store_ideapad_fan);
418 static struct attribute *ideapad_attributes[] = {
419 &dev_attr_camera_power.attr,
420 &dev_attr_fan_mode.attr,
424 static umode_t ideapad_is_visible(struct kobject *kobj,
425 struct attribute *attr,
428 struct device *dev = container_of(kobj, struct device, kobj);
429 struct ideapad_private *priv = dev_get_drvdata(dev);
432 if (attr == &dev_attr_camera_power.attr)
433 supported = test_bit(CFG_CAMERA_BIT, &(priv->cfg));
434 else if (attr == &dev_attr_fan_mode.attr) {
436 supported = !read_ec_data(priv->adev->handle, VPCCMD_R_FAN,
441 return supported ? attr->mode : 0;
444 static const struct attribute_group ideapad_attribute_group = {
445 .is_visible = ideapad_is_visible,
446 .attrs = ideapad_attributes
452 struct ideapad_rfk_data {
459 static const struct ideapad_rfk_data ideapad_rfk_data[] = {
460 { "ideapad_wlan", CFG_WIFI_BIT, VPCCMD_W_WIFI, RFKILL_TYPE_WLAN },
461 { "ideapad_bluetooth", CFG_BT_BIT, VPCCMD_W_BT, RFKILL_TYPE_BLUETOOTH },
462 { "ideapad_3g", CFG_3G_BIT, VPCCMD_W_3G, RFKILL_TYPE_WWAN },
465 static int ideapad_rfk_set(void *data, bool blocked)
467 struct ideapad_rfk_priv *priv = data;
468 int opcode = ideapad_rfk_data[priv->dev].opcode;
470 return write_ec_cmd(priv->priv->adev->handle, opcode, !blocked);
473 static struct rfkill_ops ideapad_rfk_ops = {
474 .set_block = ideapad_rfk_set,
477 static void ideapad_sync_rfk_state(struct ideapad_private *priv)
479 unsigned long hw_blocked = 0;
482 if (priv->has_hw_rfkill_switch) {
483 if (read_ec_data(priv->adev->handle, VPCCMD_R_RF, &hw_blocked))
485 hw_blocked = !hw_blocked;
488 for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
490 rfkill_set_hw_state(priv->rfk[i], hw_blocked);
493 static int ideapad_register_rfkill(struct ideapad_private *priv, int dev)
496 unsigned long sw_blocked;
499 (ideapad_rfk_data[dev].type == RFKILL_TYPE_BLUETOOTH)) {
500 /* Force to enable bluetooth when no_bt_rfkill=1 */
501 write_ec_cmd(priv->adev->handle,
502 ideapad_rfk_data[dev].opcode, 1);
505 priv->rfk_priv[dev].dev = dev;
506 priv->rfk_priv[dev].priv = priv;
508 priv->rfk[dev] = rfkill_alloc(ideapad_rfk_data[dev].name,
509 &priv->platform_device->dev,
510 ideapad_rfk_data[dev].type,
512 &priv->rfk_priv[dev]);
516 if (read_ec_data(priv->adev->handle, ideapad_rfk_data[dev].opcode-1,
518 rfkill_init_sw_state(priv->rfk[dev], 0);
520 sw_blocked = !sw_blocked;
521 rfkill_init_sw_state(priv->rfk[dev], sw_blocked);
524 ret = rfkill_register(priv->rfk[dev]);
526 rfkill_destroy(priv->rfk[dev]);
532 static void ideapad_unregister_rfkill(struct ideapad_private *priv, int dev)
537 rfkill_unregister(priv->rfk[dev]);
538 rfkill_destroy(priv->rfk[dev]);
544 static int ideapad_sysfs_init(struct ideapad_private *priv)
546 return sysfs_create_group(&priv->platform_device->dev.kobj,
547 &ideapad_attribute_group);
550 static void ideapad_sysfs_exit(struct ideapad_private *priv)
552 sysfs_remove_group(&priv->platform_device->dev.kobj,
553 &ideapad_attribute_group);
559 static const struct key_entry ideapad_keymap[] = {
560 { KE_KEY, 6, { KEY_SWITCHVIDEOMODE } },
561 { KE_KEY, 7, { KEY_CAMERA } },
562 { KE_KEY, 11, { KEY_F16 } },
563 { KE_KEY, 13, { KEY_WLAN } },
564 { KE_KEY, 16, { KEY_PROG1 } },
565 { KE_KEY, 17, { KEY_PROG2 } },
566 { KE_KEY, 64, { KEY_PROG3 } },
567 { KE_KEY, 65, { KEY_PROG4 } },
568 { KE_KEY, 66, { KEY_TOUCHPAD_OFF } },
569 { KE_KEY, 67, { KEY_TOUCHPAD_ON } },
573 static int ideapad_input_init(struct ideapad_private *priv)
575 struct input_dev *inputdev;
578 inputdev = input_allocate_device();
582 inputdev->name = "Ideapad extra buttons";
583 inputdev->phys = "ideapad/input0";
584 inputdev->id.bustype = BUS_HOST;
585 inputdev->dev.parent = &priv->platform_device->dev;
587 error = sparse_keymap_setup(inputdev, ideapad_keymap, NULL);
589 pr_err("Unable to setup input device keymap\n");
593 error = input_register_device(inputdev);
595 pr_err("Unable to register input device\n");
596 goto err_free_keymap;
599 priv->inputdev = inputdev;
603 sparse_keymap_free(inputdev);
605 input_free_device(inputdev);
609 static void ideapad_input_exit(struct ideapad_private *priv)
611 sparse_keymap_free(priv->inputdev);
612 input_unregister_device(priv->inputdev);
613 priv->inputdev = NULL;
616 static void ideapad_input_report(struct ideapad_private *priv,
617 unsigned long scancode)
619 sparse_keymap_report_event(priv->inputdev, scancode, 1, true);
622 static void ideapad_input_novokey(struct ideapad_private *priv)
624 unsigned long long_pressed;
626 if (read_ec_data(priv->adev->handle, VPCCMD_R_NOVO, &long_pressed))
629 ideapad_input_report(priv, 17);
631 ideapad_input_report(priv, 16);
634 static void ideapad_check_special_buttons(struct ideapad_private *priv)
636 unsigned long bit, value;
638 read_ec_data(priv->adev->handle, VPCCMD_R_SPECIAL_BUTTONS, &value);
640 for (bit = 0; bit < 16; bit++) {
641 if (test_bit(bit, &value)) {
645 /* Thermal Management button */
646 ideapad_input_report(priv, 65);
649 /* OneKey Theater button */
650 ideapad_input_report(priv, 64);
653 pr_info("Unknown special button: %lu\n", bit);
663 static int ideapad_backlight_get_brightness(struct backlight_device *blightdev)
665 struct ideapad_private *priv = bl_get_data(blightdev);
671 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now))
676 static int ideapad_backlight_update_status(struct backlight_device *blightdev)
678 struct ideapad_private *priv = bl_get_data(blightdev);
683 if (write_ec_cmd(priv->adev->handle, VPCCMD_W_BL,
684 blightdev->props.brightness))
686 if (write_ec_cmd(priv->adev->handle, VPCCMD_W_BL_POWER,
687 blightdev->props.power == FB_BLANK_POWERDOWN ? 0 : 1))
693 static const struct backlight_ops ideapad_backlight_ops = {
694 .get_brightness = ideapad_backlight_get_brightness,
695 .update_status = ideapad_backlight_update_status,
698 static int ideapad_backlight_init(struct ideapad_private *priv)
700 struct backlight_device *blightdev;
701 struct backlight_properties props;
702 unsigned long max, now, power;
704 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &max))
706 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now))
708 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power))
711 memset(&props, 0, sizeof(struct backlight_properties));
712 props.max_brightness = max;
713 props.type = BACKLIGHT_PLATFORM;
714 blightdev = backlight_device_register("ideapad",
715 &priv->platform_device->dev,
717 &ideapad_backlight_ops,
719 if (IS_ERR(blightdev)) {
720 pr_err("Could not register backlight device\n");
721 return PTR_ERR(blightdev);
724 priv->blightdev = blightdev;
725 blightdev->props.brightness = now;
726 blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
727 backlight_update_status(blightdev);
732 static void ideapad_backlight_exit(struct ideapad_private *priv)
734 backlight_device_unregister(priv->blightdev);
735 priv->blightdev = NULL;
738 static void ideapad_backlight_notify_power(struct ideapad_private *priv)
741 struct backlight_device *blightdev = priv->blightdev;
745 if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power))
747 blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
750 static void ideapad_backlight_notify_brightness(struct ideapad_private *priv)
754 /* if we control brightness via acpi video driver */
755 if (priv->blightdev == NULL) {
756 read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now);
760 backlight_force_update(priv->blightdev, BACKLIGHT_UPDATE_HOTKEY);
766 static void ideapad_sync_touchpad_state(struct ideapad_private *priv)
770 /* Without reading from EC touchpad LED doesn't switch state */
771 if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value)) {
772 /* Some IdeaPads don't really turn off touchpad - they only
773 * switch the LED state. We (de)activate KBC AUX port to turn
774 * touchpad off and on. We send KEY_TOUCHPAD_OFF and
775 * KEY_TOUCHPAD_ON to not to get out of sync with LED */
777 i8042_command(¶m, value ? I8042_CMD_AUX_ENABLE :
778 I8042_CMD_AUX_DISABLE);
779 ideapad_input_report(priv, value ? 67 : 66);
783 static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data)
785 struct ideapad_private *priv = data;
786 unsigned long vpc1, vpc2, vpc_bit;
788 if (read_ec_data(handle, VPCCMD_R_VPC1, &vpc1))
790 if (read_ec_data(handle, VPCCMD_R_VPC2, &vpc2))
793 vpc1 = (vpc2 << 8) | vpc1;
794 for (vpc_bit = 0; vpc_bit < 16; vpc_bit++) {
795 if (test_bit(vpc_bit, &vpc1)) {
798 ideapad_sync_rfk_state(priv);
804 ideapad_input_report(priv, vpc_bit);
807 ideapad_sync_touchpad_state(priv);
810 ideapad_backlight_notify_brightness(priv);
813 ideapad_input_novokey(priv);
816 ideapad_backlight_notify_power(priv);
819 ideapad_check_special_buttons(priv);
822 pr_info("Unknown event: %lu\n", vpc_bit);
829 * Some ideapads don't have a hardware rfkill switch, reading VPCCMD_R_RF
830 * always results in 0 on these models, causing ideapad_laptop to wrongly
831 * report all radios as hardware-blocked.
833 static const struct dmi_system_id no_hw_rfkill_list[] = {
835 .ident = "Lenovo G40-30",
837 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
838 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo G40-30"),
842 .ident = "Lenovo G50-30",
844 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
845 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo G50-30"),
849 .ident = "Lenovo Yoga 2 11 / 13 / Pro",
851 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
852 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Yoga 2"),
856 .ident = "Lenovo Yoga 3 14",
858 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
859 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Yoga 3 14"),
863 .ident = "Lenovo Yoga 2 11 / 13 / Pro",
865 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
866 DMI_MATCH(DMI_BOARD_NAME, "Yoga2"),
870 .ident = "Lenovo Yoga 3 Pro 1370",
872 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
873 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo YOGA 3 Pro-1370"),
879 static int ideapad_acpi_add(struct platform_device *pdev)
883 struct ideapad_private *priv;
884 struct acpi_device *adev;
886 ret = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev);
890 if (read_method_int(adev->handle, "_CFG", &cfg))
893 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
897 dev_set_drvdata(&pdev->dev, priv);
900 priv->platform_device = pdev;
901 priv->has_hw_rfkill_switch = !dmi_check_system(no_hw_rfkill_list);
903 ret = ideapad_sysfs_init(priv);
907 ret = ideapad_debugfs_init(priv);
911 ret = ideapad_input_init(priv);
916 * On some models without a hw-switch (the yoga 2 13 at least)
917 * VPCCMD_W_RF must be explicitly set to 1 for the wifi to work.
919 if (!priv->has_hw_rfkill_switch)
920 write_ec_cmd(priv->adev->handle, VPCCMD_W_RF, 1);
922 for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
923 if (test_bit(ideapad_rfk_data[i].cfgbit, &priv->cfg))
924 ideapad_register_rfkill(priv, i);
926 ideapad_sync_rfk_state(priv);
927 ideapad_sync_touchpad_state(priv);
929 if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
930 ret = ideapad_backlight_init(priv);
931 if (ret && ret != -ENODEV)
932 goto backlight_failed;
934 ret = acpi_install_notify_handler(adev->handle,
935 ACPI_DEVICE_NOTIFY, ideapad_acpi_notify, priv);
937 goto notification_failed;
941 ideapad_backlight_exit(priv);
943 for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
944 ideapad_unregister_rfkill(priv, i);
945 ideapad_input_exit(priv);
947 ideapad_debugfs_exit(priv);
949 ideapad_sysfs_exit(priv);
953 static int ideapad_acpi_remove(struct platform_device *pdev)
955 struct ideapad_private *priv = dev_get_drvdata(&pdev->dev);
958 acpi_remove_notify_handler(priv->adev->handle,
959 ACPI_DEVICE_NOTIFY, ideapad_acpi_notify);
960 ideapad_backlight_exit(priv);
961 for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
962 ideapad_unregister_rfkill(priv, i);
963 ideapad_input_exit(priv);
964 ideapad_debugfs_exit(priv);
965 ideapad_sysfs_exit(priv);
966 dev_set_drvdata(&pdev->dev, NULL);
971 #ifdef CONFIG_PM_SLEEP
972 static int ideapad_acpi_resume(struct device *device)
974 struct ideapad_private *priv;
978 priv = dev_get_drvdata(device);
980 ideapad_sync_rfk_state(priv);
981 ideapad_sync_touchpad_state(priv);
985 static SIMPLE_DEV_PM_OPS(ideapad_pm, NULL, ideapad_acpi_resume);
987 static const struct acpi_device_id ideapad_device_ids[] = {
991 MODULE_DEVICE_TABLE(acpi, ideapad_device_ids);
993 static struct platform_driver ideapad_acpi_driver = {
994 .probe = ideapad_acpi_add,
995 .remove = ideapad_acpi_remove,
997 .name = "ideapad_acpi",
999 .acpi_match_table = ACPI_PTR(ideapad_device_ids),
1003 module_platform_driver(ideapad_acpi_driver);
1005 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
1006 MODULE_DESCRIPTION("IdeaPad ACPI Extras");
1007 MODULE_LICENSE("GPL");