]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/input/misc/twl4030-pwrbutton.c
i2c: move twl4030-pwrbutton to child registration style
[linux-2.6-omap-h63xx.git] / drivers / input / misc / twl4030-pwrbutton.c
1 /**
2  * drivers/i2c/chips/twl4030-pwrbutton.c
3  *
4  * Driver for sending triton2 power button event to input-layer
5  *
6  * Copyright (C) 2008 Nokia Corporation
7  *
8  * Written by Peter De Schrijver <peter.de-schrijver@nokia.com>
9  *
10  * This file is subject to the terms and conditions of the GNU General
11  * Public License. See the file "COPYING" in the main directory of this
12  * archive for more details.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/kernel.h>
27 #include <linux/errno.h>
28 #include <linux/input.h>
29 #include <linux/interrupt.h>
30 #include <linux/platform_device.h>
31 #include <linux/i2c/twl4030.h>
32
33 #define PWR_PWRON_IRQ (1 << 0)
34
35 #define STS_HW_CONDITIONS 0xf
36
37 static struct input_dev *powerbutton_dev;
38 static struct device *dbg_dev;
39
40 static irqreturn_t powerbutton_irq(int irq, void *dev_id)
41 {
42         int err;
43         u8 value;
44
45 #ifdef CONFIG_LOCKDEP
46         /* WORKAROUND for lockdep forcing IRQF_DISABLED on us, which
47          * we don't want and can't tolerate.  Although it might be
48          * friendlier not to borrow this thread context...
49          */
50         local_irq_enable();
51 #endif
52
53         err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &value,
54                                   STS_HW_CONDITIONS);
55         if (!err)  {
56                 input_report_key(powerbutton_dev, KEY_POWER,
57                                  value & PWR_PWRON_IRQ);
58         } else {
59                 dev_err(dbg_dev, "twl4030: i2c error %d while reading TWL4030"
60                         " PM_MASTER STS_HW_CONDITIONS register\n", err);
61         }
62
63         return IRQ_HANDLED;
64 }
65
66 static int __devinit twl4030_pwrbutton_probe(struct platform_device *pdev)
67 {
68         int err = 0;
69         int irq = platform_get_irq(pdev, 0);
70
71         dbg_dev = &pdev->dev;
72
73         /* PWRBTN == PWRON */
74         err = request_irq(irq, powerbutton_irq,
75                         IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
76                         "twl4030-pwrbutton", NULL);
77         if (err < 0) {
78                 dev_dbg(&pdev->dev, "Can't get IRQ for power button: %d\n", err);
79                 goto out;
80         }
81
82         powerbutton_dev = input_allocate_device();
83         if (!powerbutton_dev) {
84                 dev_dbg(&pdev->dev, "Can't allocate power button\n");
85                 err = -ENOMEM;
86                 goto free_irq_and_out;
87         }
88
89         powerbutton_dev->evbit[0] = BIT_MASK(EV_KEY);
90         powerbutton_dev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);
91         powerbutton_dev->name = "triton2-pwrbutton";
92
93         err = input_register_device(powerbutton_dev);
94         if (err) {
95                 dev_dbg(&pdev->dev, "Can't register power button: %d\n", err);
96                 goto free_input_dev;
97         }
98
99         dev_info(&pdev->dev, "triton2 power button driver initialized\n");
100
101         return 0;
102
103
104 free_input_dev:
105         input_free_device(powerbutton_dev);
106 free_irq_and_out:
107         free_irq(TWL4030_PWRIRQ_PWRBTN, NULL);
108 out:
109         return err;
110 }
111
112 static int __devexit twl4030_pwrbutton_remove(struct platform_device *pdev)
113 {
114         int irq = platform_get_irq(pdev, 0);
115
116         free_irq(irq, NULL);
117         input_unregister_device(powerbutton_dev);
118         input_free_device(powerbutton_dev);
119
120         return 0;
121 }
122
123 struct platform_driver twl4030_pwrbutton_driver = {
124         .probe          = twl4030_pwrbutton_probe,
125         .remove         = twl4030_pwrbutton_remove,
126         .driver         = {
127                 .name   = "twl4030-pwrbutton",
128                 .owner  = THIS_MODULE,
129         },
130 };
131
132 static int __init twl4030_pwrbutton_init(void)
133 {
134         return platform_driver_register(&twl4030_pwrbutton_driver);
135 }
136 module_init(twl4030_pwrbutton_init);
137
138 static void __exit twl4030_pwrbutton_exit(void)
139 {
140         platform_driver_unregister(&twl4030_pwrbutton_driver);
141 }
142 module_exit(twl4030_pwrbutton_exit);
143
144 MODULE_DESCRIPTION("Triton2 Power Button");
145 MODULE_LICENSE("GPL");
146 MODULE_AUTHOR("Peter De Schrijver");
147