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");
102 onkey
->input
= input_dev
;
103 onkey
->da9052
= da9052
;
105 INIT_DELAYED_WORK(&onkey
->work
, da9052_onkey_work
);
107 input_dev
->name
= "da9052-onkey";
108 input_dev
->phys
= "da9052-onkey/input0";
109 input_dev
->dev
.parent
= &pdev
->dev
;
111 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
);
112 __set_bit(KEY_POWER
, input_dev
->keybit
);
114 error
= request_threaded_irq(onkey
->irq
, NULL
, da9052_onkey_irq
,
115 IRQF_TRIGGER_LOW
| IRQF_ONESHOT
,
118 dev_err(onkey
->da9052
->dev
,
119 "Failed to register ONKEY IRQ %d, error = %d\n",
124 error
= input_register_device(onkey
->input
);
126 dev_err(&pdev
->dev
, "Unable to register input device, %d\n",
131 platform_set_drvdata(pdev
, onkey
);
135 free_irq(onkey
->irq
, onkey
);
136 cancel_delayed_work_sync(&onkey
->work
);
138 input_free_device(input_dev
);
144 static int __devexit
da9052_onkey_remove(struct platform_device
*pdev
)
146 struct da9052_onkey
*onkey
= platform_get_drvdata(pdev
);
148 free_irq(onkey
->irq
, onkey
);
149 cancel_delayed_work_sync(&onkey
->work
);
151 input_unregister_device(onkey
->input
);
157 static struct platform_driver da9052_onkey_driver
= {
158 .probe
= da9052_onkey_probe
,
159 .remove
= __devexit_p(da9052_onkey_remove
),
161 .name
= "da9052-onkey",
162 .owner
= THIS_MODULE
,
165 module_platform_driver(da9052_onkey_driver
);
167 MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
168 MODULE_DESCRIPTION("Onkey driver for DA9052");
169 MODULE_LICENSE("GPL");
170 MODULE_ALIAS("platform:da9052-onkey");