x86/xen: resume timer irqs early
[linux/fpc-iii.git] / drivers / input / misc / da9052_onkey.c
blob020569a499f20faa03a63fff95847ed8be42c273
1 /*
2 * ON pin driver for Dialog DA9052 PMICs
4 * Copyright(c) 2012 Dialog Semiconductor Ltd.
6 * Author: David Dajun Chen <dchen@diasemi.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
14 #include <linux/init.h>
15 #include <linux/input.h>
16 #include <linux/module.h>
17 #include <linux/platform_device.h>
18 #include <linux/workqueue.h>
20 #include <linux/mfd/da9052/da9052.h>
21 #include <linux/mfd/da9052/reg.h>
23 struct da9052_onkey {
24 struct da9052 *da9052;
25 struct input_dev *input;
26 struct delayed_work work;
29 static void da9052_onkey_query(struct da9052_onkey *onkey)
31 int key_stat;
33 key_stat = da9052_reg_read(onkey->da9052, DA9052_EVENT_B_REG);
34 if (key_stat < 0) {
35 dev_err(onkey->da9052->dev,
36 "Failed to read onkey event %d\n", key_stat);
37 } else {
39 * Since interrupt for deassertion of ONKEY pin is not
40 * generated, onkey event state determines the onkey
41 * button state.
43 key_stat &= DA9052_EVENTB_ENONKEY;
44 input_report_key(onkey->input, KEY_POWER, key_stat);
45 input_sync(onkey->input);
49 * Interrupt is generated only when the ONKEY pin is asserted.
50 * Hence the deassertion of the pin is simulated through work queue.
52 if (key_stat)
53 schedule_delayed_work(&onkey->work, msecs_to_jiffies(50));
56 static void da9052_onkey_work(struct work_struct *work)
58 struct da9052_onkey *onkey = container_of(work, struct da9052_onkey,
59 work.work);
61 da9052_onkey_query(onkey);
64 static irqreturn_t da9052_onkey_irq(int irq, void *data)
66 struct da9052_onkey *onkey = data;
68 da9052_onkey_query(onkey);
70 return IRQ_HANDLED;
73 static int da9052_onkey_probe(struct platform_device *pdev)
75 struct da9052 *da9052 = dev_get_drvdata(pdev->dev.parent);
76 struct da9052_onkey *onkey;
77 struct input_dev *input_dev;
78 int error;
80 if (!da9052) {
81 dev_err(&pdev->dev, "Failed to get the driver's data\n");
82 return -EINVAL;
85 onkey = kzalloc(sizeof(*onkey), GFP_KERNEL);
86 input_dev = input_allocate_device();
87 if (!onkey || !input_dev) {
88 dev_err(&pdev->dev, "Failed to allocate memory\n");
89 error = -ENOMEM;
90 goto err_free_mem;
93 onkey->input = input_dev;
94 onkey->da9052 = da9052;
95 INIT_DELAYED_WORK(&onkey->work, da9052_onkey_work);
97 input_dev->name = "da9052-onkey";
98 input_dev->phys = "da9052-onkey/input0";
99 input_dev->dev.parent = &pdev->dev;
101 input_dev->evbit[0] = BIT_MASK(EV_KEY);
102 __set_bit(KEY_POWER, input_dev->keybit);
104 error = da9052_request_irq(onkey->da9052, DA9052_IRQ_NONKEY, "ONKEY",
105 da9052_onkey_irq, onkey);
106 if (error < 0) {
107 dev_err(onkey->da9052->dev,
108 "Failed to register ONKEY IRQ: %d\n", error);
109 goto err_free_mem;
112 error = input_register_device(onkey->input);
113 if (error) {
114 dev_err(&pdev->dev, "Unable to register input device, %d\n",
115 error);
116 goto err_free_irq;
119 platform_set_drvdata(pdev, onkey);
120 return 0;
122 err_free_irq:
123 da9052_free_irq(onkey->da9052, DA9052_IRQ_NONKEY, onkey);
124 cancel_delayed_work_sync(&onkey->work);
125 err_free_mem:
126 input_free_device(input_dev);
127 kfree(onkey);
129 return error;
132 static int da9052_onkey_remove(struct platform_device *pdev)
134 struct da9052_onkey *onkey = platform_get_drvdata(pdev);
136 da9052_free_irq(onkey->da9052, DA9052_IRQ_NONKEY, onkey);
137 cancel_delayed_work_sync(&onkey->work);
139 input_unregister_device(onkey->input);
140 kfree(onkey);
142 return 0;
145 static struct platform_driver da9052_onkey_driver = {
146 .probe = da9052_onkey_probe,
147 .remove = da9052_onkey_remove,
148 .driver = {
149 .name = "da9052-onkey",
150 .owner = THIS_MODULE,
153 module_platform_driver(da9052_onkey_driver);
155 MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
156 MODULE_DESCRIPTION("Onkey driver for DA9052");
157 MODULE_LICENSE("GPL");
158 MODULE_ALIAS("platform:da9052-onkey");