1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/interrupt.h>
23#include <linux/slab.h>
24#include <linux/platform_device.h>
25#include <linux/input.h>
26#include <linux/mfd/intel_msic.h>
27#include <linux/pm_wakeirq.h>
28
29#define DRIVER_NAME "msic_power_btn"
30
31#define MSIC_PB_LEVEL (1 << 3)
32
33
34
35
36
37#define MSIC_PWRBTNM (1 << 0)
38
39static irqreturn_t mfld_pb_isr(int irq, void *dev_id)
40{
41 struct input_dev *input = dev_id;
42 int ret;
43 u8 pbstat;
44
45 ret = intel_msic_reg_read(INTEL_MSIC_PBSTATUS, &pbstat);
46 dev_dbg(input->dev.parent, "PB_INT status= %d\n", pbstat);
47
48 if (ret < 0) {
49 dev_err(input->dev.parent, "Read error %d while reading"
50 " MSIC_PB_STATUS\n", ret);
51 } else {
52 input_event(input, EV_KEY, KEY_POWER,
53 !(pbstat & MSIC_PB_LEVEL));
54 input_sync(input);
55 }
56
57 return IRQ_HANDLED;
58}
59
60static int mfld_pb_probe(struct platform_device *pdev)
61{
62 struct input_dev *input;
63 int irq = platform_get_irq(pdev, 0);
64 int error;
65
66 if (irq < 0)
67 return -EINVAL;
68
69 input = input_allocate_device();
70 if (!input)
71 return -ENOMEM;
72
73 input->name = pdev->name;
74 input->phys = "power-button/input0";
75 input->id.bustype = BUS_HOST;
76 input->dev.parent = &pdev->dev;
77
78 input_set_capability(input, EV_KEY, KEY_POWER);
79
80 error = request_threaded_irq(irq, NULL, mfld_pb_isr, 0,
81 DRIVER_NAME, input);
82 if (error) {
83 dev_err(&pdev->dev, "Unable to request irq %d for mfld power"
84 "button\n", irq);
85 goto err_free_input;
86 }
87
88 device_init_wakeup(&pdev->dev, true);
89 dev_pm_set_wake_irq(&pdev->dev, irq);
90
91 error = input_register_device(input);
92 if (error) {
93 dev_err(&pdev->dev, "Unable to register input dev, error "
94 "%d\n", error);
95 goto err_free_irq;
96 }
97
98 platform_set_drvdata(pdev, input);
99
100
101
102
103
104
105
106
107
108
109
110 error = intel_msic_reg_update(INTEL_MSIC_IRQLVL1MSK, 0, MSIC_PWRBTNM);
111 if (error) {
112 dev_err(&pdev->dev, "Unable to clear power button interrupt, "
113 "error: %d\n", error);
114 goto err_free_irq;
115 }
116
117 return 0;
118
119err_free_irq:
120 free_irq(irq, input);
121err_free_input:
122 input_free_device(input);
123 return error;
124}
125
126static int mfld_pb_remove(struct platform_device *pdev)
127{
128 struct input_dev *input = platform_get_drvdata(pdev);
129 int irq = platform_get_irq(pdev, 0);
130
131 dev_pm_clear_wake_irq(&pdev->dev);
132 device_init_wakeup(&pdev->dev, false);
133 free_irq(irq, input);
134 input_unregister_device(input);
135
136 return 0;
137}
138
139static struct platform_driver mfld_pb_driver = {
140 .driver = {
141 .name = DRIVER_NAME,
142 },
143 .probe = mfld_pb_probe,
144 .remove = mfld_pb_remove,
145};
146
147module_platform_driver(mfld_pb_driver);
148
149MODULE_AUTHOR("Hong Liu <hong.liu@intel.com>");
150MODULE_DESCRIPTION("Intel Medfield Power Button Driver");
151MODULE_LICENSE("GPL v2");
152MODULE_ALIAS("platform:" DRIVER_NAME);
153