Merge branch 'bind_unbind' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[GitHub/LineageOS/android_kernel_motorola_exynos9610.git] / drivers / input / misc / axp20x-pek.c
index 400869e61a0663be592e723f8f9de4f3596aaf3d..cfeb0e943de69519779508a65fab961222dfce27 100644 (file)
@@ -182,13 +182,6 @@ static irqreturn_t axp20x_pek_irq(int irq, void *pwr)
        return IRQ_HANDLED;
 }
 
-static void axp20x_remove_sysfs_group(void *_data)
-{
-       struct device *dev = _data;
-
-       sysfs_remove_group(&dev->kobj, &axp20x_attribute_group);
-}
-
 static int axp20x_pek_probe_input_device(struct axp20x_pek *axp20x_pek,
                                         struct platform_device *pdev)
 {
@@ -253,6 +246,9 @@ static int axp20x_pek_probe_input_device(struct axp20x_pek *axp20x_pek,
                return error;
        }
 
+       if (axp20x_pek->axp20x->variant == AXP288_ID)
+               enable_irq_wake(axp20x_pek->irq_dbr);
+
        return 0;
 }
 
@@ -310,31 +306,47 @@ static int axp20x_pek_probe(struct platform_device *pdev)
                        return error;
        }
 
-       error = sysfs_create_group(&pdev->dev.kobj, &axp20x_attribute_group);
+       error = devm_device_add_group(&pdev->dev, &axp20x_attribute_group);
        if (error) {
                dev_err(&pdev->dev, "Failed to create sysfs attributes: %d\n",
                        error);
                return error;
        }
 
-       error = devm_add_action(&pdev->dev,
-                               axp20x_remove_sysfs_group, &pdev->dev);
-       if (error) {
-               axp20x_remove_sysfs_group(&pdev->dev);
-               dev_err(&pdev->dev, "Failed to add sysfs cleanup action: %d\n",
-                       error);
-               return error;
-       }
-
        platform_set_drvdata(pdev, axp20x_pek);
 
        return 0;
 }
 
+static int __maybe_unused axp20x_pek_resume_noirq(struct device *dev)
+{
+       struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev);
+
+       if (axp20x_pek->axp20x->variant != AXP288_ID)
+               return 0;
+
+       /*
+        * Clear interrupts from button presses during suspend, to avoid
+        * a wakeup power-button press getting reported to userspace.
+        */
+       regmap_write(axp20x_pek->axp20x->regmap,
+                    AXP20X_IRQ1_STATE + AXP288_IRQ_POKN / 8,
+                    BIT(AXP288_IRQ_POKN % 8));
+
+       return 0;
+}
+
+static const struct dev_pm_ops axp20x_pek_pm_ops = {
+#ifdef CONFIG_PM_SLEEP
+       .resume_noirq = axp20x_pek_resume_noirq,
+#endif
+};
+
 static struct platform_driver axp20x_pek_driver = {
        .probe          = axp20x_pek_probe,
        .driver         = {
                .name           = "axp20x-pek",
+               .pm             = &axp20x_pek_pm_ops,
        },
 };
 module_platform_driver(axp20x_pek_driver);