13 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/slab.h>
18 #include <linux/input.h>
26 #define PON_CNTL_1 0x1C
27 #define PON_CNTL_PULL_UP BIT(7)
28 #define PON_CNTL_TRIG_DELAY_MASK (0x7)
35 struct input_dev *
pwr;
39 static irqreturn_t pwrkey_press_irq(
int irq,
void *_pwrkey)
44 input_sync(pwrkey->
pwr);
49 static irqreturn_t pwrkey_release_irq(
int irq,
void *_pwrkey)
54 input_sync(pwrkey->
pwr);
59 #ifdef CONFIG_PM_SLEEP
60 static int pmic8xxx_pwrkey_suspend(
struct device *
dev)
64 if (device_may_wakeup(dev))
70 static int pmic8xxx_pwrkey_resume(
struct device *dev)
74 if (device_may_wakeup(dev))
82 pmic8xxx_pwrkey_suspend, pmic8xxx_pwrkey_resume);
86 struct input_dev *pwr;
94 dev_get_platdata(&pdev->
dev);
97 dev_err(&pdev->
dev,
"power key platform data not supplied\n");
102 dev_err(&pdev->
dev,
"invalid power key trigger delay\n");
106 pwrkey = kzalloc(
sizeof(*pwrkey),
GFP_KERNEL);
110 pwr = input_allocate_device();
112 dev_dbg(&pdev->
dev,
"Can't allocate power button\n");
119 pwr->name =
"pmic8xxx_pwrkey";
120 pwr->phys =
"pmic8xxx_pwrkey/input0";
121 pwr->dev.parent = &pdev->
dev;
124 delay = 1 +
ilog2(delay);
128 dev_err(&pdev->
dev,
"failed reading PON_CNTL_1 err=%d\n", err);
141 dev_err(&pdev->
dev,
"failed writing PON_CNTL_1 err=%d\n", err);
145 err = input_register_device(pwr);
147 dev_dbg(&pdev->
dev,
"Can't register power key: %d\n", err);
154 platform_set_drvdata(pdev, pwrkey);
159 dev_dbg(&pdev->
dev,
"Can't get %d IRQ for pwrkey: %d\n",
161 goto unreg_input_dev;
164 err =
request_irq(key_release_irq, pwrkey_release_irq,
167 dev_dbg(&pdev->
dev,
"Can't get %d IRQ for pwrkey: %d\n",
168 key_release_irq, err);
180 platform_set_drvdata(pdev,
NULL);
181 input_unregister_device(pwr);
184 input_free_device(pwr);
200 input_unregister_device(pwrkey->
pwr);
201 platform_set_drvdata(pdev,
NULL);
208 .probe = pmic8xxx_pwrkey_probe,
213 .pm = &pm8xxx_pwr_key_pm_ops,