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>
24 struct da9052 *da9052;
25 struct input_dev *input;
26 struct delayed_work work;
30 static void da9052_onkey_query(struct da9052_onkey *onkey)
34 key_stat = da9052_reg_read(onkey->da9052, DA9052_EVENT_B_REG);
36 dev_err(onkey->da9052->dev,
37 "Failed to read onkey event %d\n", key_stat);
40 * Since interrupt for deassertion of ONKEY pin is not
41 * generated, onkey event state determines the onkey
44 key_stat &= DA9052_EVENTB_ENONKEY;
45 input_report_key(onkey->input, KEY_POWER, key_stat);
46 input_sync(onkey->input);
50 * Interrupt is generated only when the ONKEY pin is asserted.
51 * Hence the deassertion of the pin is simulated through work queue.
54 schedule_delayed_work(&onkey->work, msecs_to_jiffies(50));
57 static void da9052_onkey_work(struct work_struct *work)
59 struct da9052_onkey *onkey = container_of(work, struct da9052_onkey,
62 da9052_onkey_query(onkey);
65 static irqreturn_t da9052_onkey_irq(int irq, void *data)
67 struct da9052_onkey *onkey = data;
69 da9052_onkey_query(onkey);
74 static int __devinit da9052_onkey_probe(struct platform_device *pdev)
76 struct da9052 *da9052 = dev_get_drvdata(pdev->dev.parent);
77 struct da9052_onkey *onkey;
78 struct input_dev *input_dev;
83 dev_err(&pdev->dev, "Failed to get the driver's data\n");
87 irq = platform_get_irq_byname(pdev, "ONKEY");
90 "Failed to get an IRQ for input device, %d\n", irq);
94 onkey = kzalloc(sizeof(*onkey), GFP_KERNEL);
95 input_dev = input_allocate_device();
96 if (!onkey || !input_dev) {
97 dev_err(&pdev->dev, "Failed to allocate memory\n");
101 onkey->input = input_dev;
102 onkey->da9052 = da9052;
104 INIT_DELAYED_WORK(&onkey->work, da9052_onkey_work);
106 input_dev->name = "da9052-onkey";
107 input_dev->phys = "da9052-onkey/input0";
108 input_dev->dev.parent = &pdev->dev;
110 input_dev->evbit[0] = BIT_MASK(EV_KEY);
111 __set_bit(KEY_POWER, input_dev->keybit);
113 error = request_threaded_irq(onkey->irq, NULL, da9052_onkey_irq,
114 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
117 dev_err(onkey->da9052->dev,
118 "Failed to register ONKEY IRQ %d, error = %d\n",
123 error = input_register_device(onkey->input);
125 dev_err(&pdev->dev, "Unable to register input device, %d\n",
130 platform_set_drvdata(pdev, onkey);
134 free_irq(onkey->irq, onkey);
135 cancel_delayed_work_sync(&onkey->work);
137 input_free_device(input_dev);
143 static int __devexit da9052_onkey_remove(struct platform_device *pdev)
145 struct da9052_onkey *onkey = platform_get_drvdata(pdev);
147 free_irq(onkey->irq, onkey);
148 cancel_delayed_work_sync(&onkey->work);
150 input_unregister_device(onkey->input);
156 static struct platform_driver da9052_onkey_driver = {
157 .probe = da9052_onkey_probe,
158 .remove = __devexit_p(da9052_onkey_remove),
160 .name = "da9052-onkey",
161 .owner = THIS_MODULE,
164 module_platform_driver(da9052_onkey_driver);
166 MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
167 MODULE_DESCRIPTION("Onkey driver for DA9052");
168 MODULE_LICENSE("GPL");
169 MODULE_ALIAS("platform:da9052-onkey");