blob: 30b459b6b344c427cd4bef9501b4c592ef952a56 [file] [log] [blame]
Aaro Koskinen544a46c2012-11-10 00:50:25 -08001/*
2 * Retu power button driver.
3 *
4 * Copyright (C) 2004-2010 Nokia Corporation
5 *
6 * Original code written by Ari Saastamoinen, Juha Yrjölä and Felipe Balbi.
7 * Rewritten by Aaro Koskinen.
8 *
9 * This file is subject to the terms and conditions of the GNU General
10 * Public License. See the file "COPYING" in the main directory of this
11 * archive for more details.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */
18
19#include <linux/irq.h>
Aaro Koskinen544a46c2012-11-10 00:50:25 -080020#include <linux/slab.h>
21#include <linux/errno.h>
22#include <linux/input.h>
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/mfd/retu.h>
26#include <linux/interrupt.h>
27#include <linux/platform_device.h>
28
29#define RETU_STATUS_PWRONX (1 << 5)
30
31static irqreturn_t retu_pwrbutton_irq(int irq, void *_pwr)
32{
33 struct input_dev *idev = _pwr;
34 struct retu_dev *rdev = input_get_drvdata(idev);
35 bool state;
36
37 state = !(retu_read(rdev, RETU_REG_STATUS) & RETU_STATUS_PWRONX);
38 input_report_key(idev, KEY_POWER, state);
39 input_sync(idev);
40
41 return IRQ_HANDLED;
42}
43
Bill Pemberton5298cc42012-11-23 21:38:25 -080044static int retu_pwrbutton_probe(struct platform_device *pdev)
Aaro Koskinen544a46c2012-11-10 00:50:25 -080045{
46 struct retu_dev *rdev = dev_get_drvdata(pdev->dev.parent);
47 struct input_dev *idev;
48 int irq;
49 int error;
50
51 irq = platform_get_irq(pdev, 0);
52 if (irq < 0)
53 return irq;
54
55 idev = devm_input_allocate_device(&pdev->dev);
56 if (!idev)
57 return -ENOMEM;
58
59 idev->name = "retu-pwrbutton";
60 idev->dev.parent = &pdev->dev;
61
62 input_set_capability(idev, EV_KEY, KEY_POWER);
63 input_set_drvdata(idev, rdev);
64
65 error = devm_request_threaded_irq(&pdev->dev, irq,
Fabio Estevam6b36d8f2015-05-15 15:55:34 -070066 NULL, retu_pwrbutton_irq,
67 IRQF_ONESHOT,
Aaro Koskinen544a46c2012-11-10 00:50:25 -080068 "retu-pwrbutton", idev);
69 if (error)
70 return error;
71
72 error = input_register_device(idev);
73 if (error)
74 return error;
75
76 return 0;
77}
78
Bill Pembertone2619cf2012-11-23 21:50:47 -080079static int retu_pwrbutton_remove(struct platform_device *pdev)
Aaro Koskinen544a46c2012-11-10 00:50:25 -080080{
81 return 0;
82}
83
84static struct platform_driver retu_pwrbutton_driver = {
85 .probe = retu_pwrbutton_probe,
Bill Pemberton1cb0aa82012-11-23 21:27:39 -080086 .remove = retu_pwrbutton_remove,
Aaro Koskinen544a46c2012-11-10 00:50:25 -080087 .driver = {
88 .name = "retu-pwrbutton",
Aaro Koskinen544a46c2012-11-10 00:50:25 -080089 },
90};
91module_platform_driver(retu_pwrbutton_driver);
92
93MODULE_ALIAS("platform:retu-pwrbutton");
94MODULE_DESCRIPTION("Retu Power Button");
95MODULE_AUTHOR("Ari Saastamoinen");
96MODULE_AUTHOR("Felipe Balbi");
97MODULE_AUTHOR("Aaro Koskinen <aaro.koskinen@iki.fi>");
98MODULE_LICENSE("GPL");