blob: 840e53732753f556a6f89e7afde3b2c1bf65edcc [file] [log] [blame]
Abraham Arcea17f7952010-08-31 17:05:27 -07001/*
2 * OMAP4 Keypad Driver
3 *
4 * Copyright (C) 2010 Texas Instruments
5 *
6 * Author: Abraham Arce <x0066660@ti.com>
7 * Initial Code: Syed Rafiuddin <rafiuddin.syed@ti.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#include <linux/module.h>
Abraham Arcea17f7952010-08-31 17:05:27 -070025#include <linux/interrupt.h>
26#include <linux/platform_device.h>
27#include <linux/errno.h>
28#include <linux/io.h>
Sourav Poddar13987432012-07-13 00:10:47 -070029#include <linux/of.h>
Abraham Arcea17f7952010-08-31 17:05:27 -070030#include <linux/input.h>
Joachim Eastwood61721c82014-05-29 00:30:02 -070031#include <linux/input/matrix_keypad.h>
Abraham Arcea17f7952010-08-31 17:05:27 -070032#include <linux/slab.h>
Abraham Arce5ad567f2011-02-22 22:25:59 -080033#include <linux/pm_runtime.h>
Abraham Arcea17f7952010-08-31 17:05:27 -070034
Abraham Arcea17f7952010-08-31 17:05:27 -070035/* OMAP4 registers */
36#define OMAP4_KBD_REVISION 0x00
37#define OMAP4_KBD_SYSCONFIG 0x10
38#define OMAP4_KBD_SYSSTATUS 0x14
39#define OMAP4_KBD_IRQSTATUS 0x18
40#define OMAP4_KBD_IRQENABLE 0x1C
41#define OMAP4_KBD_WAKEUPENABLE 0x20
42#define OMAP4_KBD_PENDING 0x24
43#define OMAP4_KBD_CTRL 0x28
44#define OMAP4_KBD_DEBOUNCINGTIME 0x2C
45#define OMAP4_KBD_LONGKEYTIME 0x30
46#define OMAP4_KBD_TIMEOUT 0x34
47#define OMAP4_KBD_STATEMACHINE 0x38
48#define OMAP4_KBD_ROWINPUTS 0x3C
49#define OMAP4_KBD_COLUMNOUTPUTS 0x40
50#define OMAP4_KBD_FULLCODE31_0 0x44
51#define OMAP4_KBD_FULLCODE63_32 0x48
52
53/* OMAP4 bit definitions */
Illia Smyrnov875ad692013-08-25 23:25:18 -070054#define OMAP4_DEF_IRQENABLE_EVENTEN BIT(0)
55#define OMAP4_DEF_IRQENABLE_LONGKEY BIT(1)
56#define OMAP4_DEF_WUP_EVENT_ENA BIT(0)
57#define OMAP4_DEF_WUP_LONG_KEY_ENA BIT(1)
58#define OMAP4_DEF_CTRL_NOSOFTMODE BIT(1)
59#define OMAP4_DEF_CTRL_PTV_SHIFT 2
Abraham Arcea17f7952010-08-31 17:05:27 -070060
61/* OMAP4 values */
Illia Smyrnov875ad692013-08-25 23:25:18 -070062#define OMAP4_VAL_IRQDISABLE 0x0
Tony Lindgren6c3516f2018-12-03 11:24:30 -080063
64/*
65 * Errata i689: If a key is released for a time shorter than debounce time,
66 * the keyboard will idle and never detect the key release. The workaround
67 * is to use at least a 12ms debounce time. See omap5432 TRM chapter
68 * "26.4.6.2 Keyboard Controller Timer" for more information.
69 */
70#define OMAP4_KEYPAD_PTV_DIV_128 0x6
71#define OMAP4_KEYPAD_DEBOUNCINGTIME_MS(dbms, ptv) \
72 ((((dbms) * 1000) / ((1 << ((ptv) + 1)) * (1000000 / 32768))) - 1)
73#define OMAP4_VAL_DEBOUNCINGTIME_16MS \
74 OMAP4_KEYPAD_DEBOUNCINGTIME_MS(16, OMAP4_KEYPAD_PTV_DIV_128)
Abraham Arcea17f7952010-08-31 17:05:27 -070075
Poddar, Souravf77621c2012-05-10 22:32:00 -070076enum {
77 KBD_REVISION_OMAP4 = 0,
78 KBD_REVISION_OMAP5,
79};
80
Abraham Arcea17f7952010-08-31 17:05:27 -070081struct omap4_keypad {
82 struct input_dev *input;
83
84 void __iomem *base;
Illia Smyrnov78608a02013-08-25 23:29:30 -070085 bool irq_wake_enabled;
Poddar, Souravf77621c2012-05-10 22:32:00 -070086 unsigned int irq;
Abraham Arcea17f7952010-08-31 17:05:27 -070087
88 unsigned int rows;
89 unsigned int cols;
Poddar, Souravf77621c2012-05-10 22:32:00 -070090 u32 reg_offset;
91 u32 irqreg_offset;
Abraham Arcea17f7952010-08-31 17:05:27 -070092 unsigned int row_shift;
Sourav Poddar13987432012-07-13 00:10:47 -070093 bool no_autorepeat;
Abraham Arcea17f7952010-08-31 17:05:27 -070094 unsigned char key_state[8];
Sourav Poddar13987432012-07-13 00:10:47 -070095 unsigned short *keymap;
Abraham Arcea17f7952010-08-31 17:05:27 -070096};
97
Poddar, Souravf77621c2012-05-10 22:32:00 -070098static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
99{
100 return __raw_readl(keypad_data->base +
101 keypad_data->reg_offset + offset);
102}
103
104static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
105{
106 __raw_writel(value,
107 keypad_data->base + keypad_data->reg_offset + offset);
108}
109
110static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
111{
112 return __raw_readl(keypad_data->base +
113 keypad_data->irqreg_offset + offset);
114}
115
116static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
117 u32 offset, u32 value)
118{
119 __raw_writel(value,
120 keypad_data->base + keypad_data->irqreg_offset + offset);
121}
122
123
Illia Smyrnovc683da32013-08-25 23:25:50 -0700124/* Interrupt handlers */
125static irqreturn_t omap4_keypad_irq_handler(int irq, void *dev_id)
126{
127 struct omap4_keypad *keypad_data = dev_id;
128
Tony Lindgrene2ca26e2018-12-04 13:52:49 -0800129 if (kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS))
Illia Smyrnovc683da32013-08-25 23:25:50 -0700130 return IRQ_WAKE_THREAD;
Illia Smyrnovc683da32013-08-25 23:25:50 -0700131
132 return IRQ_NONE;
133}
134
135static irqreturn_t omap4_keypad_irq_thread_fn(int irq, void *dev_id)
Abraham Arcea17f7952010-08-31 17:05:27 -0700136{
137 struct omap4_keypad *keypad_data = dev_id;
138 struct input_dev *input_dev = keypad_data->input;
139 unsigned char key_state[ARRAY_SIZE(keypad_data->key_state)];
140 unsigned int col, row, code, changed;
141 u32 *new_state = (u32 *) key_state;
142
Poddar, Souravf77621c2012-05-10 22:32:00 -0700143 *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
144 *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
Abraham Arcea17f7952010-08-31 17:05:27 -0700145
146 for (row = 0; row < keypad_data->rows; row++) {
147 changed = key_state[row] ^ keypad_data->key_state[row];
148 if (!changed)
149 continue;
150
151 for (col = 0; col < keypad_data->cols; col++) {
152 if (changed & (1 << col)) {
153 code = MATRIX_SCAN_CODE(row, col,
154 keypad_data->row_shift);
155 input_event(input_dev, EV_MSC, MSC_SCAN, code);
156 input_report_key(input_dev,
157 keypad_data->keymap[code],
158 key_state[row] & (1 << col));
159 }
160 }
161 }
162
163 input_sync(input_dev);
164
165 memcpy(keypad_data->key_state, key_state,
166 sizeof(keypad_data->key_state));
167
168 /* clear pending interrupts */
Poddar, Souravf77621c2012-05-10 22:32:00 -0700169 kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
170 kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
Abraham Arcea17f7952010-08-31 17:05:27 -0700171
Abraham Arcea17f7952010-08-31 17:05:27 -0700172 return IRQ_HANDLED;
173}
174
Abraham Arce5ad567f2011-02-22 22:25:59 -0800175static int omap4_keypad_open(struct input_dev *input)
176{
177 struct omap4_keypad *keypad_data = input_get_drvdata(input);
178
179 pm_runtime_get_sync(input->dev.parent);
180
181 disable_irq(keypad_data->irq);
182
Poddar, Souravf77621c2012-05-10 22:32:00 -0700183 kbd_writel(keypad_data, OMAP4_KBD_CTRL,
Illia Smyrnov875ad692013-08-25 23:25:18 -0700184 OMAP4_DEF_CTRL_NOSOFTMODE |
Tony Lindgren6c3516f2018-12-03 11:24:30 -0800185 (OMAP4_KEYPAD_PTV_DIV_128 << OMAP4_DEF_CTRL_PTV_SHIFT));
Poddar, Souravf77621c2012-05-10 22:32:00 -0700186 kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
Tony Lindgren6c3516f2018-12-03 11:24:30 -0800187 OMAP4_VAL_DEBOUNCINGTIME_16MS);
Illia Smyrnovafbac60b2013-08-25 23:26:16 -0700188 /* clear pending interrupts */
Poddar, Souravf77621c2012-05-10 22:32:00 -0700189 kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
Illia Smyrnovafbac60b2013-08-25 23:26:16 -0700190 kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
Poddar, Souravf77621c2012-05-10 22:32:00 -0700191 kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
192 OMAP4_DEF_IRQENABLE_EVENTEN |
193 OMAP4_DEF_IRQENABLE_LONGKEY);
194 kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
195 OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
Abraham Arce5ad567f2011-02-22 22:25:59 -0800196
197 enable_irq(keypad_data->irq);
198
199 return 0;
200}
201
202static void omap4_keypad_close(struct input_dev *input)
203{
204 struct omap4_keypad *keypad_data = input_get_drvdata(input);
205
206 disable_irq(keypad_data->irq);
207
Tony Lindgrene2ca26e2018-12-04 13:52:49 -0800208 /* Disable interrupts and wake-up events */
Poddar, Souravf77621c2012-05-10 22:32:00 -0700209 kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
210 OMAP4_VAL_IRQDISABLE);
Tony Lindgrene2ca26e2018-12-04 13:52:49 -0800211 kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE, 0);
Abraham Arce5ad567f2011-02-22 22:25:59 -0800212
213 /* clear pending interrupts */
Poddar, Souravf77621c2012-05-10 22:32:00 -0700214 kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
215 kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
Abraham Arce5ad567f2011-02-22 22:25:59 -0800216
217 enable_irq(keypad_data->irq);
218
219 pm_runtime_put_sync(input->dev.parent);
220}
221
Bill Pemberton5298cc42012-11-23 21:38:25 -0800222static int omap4_keypad_parse_dt(struct device *dev,
223 struct omap4_keypad *keypad_data)
Sourav Poddar13987432012-07-13 00:10:47 -0700224{
225 struct device_node *np = dev->of_node;
Simon Glass43840412013-02-25 14:08:40 -0800226 int err;
Sourav Poddar13987432012-07-13 00:10:47 -0700227
Dmitry Torokhovaef01aa2016-11-11 12:43:12 -0800228 err = matrix_keypad_parse_properties(dev, &keypad_data->rows,
229 &keypad_data->cols);
Simon Glass43840412013-02-25 14:08:40 -0800230 if (err)
231 return err;
Sourav Poddar13987432012-07-13 00:10:47 -0700232
233 if (of_get_property(np, "linux,input-no-autorepeat", NULL))
234 keypad_data->no_autorepeat = true;
235
236 return 0;
237}
Sourav Poddar13987432012-07-13 00:10:47 -0700238
Bill Pemberton5298cc42012-11-23 21:38:25 -0800239static int omap4_keypad_probe(struct platform_device *pdev)
Abraham Arcea17f7952010-08-31 17:05:27 -0700240{
Abraham Arcea17f7952010-08-31 17:05:27 -0700241 struct omap4_keypad *keypad_data;
242 struct input_dev *input_dev;
Abraham Arcef3a1ba62010-09-29 23:35:57 -0700243 struct resource *res;
Sourav Poddar13987432012-07-13 00:10:47 -0700244 unsigned int max_keys;
Poddar, Souravf77621c2012-05-10 22:32:00 -0700245 int rev;
Abraham Arcef3a1ba62010-09-29 23:35:57 -0700246 int irq;
Abraham Arcea17f7952010-08-31 17:05:27 -0700247 int error;
248
Abraham Arcef3a1ba62010-09-29 23:35:57 -0700249 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
250 if (!res) {
Abraham Arcea17f7952010-08-31 17:05:27 -0700251 dev_err(&pdev->dev, "no base address specified\n");
252 return -EINVAL;
253 }
254
Abraham Arcef3a1ba62010-09-29 23:35:57 -0700255 irq = platform_get_irq(pdev, 0);
256 if (!irq) {
Abraham Arcea17f7952010-08-31 17:05:27 -0700257 dev_err(&pdev->dev, "no keyboard irq assigned\n");
258 return -EINVAL;
259 }
260
Sourav Poddar13987432012-07-13 00:10:47 -0700261 keypad_data = kzalloc(sizeof(struct omap4_keypad), GFP_KERNEL);
Abraham Arcea17f7952010-08-31 17:05:27 -0700262 if (!keypad_data) {
263 dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
264 return -ENOMEM;
265 }
266
Sourav Poddar13987432012-07-13 00:10:47 -0700267 keypad_data->irq = irq;
Abraham Arcea17f7952010-08-31 17:05:27 -0700268
Joachim Eastwood61721c82014-05-29 00:30:02 -0700269 error = omap4_keypad_parse_dt(&pdev->dev, keypad_data);
270 if (error)
Sudip Mukherjeeb83b1452015-09-28 15:59:22 -0700271 goto err_free_keypad;
Sourav Poddar13987432012-07-13 00:10:47 -0700272
273 res = request_mem_region(res->start, resource_size(res), pdev->name);
Abraham Arcef3a1ba62010-09-29 23:35:57 -0700274 if (!res) {
275 dev_err(&pdev->dev, "can't request mem region\n");
276 error = -EBUSY;
277 goto err_free_keypad;
278 }
279
280 keypad_data->base = ioremap(res->start, resource_size(res));
281 if (!keypad_data->base) {
282 dev_err(&pdev->dev, "can't ioremap mem resource\n");
283 error = -ENOMEM;
284 goto err_release_mem;
285 }
286
Abraham Arcea17f7952010-08-31 17:05:27 -0700287
Poddar, Souravf77621c2012-05-10 22:32:00 -0700288 /*
Sourav Poddar13987432012-07-13 00:10:47 -0700289 * Enable clocks for the keypad module so that we can read
290 * revision register.
291 */
Poddar, Souravf77621c2012-05-10 22:32:00 -0700292 pm_runtime_enable(&pdev->dev);
293 error = pm_runtime_get_sync(&pdev->dev);
294 if (error) {
295 dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
296 goto err_unmap;
297 }
298 rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
299 rev &= 0x03 << 30;
300 rev >>= 30;
301 switch (rev) {
302 case KBD_REVISION_OMAP4:
303 keypad_data->reg_offset = 0x00;
304 keypad_data->irqreg_offset = 0x00;
305 break;
306 case KBD_REVISION_OMAP5:
307 keypad_data->reg_offset = 0x10;
308 keypad_data->irqreg_offset = 0x0c;
309 break;
310 default:
311 dev_err(&pdev->dev,
312 "Keypad reports unsupported revision %d", rev);
313 error = -EINVAL;
314 goto err_pm_put_sync;
315 }
316
Abraham Arcea17f7952010-08-31 17:05:27 -0700317 /* input device allocation */
318 keypad_data->input = input_dev = input_allocate_device();
319 if (!input_dev) {
320 error = -ENOMEM;
Poddar, Souravf77621c2012-05-10 22:32:00 -0700321 goto err_pm_put_sync;
Abraham Arcea17f7952010-08-31 17:05:27 -0700322 }
323
324 input_dev->name = pdev->name;
325 input_dev->dev.parent = &pdev->dev;
326 input_dev->id.bustype = BUS_HOST;
327 input_dev->id.vendor = 0x0001;
328 input_dev->id.product = 0x0001;
329 input_dev->id.version = 0x0001;
330
Abraham Arce5ad567f2011-02-22 22:25:59 -0800331 input_dev->open = omap4_keypad_open;
332 input_dev->close = omap4_keypad_close;
333
Sourav Poddar13987432012-07-13 00:10:47 -0700334 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
335 if (!keypad_data->no_autorepeat)
336 __set_bit(EV_REP, input_dev->evbit);
337
338 input_set_drvdata(input_dev, keypad_data);
339
340 keypad_data->row_shift = get_count_order(keypad_data->cols);
341 max_keys = keypad_data->rows << keypad_data->row_shift;
Kees Cook6396bb22018-06-12 14:03:40 -0700342 keypad_data->keymap = kcalloc(max_keys,
343 sizeof(keypad_data->keymap[0]),
Sourav Poddar13987432012-07-13 00:10:47 -0700344 GFP_KERNEL);
345 if (!keypad_data->keymap) {
346 dev_err(&pdev->dev, "Not enough memory for keymap\n");
347 error = -ENOMEM;
Dmitry Torokhov19328112012-05-10 22:37:08 -0700348 goto err_free_input;
349 }
Abraham Arcea17f7952010-08-31 17:05:27 -0700350
Joachim Eastwood61721c82014-05-29 00:30:02 -0700351 error = matrix_keypad_build_keymap(NULL, NULL,
Sourav Poddar13987432012-07-13 00:10:47 -0700352 keypad_data->rows, keypad_data->cols,
353 keypad_data->keymap, input_dev);
354 if (error) {
355 dev_err(&pdev->dev, "failed to build keymap\n");
356 goto err_free_keymap;
357 }
Abraham Arcea17f7952010-08-31 17:05:27 -0700358
Illia Smyrnovc683da32013-08-25 23:25:50 -0700359 error = request_threaded_irq(keypad_data->irq, omap4_keypad_irq_handler,
Tony Lindgrene2ca26e2018-12-04 13:52:49 -0800360 omap4_keypad_irq_thread_fn, IRQF_ONESHOT,
Illia Smyrnovc683da32013-08-25 23:25:50 -0700361 "omap4-keypad", keypad_data);
Abraham Arcea17f7952010-08-31 17:05:27 -0700362 if (error) {
363 dev_err(&pdev->dev, "failed to register interrupt\n");
Christophe JAILLET9bb9dc12017-04-10 20:48:16 -0700364 goto err_free_keymap;
Abraham Arcea17f7952010-08-31 17:05:27 -0700365 }
366
Illia Smyrnov78608a02013-08-25 23:29:30 -0700367 device_init_wakeup(&pdev->dev, true);
Poddar, Souravf77621c2012-05-10 22:32:00 -0700368 pm_runtime_put_sync(&pdev->dev);
Abraham Arce5ad567f2011-02-22 22:25:59 -0800369
Abraham Arcea17f7952010-08-31 17:05:27 -0700370 error = input_register_device(keypad_data->input);
371 if (error < 0) {
372 dev_err(&pdev->dev, "failed to register input device\n");
Abraham Arce5ad567f2011-02-22 22:25:59 -0800373 goto err_pm_disable;
Abraham Arcea17f7952010-08-31 17:05:27 -0700374 }
375
Abraham Arcea17f7952010-08-31 17:05:27 -0700376 platform_set_drvdata(pdev, keypad_data);
377 return 0;
378
Abraham Arce5ad567f2011-02-22 22:25:59 -0800379err_pm_disable:
380 pm_runtime_disable(&pdev->dev);
Abraham Arcea17f7952010-08-31 17:05:27 -0700381 free_irq(keypad_data->irq, keypad_data);
Sourav Poddar13987432012-07-13 00:10:47 -0700382err_free_keymap:
383 kfree(keypad_data->keymap);
Abraham Arcea17f7952010-08-31 17:05:27 -0700384err_free_input:
385 input_free_device(input_dev);
Poddar, Souravf77621c2012-05-10 22:32:00 -0700386err_pm_put_sync:
387 pm_runtime_put_sync(&pdev->dev);
Abraham Arcef3a1ba62010-09-29 23:35:57 -0700388err_unmap:
389 iounmap(keypad_data->base);
390err_release_mem:
Sourav Poddar13987432012-07-13 00:10:47 -0700391 release_mem_region(res->start, resource_size(res));
Abraham Arcea17f7952010-08-31 17:05:27 -0700392err_free_keypad:
393 kfree(keypad_data);
394 return error;
395}
396
Bill Pembertone2619cf2012-11-23 21:50:47 -0800397static int omap4_keypad_remove(struct platform_device *pdev)
Abraham Arcea17f7952010-08-31 17:05:27 -0700398{
399 struct omap4_keypad *keypad_data = platform_get_drvdata(pdev);
Abraham Arcef3a1ba62010-09-29 23:35:57 -0700400 struct resource *res;
Abraham Arcea17f7952010-08-31 17:05:27 -0700401
402 free_irq(keypad_data->irq, keypad_data);
Abraham Arce5ad567f2011-02-22 22:25:59 -0800403
404 pm_runtime_disable(&pdev->dev);
405
Abraham Arcea17f7952010-08-31 17:05:27 -0700406 input_unregister_device(keypad_data->input);
Abraham Arcef3a1ba62010-09-29 23:35:57 -0700407
408 iounmap(keypad_data->base);
409
410 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
411 release_mem_region(res->start, resource_size(res));
412
Sourav Poddar13987432012-07-13 00:10:47 -0700413 kfree(keypad_data->keymap);
Abraham Arcea17f7952010-08-31 17:05:27 -0700414 kfree(keypad_data);
Sourav Poddar13987432012-07-13 00:10:47 -0700415
Abraham Arcea17f7952010-08-31 17:05:27 -0700416 return 0;
417}
418
Sourav Poddar13987432012-07-13 00:10:47 -0700419static const struct of_device_id omap_keypad_dt_match[] = {
420 { .compatible = "ti,omap4-keypad" },
421 {},
422};
423MODULE_DEVICE_TABLE(of, omap_keypad_dt_match);
Sourav Poddar13987432012-07-13 00:10:47 -0700424
Illia Smyrnov78608a02013-08-25 23:29:30 -0700425#ifdef CONFIG_PM_SLEEP
426static int omap4_keypad_suspend(struct device *dev)
427{
428 struct platform_device *pdev = to_platform_device(dev);
429 struct omap4_keypad *keypad_data = platform_get_drvdata(pdev);
430 int error;
431
432 if (device_may_wakeup(&pdev->dev)) {
433 error = enable_irq_wake(keypad_data->irq);
434 if (!error)
435 keypad_data->irq_wake_enabled = true;
436 }
437
438 return 0;
439}
440
441static int omap4_keypad_resume(struct device *dev)
442{
443 struct platform_device *pdev = to_platform_device(dev);
444 struct omap4_keypad *keypad_data = platform_get_drvdata(pdev);
445
446 if (device_may_wakeup(&pdev->dev) && keypad_data->irq_wake_enabled) {
447 disable_irq_wake(keypad_data->irq);
448 keypad_data->irq_wake_enabled = false;
449 }
450
451 return 0;
452}
453#endif
454
455static SIMPLE_DEV_PM_OPS(omap4_keypad_pm_ops,
456 omap4_keypad_suspend, omap4_keypad_resume);
457
Abraham Arcea17f7952010-08-31 17:05:27 -0700458static struct platform_driver omap4_keypad_driver = {
459 .probe = omap4_keypad_probe,
Bill Pemberton1cb0aa82012-11-23 21:27:39 -0800460 .remove = omap4_keypad_remove,
Abraham Arcea17f7952010-08-31 17:05:27 -0700461 .driver = {
462 .name = "omap4-keypad",
Illia Smyrnov78608a02013-08-25 23:29:30 -0700463 .pm = &omap4_keypad_pm_ops,
Joachim Eastwood61721c82014-05-29 00:30:02 -0700464 .of_match_table = omap_keypad_dt_match,
Abraham Arcea17f7952010-08-31 17:05:27 -0700465 },
466};
JJ Ding5146c842011-11-29 11:08:39 -0800467module_platform_driver(omap4_keypad_driver);
Abraham Arcea17f7952010-08-31 17:05:27 -0700468
469MODULE_AUTHOR("Texas Instruments");
470MODULE_DESCRIPTION("OMAP4 Keypad Driver");
471MODULE_LICENSE("GPL");
472MODULE_ALIAS("platform:omap4-keypad");