2 * wm831x-on.c - WM831X ON pin driver
4 * Copyright (C) 2009 Wolfson Microelectronics plc
6 * This file is subject to the terms and conditions of the GNU General
7 * Public License. See the file "COPYING" in the main directory of this
8 * archive for more details.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/slab.h>
23 #include <linux/kernel.h>
24 #include <linux/errno.h>
25 #include <linux/input.h>
26 #include <linux/interrupt.h>
27 #include <linux/platform_device.h>
28 #include <linux/workqueue.h>
29 #include <linux/mfd/wm831x/core.h>
32 struct input_dev
*dev
;
33 struct delayed_work work
;
34 struct wm831x
*wm831x
;
38 * The chip gives us an interrupt when the ON pin is asserted but we
39 * then need to poll to see when the pin is deasserted.
41 static void wm831x_poll_on(struct work_struct
*work
)
43 struct wm831x_on
*wm831x_on
= container_of(work
, struct wm831x_on
,
45 struct wm831x
*wm831x
= wm831x_on
->wm831x
;
48 ret
= wm831x_reg_read(wm831x
, WM831X_ON_PIN_CONTROL
);
50 poll
= !(ret
& WM831X_ON_PIN_STS
);
52 input_report_key(wm831x_on
->dev
, KEY_POWER
, poll
);
53 input_sync(wm831x_on
->dev
);
55 dev_err(wm831x
->dev
, "Failed to read ON status: %d\n", ret
);
60 schedule_delayed_work(&wm831x_on
->work
, 100);
63 static irqreturn_t
wm831x_on_irq(int irq
, void *data
)
65 struct wm831x_on
*wm831x_on
= data
;
67 schedule_delayed_work(&wm831x_on
->work
, 0);
72 static int __devinit
wm831x_on_probe(struct platform_device
*pdev
)
74 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
75 struct wm831x_on
*wm831x_on
;
76 int irq
= platform_get_irq(pdev
, 0);
79 wm831x_on
= kzalloc(sizeof(struct wm831x_on
), GFP_KERNEL
);
81 dev_err(&pdev
->dev
, "Can't allocate data\n");
85 wm831x_on
->wm831x
= wm831x
;
86 INIT_DELAYED_WORK(&wm831x_on
->work
, wm831x_poll_on
);
88 wm831x_on
->dev
= input_allocate_device();
89 if (!wm831x_on
->dev
) {
90 dev_err(&pdev
->dev
, "Can't allocate input dev\n");
95 wm831x_on
->dev
->evbit
[0] = BIT_MASK(EV_KEY
);
96 wm831x_on
->dev
->keybit
[BIT_WORD(KEY_POWER
)] = BIT_MASK(KEY_POWER
);
97 wm831x_on
->dev
->name
= "wm831x_on";
98 wm831x_on
->dev
->phys
= "wm831x_on/input0";
99 wm831x_on
->dev
->dev
.parent
= &pdev
->dev
;
101 ret
= request_threaded_irq(irq
, NULL
, wm831x_on_irq
,
102 IRQF_TRIGGER_RISING
, "wm831x_on",
105 dev_err(&pdev
->dev
, "Unable to request IRQ: %d\n", ret
);
108 ret
= input_register_device(wm831x_on
->dev
);
110 dev_dbg(&pdev
->dev
, "Can't register input device: %d\n", ret
);
114 platform_set_drvdata(pdev
, wm831x_on
);
119 free_irq(irq
, wm831x_on
);
121 input_free_device(wm831x_on
->dev
);
127 static int __devexit
wm831x_on_remove(struct platform_device
*pdev
)
129 struct wm831x_on
*wm831x_on
= platform_get_drvdata(pdev
);
130 int irq
= platform_get_irq(pdev
, 0);
132 free_irq(irq
, wm831x_on
);
133 cancel_delayed_work_sync(&wm831x_on
->work
);
134 input_unregister_device(wm831x_on
->dev
);
140 static struct platform_driver wm831x_on_driver
= {
141 .probe
= wm831x_on_probe
,
142 .remove
= __devexit_p(wm831x_on_remove
),
145 .owner
= THIS_MODULE
,
148 module_platform_driver(wm831x_on_driver
);
150 MODULE_ALIAS("platform:wm831x-on");
151 MODULE_DESCRIPTION("WM831x ON pin");
152 MODULE_LICENSE("GPL");
153 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");