This source file includes following definitions.
- powerbutton_irq
- twl4030_pwrbutton_probe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/kernel.h>
26 #include <linux/errno.h>
27 #include <linux/input.h>
28 #include <linux/interrupt.h>
29 #include <linux/platform_device.h>
30 #include <linux/mfd/twl.h>
31
32 #define PWR_PWRON_IRQ (1 << 0)
33
34 #define STS_HW_CONDITIONS 0xf
35
36 static irqreturn_t powerbutton_irq(int irq, void *_pwr)
37 {
38 struct input_dev *pwr = _pwr;
39 int err;
40 u8 value;
41
42 err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &value, STS_HW_CONDITIONS);
43 if (!err) {
44 pm_wakeup_event(pwr->dev.parent, 0);
45 input_report_key(pwr, KEY_POWER, value & PWR_PWRON_IRQ);
46 input_sync(pwr);
47 } else {
48 dev_err(pwr->dev.parent, "twl4030: i2c error %d while reading"
49 " TWL4030 PM_MASTER STS_HW_CONDITIONS register\n", err);
50 }
51
52 return IRQ_HANDLED;
53 }
54
55 static int twl4030_pwrbutton_probe(struct platform_device *pdev)
56 {
57 struct input_dev *pwr;
58 int irq = platform_get_irq(pdev, 0);
59 int err;
60
61 pwr = devm_input_allocate_device(&pdev->dev);
62 if (!pwr) {
63 dev_err(&pdev->dev, "Can't allocate power button\n");
64 return -ENOMEM;
65 }
66
67 input_set_capability(pwr, EV_KEY, KEY_POWER);
68 pwr->name = "twl4030_pwrbutton";
69 pwr->phys = "twl4030_pwrbutton/input0";
70 pwr->dev.parent = &pdev->dev;
71
72 err = devm_request_threaded_irq(&pdev->dev, irq, NULL, powerbutton_irq,
73 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING |
74 IRQF_ONESHOT,
75 "twl4030_pwrbutton", pwr);
76 if (err < 0) {
77 dev_err(&pdev->dev, "Can't get IRQ for pwrbutton: %d\n", err);
78 return err;
79 }
80
81 err = input_register_device(pwr);
82 if (err) {
83 dev_err(&pdev->dev, "Can't register power button: %d\n", err);
84 return err;
85 }
86
87 device_init_wakeup(&pdev->dev, true);
88
89 return 0;
90 }
91
92 #ifdef CONFIG_OF
93 static const struct of_device_id twl4030_pwrbutton_dt_match_table[] = {
94 { .compatible = "ti,twl4030-pwrbutton" },
95 {},
96 };
97 MODULE_DEVICE_TABLE(of, twl4030_pwrbutton_dt_match_table);
98 #endif
99
100 static struct platform_driver twl4030_pwrbutton_driver = {
101 .probe = twl4030_pwrbutton_probe,
102 .driver = {
103 .name = "twl4030_pwrbutton",
104 .of_match_table = of_match_ptr(twl4030_pwrbutton_dt_match_table),
105 },
106 };
107 module_platform_driver(twl4030_pwrbutton_driver);
108
109 MODULE_ALIAS("platform:twl4030_pwrbutton");
110 MODULE_DESCRIPTION("Triton2 Power Button");
111 MODULE_LICENSE("GPL");
112 MODULE_AUTHOR("Peter De Schrijver <peter.de-schrijver@nokia.com>");
113 MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>");
114