aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/keyboard
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/keyboard')
-rw-r--r--drivers/input/keyboard/Kconfig10
-rw-r--r--drivers/input/keyboard/Makefile1
-rw-r--r--drivers/input/keyboard/gpio_keys.c1
-rw-r--r--drivers/input/keyboard/imx_keypad.c25
-rw-r--r--drivers/input/keyboard/lpc32xx-keys.c394
-rw-r--r--drivers/input/keyboard/nomadik-ske-keypad.c76
-rw-r--r--drivers/input/keyboard/omap4-keypad.c127
-rw-r--r--drivers/input/keyboard/spear-keyboard.c137
8 files changed, 649 insertions, 122 deletions
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index c0e11ecc646f..c50fa75416f8 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -332,6 +332,16 @@ config KEYBOARD_LOCOMO
332 To compile this driver as a module, choose M here: the 332 To compile this driver as a module, choose M here: the
333 module will be called locomokbd. 333 module will be called locomokbd.
334 334
335config KEYBOARD_LPC32XX
336 tristate "LPC32XX matrix key scanner support"
337 depends on ARCH_LPC32XX && OF
338 help
339 Say Y here if you want to use NXP LPC32XX SoC key scanner interface,
340 connected to a key matrix.
341
342 To compile this driver as a module, choose M here: the
343 module will be called lpc32xx-keys.
344
335config KEYBOARD_MAPLE 345config KEYBOARD_MAPLE
336 tristate "Maple bus keyboard" 346 tristate "Maple bus keyboard"
337 depends on SH_DREAMCAST && MAPLE 347 depends on SH_DREAMCAST && MAPLE
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index b03b02456a82..44e76002f54b 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_KEYBOARD_LKKBD) += lkkbd.o
26obj-$(CONFIG_KEYBOARD_LM8323) += lm8323.o 26obj-$(CONFIG_KEYBOARD_LM8323) += lm8323.o
27obj-$(CONFIG_KEYBOARD_LM8333) += lm8333.o 27obj-$(CONFIG_KEYBOARD_LM8333) += lm8333.o
28obj-$(CONFIG_KEYBOARD_LOCOMO) += locomokbd.o 28obj-$(CONFIG_KEYBOARD_LOCOMO) += locomokbd.o
29obj-$(CONFIG_KEYBOARD_LPC32XX) += lpc32xx-keys.o
29obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o 30obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o
30obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o 31obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o
31obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o 32obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 62bfce468f9f..cbb1add43d5e 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -559,7 +559,6 @@ static int gpio_keys_get_devtree_pdata(struct device *dev,
559 pdata->rep = !!of_get_property(node, "autorepeat", NULL); 559 pdata->rep = !!of_get_property(node, "autorepeat", NULL);
560 560
561 /* First count the subnodes */ 561 /* First count the subnodes */
562 pdata->nbuttons = 0;
563 pp = NULL; 562 pp = NULL;
564 while ((pp = of_get_next_child(node, pp))) 563 while ((pp = of_get_next_child(node, pp)))
565 pdata->nbuttons++; 564 pdata->nbuttons++;
diff --git a/drivers/input/keyboard/imx_keypad.c b/drivers/input/keyboard/imx_keypad.c
index 6ee7421e2321..ff4c0a87a25f 100644
--- a/drivers/input/keyboard/imx_keypad.c
+++ b/drivers/input/keyboard/imx_keypad.c
@@ -378,20 +378,24 @@ static void imx_keypad_close(struct input_dev *dev)
378 imx_keypad_inhibit(keypad); 378 imx_keypad_inhibit(keypad);
379 379
380 /* Disable clock unit */ 380 /* Disable clock unit */
381 clk_disable(keypad->clk); 381 clk_disable_unprepare(keypad->clk);
382} 382}
383 383
384static int imx_keypad_open(struct input_dev *dev) 384static int imx_keypad_open(struct input_dev *dev)
385{ 385{
386 struct imx_keypad *keypad = input_get_drvdata(dev); 386 struct imx_keypad *keypad = input_get_drvdata(dev);
387 int error;
387 388
388 dev_dbg(&dev->dev, ">%s\n", __func__); 389 dev_dbg(&dev->dev, ">%s\n", __func__);
389 390
391 /* Enable the kpp clock */
392 error = clk_prepare_enable(keypad->clk);
393 if (error)
394 return error;
395
390 /* We became active from now */ 396 /* We became active from now */
391 keypad->enabled = true; 397 keypad->enabled = true;
392 398
393 /* Enable the kpp clock */
394 clk_enable(keypad->clk);
395 imx_keypad_config(keypad); 399 imx_keypad_config(keypad);
396 400
397 /* Sanity control, not all the rows must be actived now. */ 401 /* Sanity control, not all the rows must be actived now. */
@@ -467,7 +471,7 @@ static int __devinit imx_keypad_probe(struct platform_device *pdev)
467 goto failed_free_priv; 471 goto failed_free_priv;
468 } 472 }
469 473
470 keypad->clk = clk_get(&pdev->dev, "kpp"); 474 keypad->clk = clk_get(&pdev->dev, NULL);
471 if (IS_ERR(keypad->clk)) { 475 if (IS_ERR(keypad->clk)) {
472 dev_err(&pdev->dev, "failed to get keypad clock\n"); 476 dev_err(&pdev->dev, "failed to get keypad clock\n");
473 error = PTR_ERR(keypad->clk); 477 error = PTR_ERR(keypad->clk);
@@ -581,7 +585,7 @@ static int imx_kbd_suspend(struct device *dev)
581 mutex_lock(&input_dev->mutex); 585 mutex_lock(&input_dev->mutex);
582 586
583 if (input_dev->users) 587 if (input_dev->users)
584 clk_disable(kbd->clk); 588 clk_disable_unprepare(kbd->clk);
585 589
586 mutex_unlock(&input_dev->mutex); 590 mutex_unlock(&input_dev->mutex);
587 591
@@ -596,18 +600,23 @@ static int imx_kbd_resume(struct device *dev)
596 struct platform_device *pdev = to_platform_device(dev); 600 struct platform_device *pdev = to_platform_device(dev);
597 struct imx_keypad *kbd = platform_get_drvdata(pdev); 601 struct imx_keypad *kbd = platform_get_drvdata(pdev);
598 struct input_dev *input_dev = kbd->input_dev; 602 struct input_dev *input_dev = kbd->input_dev;
603 int ret = 0;
599 604
600 if (device_may_wakeup(&pdev->dev)) 605 if (device_may_wakeup(&pdev->dev))
601 disable_irq_wake(kbd->irq); 606 disable_irq_wake(kbd->irq);
602 607
603 mutex_lock(&input_dev->mutex); 608 mutex_lock(&input_dev->mutex);
604 609
605 if (input_dev->users) 610 if (input_dev->users) {
606 clk_enable(kbd->clk); 611 ret = clk_prepare_enable(kbd->clk);
612 if (ret)
613 goto err_clk;
614 }
607 615
616err_clk:
608 mutex_unlock(&input_dev->mutex); 617 mutex_unlock(&input_dev->mutex);
609 618
610 return 0; 619 return ret;
611} 620}
612#endif 621#endif
613 622
diff --git a/drivers/input/keyboard/lpc32xx-keys.c b/drivers/input/keyboard/lpc32xx-keys.c
new file mode 100644
index 000000000000..dd786c8a7584
--- /dev/null
+++ b/drivers/input/keyboard/lpc32xx-keys.c
@@ -0,0 +1,394 @@
1/*
2 * NXP LPC32xx SoC Key Scan Interface
3 *
4 * Authors:
5 * Kevin Wells <kevin.wells@nxp.com>
6 * Roland Stigge <stigge@antcom.de>
7 *
8 * Copyright (C) 2010 NXP Semiconductors
9 * Copyright (C) 2012 Roland Stigge
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 *
22 * This controller supports square key matrices from 1x1 up to 8x8
23 */
24
25#include <linux/module.h>
26#include <linux/interrupt.h>
27#include <linux/slab.h>
28#include <linux/irq.h>
29#include <linux/pm.h>
30#include <linux/platform_device.h>
31#include <linux/input.h>
32#include <linux/clk.h>
33#include <linux/io.h>
34#include <linux/of.h>
35#include <linux/input/matrix_keypad.h>
36
37#define DRV_NAME "lpc32xx_keys"
38
39/*
40 * Key scanner register offsets
41 */
42#define LPC32XX_KS_DEB(x) ((x) + 0x00)
43#define LPC32XX_KS_STATE_COND(x) ((x) + 0x04)
44#define LPC32XX_KS_IRQ(x) ((x) + 0x08)
45#define LPC32XX_KS_SCAN_CTL(x) ((x) + 0x0C)
46#define LPC32XX_KS_FAST_TST(x) ((x) + 0x10)
47#define LPC32XX_KS_MATRIX_DIM(x) ((x) + 0x14) /* 1..8 */
48#define LPC32XX_KS_DATA(x, y) ((x) + 0x40 + ((y) << 2))
49
50#define LPC32XX_KSCAN_DEB_NUM_DEB_PASS(n) ((n) & 0xFF)
51
52#define LPC32XX_KSCAN_SCOND_IN_IDLE 0x0
53#define LPC32XX_KSCAN_SCOND_IN_SCANONCE 0x1
54#define LPC32XX_KSCAN_SCOND_IN_IRQGEN 0x2
55#define LPC32XX_KSCAN_SCOND_IN_SCAN_MATRIX 0x3
56
57#define LPC32XX_KSCAN_IRQ_PENDING_CLR 0x1
58
59#define LPC32XX_KSCAN_SCTRL_SCAN_DELAY(n) ((n) & 0xFF)
60
61#define LPC32XX_KSCAN_FTST_FORCESCANONCE 0x1
62#define LPC32XX_KSCAN_FTST_USE32K_CLK 0x2
63
64#define LPC32XX_KSCAN_MSEL_SELECT(n) ((n) & 0xF)
65
66struct lpc32xx_kscan_drv {
67 struct input_dev *input;
68 struct clk *clk;
69 struct resource *iores;
70 void __iomem *kscan_base;
71 unsigned int irq;
72
73 u32 matrix_sz; /* Size of matrix in XxY, ie. 3 = 3x3 */
74 u32 deb_clks; /* Debounce clocks (based on 32KHz clock) */
75 u32 scan_delay; /* Scan delay (based on 32KHz clock) */
76
77 unsigned short *keymap; /* Pointer to key map for the scan matrix */
78 unsigned int row_shift;
79
80 u8 lastkeystates[8];
81};
82
83static void lpc32xx_mod_states(struct lpc32xx_kscan_drv *kscandat, int col)
84{
85 struct input_dev *input = kscandat->input;
86 unsigned row, changed, scancode, keycode;
87 u8 key;
88
89 key = readl(LPC32XX_KS_DATA(kscandat->kscan_base, col));
90 changed = key ^ kscandat->lastkeystates[col];
91 kscandat->lastkeystates[col] = key;
92
93 for (row = 0; changed; row++, changed >>= 1) {
94 if (changed & 1) {
95 /* Key state changed, signal an event */
96 scancode = MATRIX_SCAN_CODE(row, col,
97 kscandat->row_shift);
98 keycode = kscandat->keymap[scancode];
99 input_event(input, EV_MSC, MSC_SCAN, scancode);
100 input_report_key(input, keycode, key & (1 << row));
101 }
102 }
103}
104
105static irqreturn_t lpc32xx_kscan_irq(int irq, void *dev_id)
106{
107 struct lpc32xx_kscan_drv *kscandat = dev_id;
108 int i;
109
110 for (i = 0; i < kscandat->matrix_sz; i++)
111 lpc32xx_mod_states(kscandat, i);
112
113 writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
114
115 input_sync(kscandat->input);
116
117 return IRQ_HANDLED;
118}
119
120static int lpc32xx_kscan_open(struct input_dev *dev)
121{
122 struct lpc32xx_kscan_drv *kscandat = input_get_drvdata(dev);
123 int error;
124
125 error = clk_prepare_enable(kscandat->clk);
126 if (error)
127 return error;
128
129 writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
130
131 return 0;
132}
133
134static void lpc32xx_kscan_close(struct input_dev *dev)
135{
136 struct lpc32xx_kscan_drv *kscandat = input_get_drvdata(dev);
137
138 writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
139 clk_disable_unprepare(kscandat->clk);
140}
141
142static int __devinit lpc32xx_parse_dt(struct device *dev,
143 struct lpc32xx_kscan_drv *kscandat)
144{
145 struct device_node *np = dev->of_node;
146 u32 rows = 0, columns = 0;
147
148 of_property_read_u32(np, "keypad,num-rows", &rows);
149 of_property_read_u32(np, "keypad,num-columns", &columns);
150 if (!rows || rows != columns) {
151 dev_err(dev,
152 "rows and columns must be specified and be equal!\n");
153 return -EINVAL;
154 }
155
156 kscandat->matrix_sz = rows;
157 kscandat->row_shift = get_count_order(columns);
158
159 of_property_read_u32(np, "nxp,debounce-delay-ms", &kscandat->deb_clks);
160 of_property_read_u32(np, "nxp,scan-delay-ms", &kscandat->scan_delay);
161 if (!kscandat->deb_clks || !kscandat->scan_delay) {
162 dev_err(dev, "debounce or scan delay not specified\n");
163 return -EINVAL;
164 }
165
166 return 0;
167}
168
169static int __devinit lpc32xx_kscan_probe(struct platform_device *pdev)
170{
171 struct lpc32xx_kscan_drv *kscandat;
172 struct input_dev *input;
173 struct resource *res;
174 size_t keymap_size;
175 int error;
176 int irq;
177
178 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
179 if (!res) {
180 dev_err(&pdev->dev, "failed to get platform I/O memory\n");
181 return -EINVAL;
182 }
183
184 irq = platform_get_irq(pdev, 0);
185 if (irq < 0 || irq >= NR_IRQS) {
186 dev_err(&pdev->dev, "failed to get platform irq\n");
187 return -EINVAL;
188 }
189
190 kscandat = kzalloc(sizeof(struct lpc32xx_kscan_drv), GFP_KERNEL);
191 if (!kscandat) {
192 dev_err(&pdev->dev, "failed to allocate memory\n");
193 return -ENOMEM;
194 }
195
196 error = lpc32xx_parse_dt(&pdev->dev, kscandat);
197 if (error) {
198 dev_err(&pdev->dev, "failed to parse device tree\n");
199 goto err_free_mem;
200 }
201
202 keymap_size = sizeof(kscandat->keymap[0]) *
203 (kscandat->matrix_sz << kscandat->row_shift);
204 kscandat->keymap = kzalloc(keymap_size, GFP_KERNEL);
205 if (!kscandat->keymap) {
206 dev_err(&pdev->dev, "could not allocate memory for keymap\n");
207 error = -ENOMEM;
208 goto err_free_mem;
209 }
210
211 kscandat->input = input = input_allocate_device();
212 if (!input) {
213 dev_err(&pdev->dev, "failed to allocate input device\n");
214 error = -ENOMEM;
215 goto err_free_keymap;
216 }
217
218 /* Setup key input */
219 input->name = pdev->name;
220 input->phys = "lpc32xx/input0";
221 input->id.vendor = 0x0001;
222 input->id.product = 0x0001;
223 input->id.version = 0x0100;
224 input->open = lpc32xx_kscan_open;
225 input->close = lpc32xx_kscan_close;
226 input->dev.parent = &pdev->dev;
227
228 input_set_capability(input, EV_MSC, MSC_SCAN);
229
230 error = matrix_keypad_build_keymap(NULL, NULL,
231 kscandat->matrix_sz,
232 kscandat->matrix_sz,
233 kscandat->keymap, kscandat->input);
234 if (error) {
235 dev_err(&pdev->dev, "failed to build keymap\n");
236 goto err_free_input;
237 }
238
239 input_set_drvdata(kscandat->input, kscandat);
240
241 kscandat->iores = request_mem_region(res->start, resource_size(res),
242 pdev->name);
243 if (!kscandat->iores) {
244 dev_err(&pdev->dev, "failed to request I/O memory\n");
245 error = -EBUSY;
246 goto err_free_input;
247 }
248
249 kscandat->kscan_base = ioremap(kscandat->iores->start,
250 resource_size(kscandat->iores));
251 if (!kscandat->kscan_base) {
252 dev_err(&pdev->dev, "failed to remap I/O memory\n");
253 error = -EBUSY;
254 goto err_release_memregion;
255 }
256
257 /* Get the key scanner clock */
258 kscandat->clk = clk_get(&pdev->dev, NULL);
259 if (IS_ERR(kscandat->clk)) {
260 dev_err(&pdev->dev, "failed to get clock\n");
261 error = PTR_ERR(kscandat->clk);
262 goto err_unmap;
263 }
264
265 /* Configure the key scanner */
266 error = clk_prepare_enable(kscandat->clk);
267 if (error)
268 goto err_clk_put;
269
270 writel(kscandat->deb_clks, LPC32XX_KS_DEB(kscandat->kscan_base));
271 writel(kscandat->scan_delay, LPC32XX_KS_SCAN_CTL(kscandat->kscan_base));
272 writel(LPC32XX_KSCAN_FTST_USE32K_CLK,
273 LPC32XX_KS_FAST_TST(kscandat->kscan_base));
274 writel(kscandat->matrix_sz,
275 LPC32XX_KS_MATRIX_DIM(kscandat->kscan_base));
276 writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
277 clk_disable_unprepare(kscandat->clk);
278
279 error = request_irq(irq, lpc32xx_kscan_irq, 0, pdev->name, kscandat);
280 if (error) {
281 dev_err(&pdev->dev, "failed to request irq\n");
282 goto err_clk_put;
283 }
284
285 error = input_register_device(kscandat->input);
286 if (error) {
287 dev_err(&pdev->dev, "failed to register input device\n");
288 goto err_free_irq;
289 }
290
291 platform_set_drvdata(pdev, kscandat);
292 return 0;
293
294err_free_irq:
295 free_irq(irq, kscandat);
296err_clk_put:
297 clk_put(kscandat->clk);
298err_unmap:
299 iounmap(kscandat->kscan_base);
300err_release_memregion:
301 release_mem_region(kscandat->iores->start,
302 resource_size(kscandat->iores));
303err_free_input:
304 input_free_device(kscandat->input);
305err_free_keymap:
306 kfree(kscandat->keymap);
307err_free_mem:
308 kfree(kscandat);
309
310 return error;
311}
312
313static int __devexit lpc32xx_kscan_remove(struct platform_device *pdev)
314{
315 struct lpc32xx_kscan_drv *kscandat = platform_get_drvdata(pdev);
316
317 free_irq(platform_get_irq(pdev, 0), kscandat);
318 clk_put(kscandat->clk);
319 iounmap(kscandat->kscan_base);
320 release_mem_region(kscandat->iores->start,
321 resource_size(kscandat->iores));
322 input_unregister_device(kscandat->input);
323 kfree(kscandat->keymap);
324 kfree(kscandat);
325
326 return 0;
327}
328
329#ifdef CONFIG_PM_SLEEP
330static int lpc32xx_kscan_suspend(struct device *dev)
331{
332 struct platform_device *pdev = to_platform_device(dev);
333 struct lpc32xx_kscan_drv *kscandat = platform_get_drvdata(pdev);
334 struct input_dev *input = kscandat->input;
335
336 mutex_lock(&input->mutex);
337
338 if (input->users) {
339 /* Clear IRQ and disable clock */
340 writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
341 clk_disable_unprepare(kscandat->clk);
342 }
343
344 mutex_unlock(&input->mutex);
345 return 0;
346}
347
348static int lpc32xx_kscan_resume(struct device *dev)
349{
350 struct platform_device *pdev = to_platform_device(dev);
351 struct lpc32xx_kscan_drv *kscandat = platform_get_drvdata(pdev);
352 struct input_dev *input = kscandat->input;
353 int retval = 0;
354
355 mutex_lock(&input->mutex);
356
357 if (input->users) {
358 /* Enable clock and clear IRQ */
359 retval = clk_prepare_enable(kscandat->clk);
360 if (retval == 0)
361 writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
362 }
363
364 mutex_unlock(&input->mutex);
365 return retval;
366}
367#endif
368
369static SIMPLE_DEV_PM_OPS(lpc32xx_kscan_pm_ops, lpc32xx_kscan_suspend,
370 lpc32xx_kscan_resume);
371
372static const struct of_device_id lpc32xx_kscan_match[] = {
373 { .compatible = "nxp,lpc3220-key" },
374 {},
375};
376MODULE_DEVICE_TABLE(of, lpc32xx_kscan_match);
377
378static struct platform_driver lpc32xx_kscan_driver = {
379 .probe = lpc32xx_kscan_probe,
380 .remove = __devexit_p(lpc32xx_kscan_remove),
381 .driver = {
382 .name = DRV_NAME,
383 .owner = THIS_MODULE,
384 .pm = &lpc32xx_kscan_pm_ops,
385 .of_match_table = of_match_ptr(lpc32xx_kscan_match),
386 }
387};
388
389module_platform_driver(lpc32xx_kscan_driver);
390
391MODULE_LICENSE("GPL");
392MODULE_AUTHOR("Kevin Wells <kevin.wells@nxp.com>");
393MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
394MODULE_DESCRIPTION("Key scanner driver for LPC32XX devices");
diff --git a/drivers/input/keyboard/nomadik-ske-keypad.c b/drivers/input/keyboard/nomadik-ske-keypad.c
index 4ea4341a68c5..a880e7414202 100644
--- a/drivers/input/keyboard/nomadik-ske-keypad.c
+++ b/drivers/input/keyboard/nomadik-ske-keypad.c
@@ -49,6 +49,7 @@
49#define SKE_ASR3 0x2C 49#define SKE_ASR3 0x2C
50 50
51#define SKE_NUM_ASRX_REGISTERS (4) 51#define SKE_NUM_ASRX_REGISTERS (4)
52#define KEY_PRESSED_DELAY 10
52 53
53/** 54/**
54 * struct ske_keypad - data structure used by keypad driver 55 * struct ske_keypad - data structure used by keypad driver
@@ -92,7 +93,7 @@ static void ske_keypad_set_bits(struct ske_keypad *keypad, u16 addr,
92static int __init ske_keypad_chip_init(struct ske_keypad *keypad) 93static int __init ske_keypad_chip_init(struct ske_keypad *keypad)
93{ 94{
94 u32 value; 95 u32 value;
95 int timeout = 50; 96 int timeout = keypad->board->debounce_ms;
96 97
97 /* check SKE_RIS to be 0 */ 98 /* check SKE_RIS to be 0 */
98 while ((readl(keypad->reg_base + SKE_RIS) != 0x00000000) && timeout--) 99 while ((readl(keypad->reg_base + SKE_RIS) != 0x00000000) && timeout--)
@@ -135,12 +136,37 @@ static int __init ske_keypad_chip_init(struct ske_keypad *keypad)
135 return 0; 136 return 0;
136} 137}
137 138
138static void ske_keypad_read_data(struct ske_keypad *keypad) 139static void ske_keypad_report(struct ske_keypad *keypad, u8 status, int col)
139{ 140{
141 int row = 0, code, pos;
140 struct input_dev *input = keypad->input; 142 struct input_dev *input = keypad->input;
141 u16 status; 143 u32 ske_ris;
142 int col = 0, row = 0, code; 144 int key_pressed;
143 int ske_asr, ske_ris, key_pressed, i; 145 int num_of_rows;
146
147 /* find out the row */
148 num_of_rows = hweight8(status);
149 do {
150 pos = __ffs(status);
151 row = pos;
152 status &= ~(1 << pos);
153
154 code = MATRIX_SCAN_CODE(row, col, SKE_KEYPAD_ROW_SHIFT);
155 ske_ris = readl(keypad->reg_base + SKE_RIS);
156 key_pressed = ske_ris & SKE_KPRISA;
157
158 input_event(input, EV_MSC, MSC_SCAN, code);
159 input_report_key(input, keypad->keymap[code], key_pressed);
160 input_sync(input);
161 num_of_rows--;
162 } while (num_of_rows);
163}
164
165static void ske_keypad_read_data(struct ske_keypad *keypad)
166{
167 u8 status;
168 int col = 0;
169 int ske_asr, i;
144 170
145 /* 171 /*
146 * Read the auto scan registers 172 * Read the auto scan registers
@@ -154,44 +180,38 @@ static void ske_keypad_read_data(struct ske_keypad *keypad)
154 if (!ske_asr) 180 if (!ske_asr)
155 continue; 181 continue;
156 182
157 /* now that ASRx is zero, find out the column x and row y*/ 183 /* now that ASRx is zero, find out the coloumn x and row y */
158 if (ske_asr & 0xff) { 184 status = ske_asr & 0xff;
185 if (status) {
159 col = i * 2; 186 col = i * 2;
160 status = ske_asr & 0xff; 187 ske_keypad_report(keypad, status, col);
161 } else { 188 }
189 status = (ske_asr & 0xff00) >> 8;
190 if (status) {
162 col = (i * 2) + 1; 191 col = (i * 2) + 1;
163 status = (ske_asr & 0xff00) >> 8; 192 ske_keypad_report(keypad, status, col);
164 } 193 }
165
166 /* find out the row */
167 row = __ffs(status);
168
169 code = MATRIX_SCAN_CODE(row, col, SKE_KEYPAD_ROW_SHIFT);
170 ske_ris = readl(keypad->reg_base + SKE_RIS);
171 key_pressed = ske_ris & SKE_KPRISA;
172
173 input_event(input, EV_MSC, MSC_SCAN, code);
174 input_report_key(input, keypad->keymap[code], key_pressed);
175 input_sync(input);
176 } 194 }
177} 195}
178 196
179static irqreturn_t ske_keypad_irq(int irq, void *dev_id) 197static irqreturn_t ske_keypad_irq(int irq, void *dev_id)
180{ 198{
181 struct ske_keypad *keypad = dev_id; 199 struct ske_keypad *keypad = dev_id;
182 int retries = 20; 200 int timeout = keypad->board->debounce_ms;
183 201
184 /* disable auto scan interrupt; mask the interrupt generated */ 202 /* disable auto scan interrupt; mask the interrupt generated */
185 ske_keypad_set_bits(keypad, SKE_IMSC, ~SKE_KPIMA, 0x0); 203 ske_keypad_set_bits(keypad, SKE_IMSC, ~SKE_KPIMA, 0x0);
186 ske_keypad_set_bits(keypad, SKE_ICR, 0x0, SKE_KPICA); 204 ske_keypad_set_bits(keypad, SKE_ICR, 0x0, SKE_KPICA);
187 205
188 while ((readl(keypad->reg_base + SKE_CR) & SKE_KPASON) && --retries) 206 while ((readl(keypad->reg_base + SKE_CR) & SKE_KPASON) && --timeout)
189 msleep(5); 207 cpu_relax();
190 208
191 if (retries) { 209 /* SKEx registers are stable and can be read */
192 /* SKEx registers are stable and can be read */ 210 ske_keypad_read_data(keypad);
193 ske_keypad_read_data(keypad); 211
194 } 212 /* wait until raw interrupt is clear */
213 while ((readl(keypad->reg_base + SKE_RIS)) && --timeout)
214 msleep(KEY_PRESSED_DELAY);
195 215
196 /* enable auto scan interrupts */ 216 /* enable auto scan interrupts */
197 ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA); 217 ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA);
diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
index aed5f6999ce2..c05f98c41410 100644
--- a/drivers/input/keyboard/omap4-keypad.c
+++ b/drivers/input/keyboard/omap4-keypad.c
@@ -27,6 +27,7 @@
27#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28#include <linux/errno.h> 28#include <linux/errno.h>
29#include <linux/io.h> 29#include <linux/io.h>
30#include <linux/of.h>
30#include <linux/input.h> 31#include <linux/input.h>
31#include <linux/slab.h> 32#include <linux/slab.h>
32#include <linux/pm_runtime.h> 33#include <linux/pm_runtime.h>
@@ -84,8 +85,9 @@ struct omap4_keypad {
84 u32 reg_offset; 85 u32 reg_offset;
85 u32 irqreg_offset; 86 u32 irqreg_offset;
86 unsigned int row_shift; 87 unsigned int row_shift;
88 bool no_autorepeat;
87 unsigned char key_state[8]; 89 unsigned char key_state[8];
88 unsigned short keymap[]; 90 unsigned short *keymap;
89}; 91};
90 92
91static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset) 93static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
@@ -208,25 +210,51 @@ static void omap4_keypad_close(struct input_dev *input)
208 pm_runtime_put_sync(input->dev.parent); 210 pm_runtime_put_sync(input->dev.parent);
209} 211}
210 212
213#ifdef CONFIG_OF
214static int __devinit omap4_keypad_parse_dt(struct device *dev,
215 struct omap4_keypad *keypad_data)
216{
217 struct device_node *np = dev->of_node;
218
219 if (!np) {
220 dev_err(dev, "missing DT data");
221 return -EINVAL;
222 }
223
224 of_property_read_u32(np, "keypad,num-rows", &keypad_data->rows);
225 of_property_read_u32(np, "keypad,num-columns", &keypad_data->cols);
226 if (!keypad_data->rows || !keypad_data->cols) {
227 dev_err(dev, "number of keypad rows/columns not specified\n");
228 return -EINVAL;
229 }
230
231 if (of_get_property(np, "linux,input-no-autorepeat", NULL))
232 keypad_data->no_autorepeat = true;
233
234 return 0;
235}
236#else
237static inline int omap4_keypad_parse_dt(struct device *dev,
238 struct omap4_keypad *keypad_data)
239{
240 return -ENOSYS;
241}
242#endif
243
211static int __devinit omap4_keypad_probe(struct platform_device *pdev) 244static int __devinit omap4_keypad_probe(struct platform_device *pdev)
212{ 245{
213 const struct omap4_keypad_platform_data *pdata; 246 const struct omap4_keypad_platform_data *pdata =
247 dev_get_platdata(&pdev->dev);
248 const struct matrix_keymap_data *keymap_data =
249 pdata ? pdata->keymap_data : NULL;
214 struct omap4_keypad *keypad_data; 250 struct omap4_keypad *keypad_data;
215 struct input_dev *input_dev; 251 struct input_dev *input_dev;
216 struct resource *res; 252 struct resource *res;
217 resource_size_t size; 253 unsigned int max_keys;
218 unsigned int row_shift, max_keys;
219 int rev; 254 int rev;
220 int irq; 255 int irq;
221 int error; 256 int error;
222 257
223 /* platform data */
224 pdata = pdev->dev.platform_data;
225 if (!pdata) {
226 dev_err(&pdev->dev, "no platform data defined\n");
227 return -EINVAL;
228 }
229
230 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 258 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
231 if (!res) { 259 if (!res) {
232 dev_err(&pdev->dev, "no base address specified\n"); 260 dev_err(&pdev->dev, "no base address specified\n");
@@ -239,25 +267,24 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
239 return -EINVAL; 267 return -EINVAL;
240 } 268 }
241 269
242 if (!pdata->keymap_data) { 270 keypad_data = kzalloc(sizeof(struct omap4_keypad), GFP_KERNEL);
243 dev_err(&pdev->dev, "no keymap data defined\n");
244 return -EINVAL;
245 }
246
247 row_shift = get_count_order(pdata->cols);
248 max_keys = pdata->rows << row_shift;
249
250 keypad_data = kzalloc(sizeof(struct omap4_keypad) +
251 max_keys * sizeof(keypad_data->keymap[0]),
252 GFP_KERNEL);
253 if (!keypad_data) { 271 if (!keypad_data) {
254 dev_err(&pdev->dev, "keypad_data memory allocation failed\n"); 272 dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
255 return -ENOMEM; 273 return -ENOMEM;
256 } 274 }
257 275
258 size = resource_size(res); 276 keypad_data->irq = irq;
277
278 if (pdata) {
279 keypad_data->rows = pdata->rows;
280 keypad_data->cols = pdata->cols;
281 } else {
282 error = omap4_keypad_parse_dt(&pdev->dev, keypad_data);
283 if (error)
284 return error;
285 }
259 286
260 res = request_mem_region(res->start, size, pdev->name); 287 res = request_mem_region(res->start, resource_size(res), pdev->name);
261 if (!res) { 288 if (!res) {
262 dev_err(&pdev->dev, "can't request mem region\n"); 289 dev_err(&pdev->dev, "can't request mem region\n");
263 error = -EBUSY; 290 error = -EBUSY;
@@ -271,15 +298,11 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
271 goto err_release_mem; 298 goto err_release_mem;
272 } 299 }
273 300
274 keypad_data->irq = irq;
275 keypad_data->row_shift = row_shift;
276 keypad_data->rows = pdata->rows;
277 keypad_data->cols = pdata->cols;
278 301
279 /* 302 /*
280 * Enable clocks for the keypad module so that we can read 303 * Enable clocks for the keypad module so that we can read
281 * revision register. 304 * revision register.
282 */ 305 */
283 pm_runtime_enable(&pdev->dev); 306 pm_runtime_enable(&pdev->dev);
284 error = pm_runtime_get_sync(&pdev->dev); 307 error = pm_runtime_get_sync(&pdev->dev);
285 if (error) { 308 if (error) {
@@ -322,19 +345,30 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
322 input_dev->open = omap4_keypad_open; 345 input_dev->open = omap4_keypad_open;
323 input_dev->close = omap4_keypad_close; 346 input_dev->close = omap4_keypad_close;
324 347
325 error = matrix_keypad_build_keymap(pdata->keymap_data, NULL, 348 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
326 pdata->rows, pdata->cols, 349 if (!keypad_data->no_autorepeat)
350 __set_bit(EV_REP, input_dev->evbit);
351
352 input_set_drvdata(input_dev, keypad_data);
353
354 keypad_data->row_shift = get_count_order(keypad_data->cols);
355 max_keys = keypad_data->rows << keypad_data->row_shift;
356 keypad_data->keymap = kzalloc(max_keys * sizeof(keypad_data->keymap[0]),
357 GFP_KERNEL);
358 if (!keypad_data->keymap) {
359 dev_err(&pdev->dev, "Not enough memory for keymap\n");
360 error = -ENOMEM;
361 goto err_free_input;
362 }
363
364 error = matrix_keypad_build_keymap(keymap_data, NULL,
365 keypad_data->rows, keypad_data->cols,
327 keypad_data->keymap, input_dev); 366 keypad_data->keymap, input_dev);
328 if (error) { 367 if (error) {
329 dev_err(&pdev->dev, "failed to build keymap\n"); 368 dev_err(&pdev->dev, "failed to build keymap\n");
330 goto err_free_input; 369 goto err_free_keymap;
331 } 370 }
332 371
333 __set_bit(EV_REP, input_dev->evbit);
334 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
335
336 input_set_drvdata(input_dev, keypad_data);
337
338 error = request_irq(keypad_data->irq, omap4_keypad_interrupt, 372 error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
339 IRQF_TRIGGER_RISING, 373 IRQF_TRIGGER_RISING,
340 "omap4-keypad", keypad_data); 374 "omap4-keypad", keypad_data);
@@ -357,6 +391,8 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
357err_pm_disable: 391err_pm_disable:
358 pm_runtime_disable(&pdev->dev); 392 pm_runtime_disable(&pdev->dev);
359 free_irq(keypad_data->irq, keypad_data); 393 free_irq(keypad_data->irq, keypad_data);
394err_free_keymap:
395 kfree(keypad_data->keymap);
360err_free_input: 396err_free_input:
361 input_free_device(input_dev); 397 input_free_device(input_dev);
362err_pm_put_sync: 398err_pm_put_sync:
@@ -364,7 +400,7 @@ err_pm_put_sync:
364err_unmap: 400err_unmap:
365 iounmap(keypad_data->base); 401 iounmap(keypad_data->base);
366err_release_mem: 402err_release_mem:
367 release_mem_region(res->start, size); 403 release_mem_region(res->start, resource_size(res));
368err_free_keypad: 404err_free_keypad:
369 kfree(keypad_data); 405 kfree(keypad_data);
370 return error; 406 return error;
@@ -386,18 +422,29 @@ static int __devexit omap4_keypad_remove(struct platform_device *pdev)
386 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 422 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
387 release_mem_region(res->start, resource_size(res)); 423 release_mem_region(res->start, resource_size(res));
388 424
425 kfree(keypad_data->keymap);
389 kfree(keypad_data); 426 kfree(keypad_data);
427
390 platform_set_drvdata(pdev, NULL); 428 platform_set_drvdata(pdev, NULL);
391 429
392 return 0; 430 return 0;
393} 431}
394 432
433#ifdef CONFIG_OF
434static const struct of_device_id omap_keypad_dt_match[] = {
435 { .compatible = "ti,omap4-keypad" },
436 {},
437};
438MODULE_DEVICE_TABLE(of, omap_keypad_dt_match);
439#endif
440
395static struct platform_driver omap4_keypad_driver = { 441static struct platform_driver omap4_keypad_driver = {
396 .probe = omap4_keypad_probe, 442 .probe = omap4_keypad_probe,
397 .remove = __devexit_p(omap4_keypad_remove), 443 .remove = __devexit_p(omap4_keypad_remove),
398 .driver = { 444 .driver = {
399 .name = "omap4-keypad", 445 .name = "omap4-keypad",
400 .owner = THIS_MODULE, 446 .owner = THIS_MODULE,
447 .of_match_table = of_match_ptr(omap_keypad_dt_match),
401 }, 448 },
402}; 449};
403module_platform_driver(omap4_keypad_driver); 450module_platform_driver(omap4_keypad_driver);
diff --git a/drivers/input/keyboard/spear-keyboard.c b/drivers/input/keyboard/spear-keyboard.c
index 6f287f7e1538..72ef01be3360 100644
--- a/drivers/input/keyboard/spear-keyboard.c
+++ b/drivers/input/keyboard/spear-keyboard.c
@@ -27,33 +27,31 @@
27#include <plat/keyboard.h> 27#include <plat/keyboard.h>
28 28
29/* Keyboard Registers */ 29/* Keyboard Registers */
30#define MODE_REG 0x00 /* 16 bit reg */ 30#define MODE_CTL_REG 0x00
31#define STATUS_REG 0x0C /* 2 bit reg */ 31#define STATUS_REG 0x0C
32#define DATA_REG 0x10 /* 8 bit reg */ 32#define DATA_REG 0x10
33#define INTR_MASK 0x54 33#define INTR_MASK 0x54
34 34
35/* Register Values */ 35/* Register Values */
36/*
37 * pclk freq mask = (APB FEQ -1)= 82 MHZ.Programme bit 15-9 in mode
38 * control register as 1010010(82MHZ)
39 */
40#define PCLK_FREQ_MSK 0xA400 /* 82 MHz */
41#define START_SCAN 0x0100
42#define SCAN_RATE_10 0x0000
43#define SCAN_RATE_20 0x0004
44#define SCAN_RATE_40 0x0008
45#define SCAN_RATE_80 0x000C
46#define MODE_KEYBOARD 0x0002
47#define DATA_AVAIL 0x2
48
49#define KEY_MASK 0xFF000000
50#define KEY_VALUE 0x00FFFFFF
51#define ROW_MASK 0xF0
52#define COLUMN_MASK 0x0F
53#define NUM_ROWS 16 36#define NUM_ROWS 16
54#define NUM_COLS 16 37#define NUM_COLS 16
38#define MODE_CTL_PCLK_FREQ_SHIFT 9
39#define MODE_CTL_PCLK_FREQ_MSK 0x7F
40
41#define MODE_CTL_KEYBOARD (0x2 << 0)
42#define MODE_CTL_SCAN_RATE_10 (0x0 << 2)
43#define MODE_CTL_SCAN_RATE_20 (0x1 << 2)
44#define MODE_CTL_SCAN_RATE_40 (0x2 << 2)
45#define MODE_CTL_SCAN_RATE_80 (0x3 << 2)
46#define MODE_CTL_KEYNUM_SHIFT 6
47#define MODE_CTL_START_SCAN (0x1 << 8)
55 48
56#define KEY_MATRIX_SHIFT 6 49#define STATUS_DATA_AVAIL (0x1 << 1)
50
51#define DATA_ROW_MASK 0xF0
52#define DATA_COLUMN_MASK 0x0F
53
54#define ROW_SHIFT 4
57 55
58struct spear_kbd { 56struct spear_kbd {
59 struct input_dev *input; 57 struct input_dev *input;
@@ -65,6 +63,8 @@ struct spear_kbd {
65 unsigned short last_key; 63 unsigned short last_key;
66 unsigned short keycodes[NUM_ROWS * NUM_COLS]; 64 unsigned short keycodes[NUM_ROWS * NUM_COLS];
67 bool rep; 65 bool rep;
66 unsigned int suspended_rate;
67 u32 mode_ctl_reg;
68}; 68};
69 69
70static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id) 70static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id)
@@ -72,10 +72,10 @@ static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id)
72 struct spear_kbd *kbd = dev_id; 72 struct spear_kbd *kbd = dev_id;
73 struct input_dev *input = kbd->input; 73 struct input_dev *input = kbd->input;
74 unsigned int key; 74 unsigned int key;
75 u8 sts, val; 75 u32 sts, val;
76 76
77 sts = readb(kbd->io_base + STATUS_REG); 77 sts = readl_relaxed(kbd->io_base + STATUS_REG);
78 if (!(sts & DATA_AVAIL)) 78 if (!(sts & STATUS_DATA_AVAIL))
79 return IRQ_NONE; 79 return IRQ_NONE;
80 80
81 if (kbd->last_key != KEY_RESERVED) { 81 if (kbd->last_key != KEY_RESERVED) {
@@ -84,7 +84,8 @@ static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id)
84 } 84 }
85 85
86 /* following reads active (row, col) pair */ 86 /* following reads active (row, col) pair */
87 val = readb(kbd->io_base + DATA_REG); 87 val = readl_relaxed(kbd->io_base + DATA_REG) &
88 (DATA_ROW_MASK | DATA_COLUMN_MASK);
88 key = kbd->keycodes[val]; 89 key = kbd->keycodes[val];
89 90
90 input_event(input, EV_MSC, MSC_SCAN, val); 91 input_event(input, EV_MSC, MSC_SCAN, val);
@@ -94,7 +95,7 @@ static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id)
94 kbd->last_key = key; 95 kbd->last_key = key;
95 96
96 /* clear interrupt */ 97 /* clear interrupt */
97 writeb(0, kbd->io_base + STATUS_REG); 98 writel_relaxed(0, kbd->io_base + STATUS_REG);
98 99
99 return IRQ_HANDLED; 100 return IRQ_HANDLED;
100} 101}
@@ -103,7 +104,7 @@ static int spear_kbd_open(struct input_dev *dev)
103{ 104{
104 struct spear_kbd *kbd = input_get_drvdata(dev); 105 struct spear_kbd *kbd = input_get_drvdata(dev);
105 int error; 106 int error;
106 u16 val; 107 u32 val;
107 108
108 kbd->last_key = KEY_RESERVED; 109 kbd->last_key = KEY_RESERVED;
109 110
@@ -111,16 +112,20 @@ static int spear_kbd_open(struct input_dev *dev)
111 if (error) 112 if (error)
112 return error; 113 return error;
113 114
115 /* keyboard rate to be programmed is input clock (in MHz) - 1 */
116 val = clk_get_rate(kbd->clk) / 1000000 - 1;
117 val = (val & MODE_CTL_PCLK_FREQ_MSK) << MODE_CTL_PCLK_FREQ_SHIFT;
118
114 /* program keyboard */ 119 /* program keyboard */
115 val = SCAN_RATE_80 | MODE_KEYBOARD | PCLK_FREQ_MSK | 120 val = MODE_CTL_SCAN_RATE_80 | MODE_CTL_KEYBOARD | val |
116 (kbd->mode << KEY_MATRIX_SHIFT); 121 (kbd->mode << MODE_CTL_KEYNUM_SHIFT);
117 writew(val, kbd->io_base + MODE_REG); 122 writel_relaxed(val, kbd->io_base + MODE_CTL_REG);
118 writeb(1, kbd->io_base + STATUS_REG); 123 writel_relaxed(1, kbd->io_base + STATUS_REG);
119 124
120 /* start key scan */ 125 /* start key scan */
121 val = readw(kbd->io_base + MODE_REG); 126 val = readl_relaxed(kbd->io_base + MODE_CTL_REG);
122 val |= START_SCAN; 127 val |= MODE_CTL_START_SCAN;
123 writew(val, kbd->io_base + MODE_REG); 128 writel_relaxed(val, kbd->io_base + MODE_CTL_REG);
124 129
125 return 0; 130 return 0;
126} 131}
@@ -128,12 +133,12 @@ static int spear_kbd_open(struct input_dev *dev)
128static void spear_kbd_close(struct input_dev *dev) 133static void spear_kbd_close(struct input_dev *dev)
129{ 134{
130 struct spear_kbd *kbd = input_get_drvdata(dev); 135 struct spear_kbd *kbd = input_get_drvdata(dev);
131 u16 val; 136 u32 val;
132 137
133 /* stop key scan */ 138 /* stop key scan */
134 val = readw(kbd->io_base + MODE_REG); 139 val = readl_relaxed(kbd->io_base + MODE_CTL_REG);
135 val &= ~START_SCAN; 140 val &= ~MODE_CTL_START_SCAN;
136 writew(val, kbd->io_base + MODE_REG); 141 writel_relaxed(val, kbd->io_base + MODE_CTL_REG);
137 142
138 clk_disable(kbd->clk); 143 clk_disable(kbd->clk);
139 144
@@ -146,7 +151,7 @@ static int __devinit spear_kbd_parse_dt(struct platform_device *pdev,
146{ 151{
147 struct device_node *np = pdev->dev.of_node; 152 struct device_node *np = pdev->dev.of_node;
148 int error; 153 int error;
149 u32 val; 154 u32 val, suspended_rate;
150 155
151 if (!np) { 156 if (!np) {
152 dev_err(&pdev->dev, "Missing DT data\n"); 157 dev_err(&pdev->dev, "Missing DT data\n");
@@ -156,6 +161,9 @@ static int __devinit spear_kbd_parse_dt(struct platform_device *pdev,
156 if (of_property_read_bool(np, "autorepeat")) 161 if (of_property_read_bool(np, "autorepeat"))
157 kbd->rep = true; 162 kbd->rep = true;
158 163
164 if (of_property_read_u32(np, "suspended_rate", &suspended_rate))
165 kbd->suspended_rate = suspended_rate;
166
159 error = of_property_read_u32(np, "st,mode", &val); 167 error = of_property_read_u32(np, "st,mode", &val);
160 if (error) { 168 if (error) {
161 dev_err(&pdev->dev, "DT: Invalid or missing mode\n"); 169 dev_err(&pdev->dev, "DT: Invalid or missing mode\n");
@@ -213,6 +221,7 @@ static int __devinit spear_kbd_probe(struct platform_device *pdev)
213 } else { 221 } else {
214 kbd->mode = pdata->mode; 222 kbd->mode = pdata->mode;
215 kbd->rep = pdata->rep; 223 kbd->rep = pdata->rep;
224 kbd->suspended_rate = pdata->suspended_rate;
216 } 225 }
217 226
218 kbd->res = request_mem_region(res->start, resource_size(res), 227 kbd->res = request_mem_region(res->start, resource_size(res),
@@ -302,7 +311,7 @@ static int __devexit spear_kbd_remove(struct platform_device *pdev)
302 release_mem_region(kbd->res->start, resource_size(kbd->res)); 311 release_mem_region(kbd->res->start, resource_size(kbd->res));
303 kfree(kbd); 312 kfree(kbd);
304 313
305 device_init_wakeup(&pdev->dev, 1); 314 device_init_wakeup(&pdev->dev, 0);
306 platform_set_drvdata(pdev, NULL); 315 platform_set_drvdata(pdev, NULL);
307 316
308 return 0; 317 return 0;
@@ -314,15 +323,48 @@ static int spear_kbd_suspend(struct device *dev)
314 struct platform_device *pdev = to_platform_device(dev); 323 struct platform_device *pdev = to_platform_device(dev);
315 struct spear_kbd *kbd = platform_get_drvdata(pdev); 324 struct spear_kbd *kbd = platform_get_drvdata(pdev);
316 struct input_dev *input_dev = kbd->input; 325 struct input_dev *input_dev = kbd->input;
326 unsigned int rate = 0, mode_ctl_reg, val;
317 327
318 mutex_lock(&input_dev->mutex); 328 mutex_lock(&input_dev->mutex);
319 329
320 if (input_dev->users) 330 /* explicitly enable clock as we may program device */
321 clk_enable(kbd->clk); 331 clk_enable(kbd->clk);
322 332
323 if (device_may_wakeup(&pdev->dev)) 333 mode_ctl_reg = readl_relaxed(kbd->io_base + MODE_CTL_REG);
334
335 if (device_may_wakeup(&pdev->dev)) {
324 enable_irq_wake(kbd->irq); 336 enable_irq_wake(kbd->irq);
325 337
338 /*
339 * reprogram the keyboard operating frequency as on some
340 * platform it may change during system suspended
341 */
342 if (kbd->suspended_rate)
343 rate = kbd->suspended_rate / 1000000 - 1;
344 else
345 rate = clk_get_rate(kbd->clk) / 1000000 - 1;
346
347 val = mode_ctl_reg &
348 ~(MODE_CTL_PCLK_FREQ_MSK << MODE_CTL_PCLK_FREQ_SHIFT);
349 val |= (rate & MODE_CTL_PCLK_FREQ_MSK)
350 << MODE_CTL_PCLK_FREQ_SHIFT;
351 writel_relaxed(val, kbd->io_base + MODE_CTL_REG);
352
353 } else {
354 if (input_dev->users) {
355 writel_relaxed(mode_ctl_reg & ~MODE_CTL_START_SCAN,
356 kbd->io_base + MODE_CTL_REG);
357 clk_disable(kbd->clk);
358 }
359 }
360
361 /* store current configuration */
362 if (input_dev->users)
363 kbd->mode_ctl_reg = mode_ctl_reg;
364
365 /* restore previous clk state */
366 clk_disable(kbd->clk);
367
326 mutex_unlock(&input_dev->mutex); 368 mutex_unlock(&input_dev->mutex);
327 369
328 return 0; 370 return 0;
@@ -336,11 +378,16 @@ static int spear_kbd_resume(struct device *dev)
336 378
337 mutex_lock(&input_dev->mutex); 379 mutex_lock(&input_dev->mutex);
338 380
339 if (device_may_wakeup(&pdev->dev)) 381 if (device_may_wakeup(&pdev->dev)) {
340 disable_irq_wake(kbd->irq); 382 disable_irq_wake(kbd->irq);
383 } else {
384 if (input_dev->users)
385 clk_enable(kbd->clk);
386 }
341 387
388 /* restore current configuration */
342 if (input_dev->users) 389 if (input_dev->users)
343 clk_enable(kbd->clk); 390 writel_relaxed(kbd->mode_ctl_reg, kbd->io_base + MODE_CTL_REG);
344 391
345 mutex_unlock(&input_dev->mutex); 392 mutex_unlock(&input_dev->mutex);
346 393