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/input.h>
15 #include <linux/module.h>
16 #include <linux/platform_device.h>
17 #include <linux/workqueue.h>
19 #include <linux/mfd/da9052/da9052.h>
20 #include <linux/mfd/da9052/reg.h>
23 struct da9052
*da9052
;
24 struct input_dev
*input
;
25 struct delayed_work work
;
28 static void da9052_onkey_query(struct da9052_onkey
*onkey
)
32 ret
= da9052_reg_read(onkey
->da9052
, DA9052_STATUS_A_REG
);
34 dev_err(onkey
->da9052
->dev
,
35 "Failed to read onkey event err=%d\n", ret
);
38 * Since interrupt for deassertion of ONKEY pin is not
39 * generated, onkey event state determines the onkey
42 bool pressed
= !(ret
& DA9052_STATUSA_NONKEY
);
44 input_report_key(onkey
->input
, KEY_POWER
, pressed
);
45 input_sync(onkey
->input
);
48 * Interrupt is generated only when the ONKEY pin
49 * is asserted. Hence the deassertion of the pin
50 * is simulated through work queue.
53 schedule_delayed_work(&onkey
->work
,
54 msecs_to_jiffies(50));
58 static void da9052_onkey_work(struct work_struct
*work
)
60 struct da9052_onkey
*onkey
= container_of(work
, struct da9052_onkey
,
63 da9052_onkey_query(onkey
);
66 static irqreturn_t
da9052_onkey_irq(int irq
, void *data
)
68 struct da9052_onkey
*onkey
= data
;
70 da9052_onkey_query(onkey
);
75 static int da9052_onkey_probe(struct platform_device
*pdev
)
77 struct da9052
*da9052
= dev_get_drvdata(pdev
->dev
.parent
);
78 struct da9052_onkey
*onkey
;
79 struct input_dev
*input_dev
;
83 dev_err(&pdev
->dev
, "Failed to get the driver's data\n");
87 onkey
= kzalloc(sizeof(*onkey
), GFP_KERNEL
);
88 input_dev
= input_allocate_device();
89 if (!onkey
|| !input_dev
) {
90 dev_err(&pdev
->dev
, "Failed to allocate memory\n");
95 onkey
->input
= input_dev
;
96 onkey
->da9052
= da9052
;
97 INIT_DELAYED_WORK(&onkey
->work
, da9052_onkey_work
);
99 input_dev
->name
= "da9052-onkey";
100 input_dev
->phys
= "da9052-onkey/input0";
101 input_dev
->dev
.parent
= &pdev
->dev
;
103 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
);
104 __set_bit(KEY_POWER
, input_dev
->keybit
);
106 error
= da9052_request_irq(onkey
->da9052
, DA9052_IRQ_NONKEY
, "ONKEY",
107 da9052_onkey_irq
, onkey
);
109 dev_err(onkey
->da9052
->dev
,
110 "Failed to register ONKEY IRQ: %d\n", error
);
114 error
= input_register_device(onkey
->input
);
116 dev_err(&pdev
->dev
, "Unable to register input device, %d\n",
121 platform_set_drvdata(pdev
, onkey
);
125 da9052_free_irq(onkey
->da9052
, DA9052_IRQ_NONKEY
, onkey
);
126 cancel_delayed_work_sync(&onkey
->work
);
128 input_free_device(input_dev
);
134 static int da9052_onkey_remove(struct platform_device
*pdev
)
136 struct da9052_onkey
*onkey
= platform_get_drvdata(pdev
);
138 da9052_free_irq(onkey
->da9052
, DA9052_IRQ_NONKEY
, onkey
);
139 cancel_delayed_work_sync(&onkey
->work
);
141 input_unregister_device(onkey
->input
);
147 static struct platform_driver da9052_onkey_driver
= {
148 .probe
= da9052_onkey_probe
,
149 .remove
= da9052_onkey_remove
,
151 .name
= "da9052-onkey",
154 module_platform_driver(da9052_onkey_driver
);
156 MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
157 MODULE_DESCRIPTION("Onkey driver for DA9052");
158 MODULE_LICENSE("GPL");
159 MODULE_ALIAS("platform:da9052-onkey");