Loading...
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * Author: Naveen Kumar G <naveen.gaddipati@stericsson.com> for ST-Ericsson
5 * Author: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
6 *
7 * License terms:GNU General Public License (GPL) version 2
8 *
9 * Keypad controller driver for the SKE (Scroll Key Encoder) module used in
10 * the Nomadik 8815 and Ux500 platforms.
11 */
12
13#include <linux/platform_device.h>
14#include <linux/interrupt.h>
15#include <linux/spinlock.h>
16#include <linux/io.h>
17#include <linux/delay.h>
18#include <linux/input.h>
19#include <linux/slab.h>
20#include <linux/clk.h>
21#include <linux/module.h>
22
23#include <linux/platform_data/keypad-nomadik-ske.h>
24
25/* SKE_CR bits */
26#define SKE_KPMLT (0x1 << 6)
27#define SKE_KPCN (0x7 << 3)
28#define SKE_KPASEN (0x1 << 2)
29#define SKE_KPASON (0x1 << 7)
30
31/* SKE_IMSC bits */
32#define SKE_KPIMA (0x1 << 2)
33
34/* SKE_ICR bits */
35#define SKE_KPICS (0x1 << 3)
36#define SKE_KPICA (0x1 << 2)
37
38/* SKE_RIS bits */
39#define SKE_KPRISA (0x1 << 2)
40
41#define SKE_KEYPAD_ROW_SHIFT 3
42#define SKE_KPD_NUM_ROWS 8
43#define SKE_KPD_NUM_COLS 8
44
45/* keypad auto scan registers */
46#define SKE_ASR0 0x20
47#define SKE_ASR1 0x24
48#define SKE_ASR2 0x28
49#define SKE_ASR3 0x2C
50
51#define SKE_NUM_ASRX_REGISTERS (4)
52#define KEY_PRESSED_DELAY 10
53
54/**
55 * struct ske_keypad - data structure used by keypad driver
56 * @irq: irq no
57 * @reg_base: ske registers base address
58 * @input: pointer to input device object
59 * @board: keypad platform device
60 * @keymap: matrix scan code table for keycodes
61 * @clk: clock structure pointer
62 */
63struct ske_keypad {
64 int irq;
65 void __iomem *reg_base;
66 struct input_dev *input;
67 const struct ske_keypad_platform_data *board;
68 unsigned short keymap[SKE_KPD_NUM_ROWS * SKE_KPD_NUM_COLS];
69 struct clk *clk;
70 struct clk *pclk;
71 spinlock_t ske_keypad_lock;
72};
73
74static void ske_keypad_set_bits(struct ske_keypad *keypad, u16 addr,
75 u8 mask, u8 data)
76{
77 u32 ret;
78
79 spin_lock(&keypad->ske_keypad_lock);
80
81 ret = readl(keypad->reg_base + addr);
82 ret &= ~mask;
83 ret |= data;
84 writel(ret, keypad->reg_base + addr);
85
86 spin_unlock(&keypad->ske_keypad_lock);
87}
88
89/*
90 * ske_keypad_chip_init: init keypad controller configuration
91 *
92 * Enable Multi key press detection, auto scan mode
93 */
94static int __init ske_keypad_chip_init(struct ske_keypad *keypad)
95{
96 u32 value;
97 int timeout = keypad->board->debounce_ms;
98
99 /* check SKE_RIS to be 0 */
100 while ((readl(keypad->reg_base + SKE_RIS) != 0x00000000) && timeout--)
101 cpu_relax();
102
103 if (!timeout)
104 return -EINVAL;
105
106 /*
107 * set debounce value
108 * keypad dbounce is configured in DBCR[15:8]
109 * dbounce value in steps of 32/32.768 ms
110 */
111 spin_lock(&keypad->ske_keypad_lock);
112 value = readl(keypad->reg_base + SKE_DBCR);
113 value = value & 0xff;
114 value |= ((keypad->board->debounce_ms * 32000)/32768) << 8;
115 writel(value, keypad->reg_base + SKE_DBCR);
116 spin_unlock(&keypad->ske_keypad_lock);
117
118 /* enable multi key detection */
119 ske_keypad_set_bits(keypad, SKE_CR, 0x0, SKE_KPMLT);
120
121 /*
122 * set up the number of columns
123 * KPCN[5:3] defines no. of keypad columns to be auto scanned
124 */
125 value = (keypad->board->kcol - 1) << 3;
126 ske_keypad_set_bits(keypad, SKE_CR, SKE_KPCN, value);
127
128 /* clear keypad interrupt for auto(and pending SW) scans */
129 ske_keypad_set_bits(keypad, SKE_ICR, 0x0, SKE_KPICA | SKE_KPICS);
130
131 /* un-mask keypad interrupts */
132 ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA);
133
134 /* enable automatic scan */
135 ske_keypad_set_bits(keypad, SKE_CR, 0x0, SKE_KPASEN);
136
137 return 0;
138}
139
140static void ske_keypad_report(struct ske_keypad *keypad, u8 status, int col)
141{
142 int row = 0, code, pos;
143 struct input_dev *input = keypad->input;
144 u32 ske_ris;
145 int key_pressed;
146 int num_of_rows;
147
148 /* find out the row */
149 num_of_rows = hweight8(status);
150 do {
151 pos = __ffs(status);
152 row = pos;
153 status &= ~(1 << pos);
154
155 code = MATRIX_SCAN_CODE(row, col, SKE_KEYPAD_ROW_SHIFT);
156 ske_ris = readl(keypad->reg_base + SKE_RIS);
157 key_pressed = ske_ris & SKE_KPRISA;
158
159 input_event(input, EV_MSC, MSC_SCAN, code);
160 input_report_key(input, keypad->keymap[code], key_pressed);
161 input_sync(input);
162 num_of_rows--;
163 } while (num_of_rows);
164}
165
166static void ske_keypad_read_data(struct ske_keypad *keypad)
167{
168 u8 status;
169 int col = 0;
170 int ske_asr, i;
171
172 /*
173 * Read the auto scan registers
174 *
175 * Each SKE_ASRx (x=0 to x=3) contains two row values.
176 * lower byte contains row value for column 2*x,
177 * upper byte contains row value for column 2*x + 1
178 */
179 for (i = 0; i < SKE_NUM_ASRX_REGISTERS; i++) {
180 ske_asr = readl(keypad->reg_base + SKE_ASR0 + (4 * i));
181 if (!ske_asr)
182 continue;
183
184 /* now that ASRx is zero, find out the coloumn x and row y */
185 status = ske_asr & 0xff;
186 if (status) {
187 col = i * 2;
188 ske_keypad_report(keypad, status, col);
189 }
190 status = (ske_asr & 0xff00) >> 8;
191 if (status) {
192 col = (i * 2) + 1;
193 ske_keypad_report(keypad, status, col);
194 }
195 }
196}
197
198static irqreturn_t ske_keypad_irq(int irq, void *dev_id)
199{
200 struct ske_keypad *keypad = dev_id;
201 int timeout = keypad->board->debounce_ms;
202
203 /* disable auto scan interrupt; mask the interrupt generated */
204 ske_keypad_set_bits(keypad, SKE_IMSC, ~SKE_KPIMA, 0x0);
205 ske_keypad_set_bits(keypad, SKE_ICR, 0x0, SKE_KPICA);
206
207 while ((readl(keypad->reg_base + SKE_CR) & SKE_KPASON) && --timeout)
208 cpu_relax();
209
210 /* SKEx registers are stable and can be read */
211 ske_keypad_read_data(keypad);
212
213 /* wait until raw interrupt is clear */
214 while ((readl(keypad->reg_base + SKE_RIS)) && --timeout)
215 msleep(KEY_PRESSED_DELAY);
216
217 /* enable auto scan interrupts */
218 ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA);
219
220 return IRQ_HANDLED;
221}
222
223static int __init ske_keypad_probe(struct platform_device *pdev)
224{
225 const struct ske_keypad_platform_data *plat =
226 dev_get_platdata(&pdev->dev);
227 struct ske_keypad *keypad;
228 struct input_dev *input;
229 struct resource *res;
230 int irq;
231 int error;
232
233 if (!plat) {
234 dev_err(&pdev->dev, "invalid keypad platform data\n");
235 return -EINVAL;
236 }
237
238 irq = platform_get_irq(pdev, 0);
239 if (irq < 0) {
240 dev_err(&pdev->dev, "failed to get keypad irq\n");
241 return -EINVAL;
242 }
243
244 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
245 if (!res) {
246 dev_err(&pdev->dev, "missing platform resources\n");
247 return -EINVAL;
248 }
249
250 keypad = kzalloc(sizeof(struct ske_keypad), GFP_KERNEL);
251 input = input_allocate_device();
252 if (!keypad || !input) {
253 dev_err(&pdev->dev, "failed to allocate keypad memory\n");
254 error = -ENOMEM;
255 goto err_free_mem;
256 }
257
258 keypad->irq = irq;
259 keypad->board = plat;
260 keypad->input = input;
261 spin_lock_init(&keypad->ske_keypad_lock);
262
263 if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
264 dev_err(&pdev->dev, "failed to request I/O memory\n");
265 error = -EBUSY;
266 goto err_free_mem;
267 }
268
269 keypad->reg_base = ioremap(res->start, resource_size(res));
270 if (!keypad->reg_base) {
271 dev_err(&pdev->dev, "failed to remap I/O memory\n");
272 error = -ENXIO;
273 goto err_free_mem_region;
274 }
275
276 keypad->pclk = clk_get(&pdev->dev, "apb_pclk");
277 if (IS_ERR(keypad->pclk)) {
278 dev_err(&pdev->dev, "failed to get pclk\n");
279 error = PTR_ERR(keypad->pclk);
280 goto err_iounmap;
281 }
282
283 keypad->clk = clk_get(&pdev->dev, NULL);
284 if (IS_ERR(keypad->clk)) {
285 dev_err(&pdev->dev, "failed to get clk\n");
286 error = PTR_ERR(keypad->clk);
287 goto err_pclk;
288 }
289
290 input->id.bustype = BUS_HOST;
291 input->name = "ux500-ske-keypad";
292 input->dev.parent = &pdev->dev;
293
294 error = matrix_keypad_build_keymap(plat->keymap_data, NULL,
295 SKE_KPD_NUM_ROWS, SKE_KPD_NUM_COLS,
296 keypad->keymap, input);
297 if (error) {
298 dev_err(&pdev->dev, "Failed to build keymap\n");
299 goto err_clk;
300 }
301
302 input_set_capability(input, EV_MSC, MSC_SCAN);
303 if (!plat->no_autorepeat)
304 __set_bit(EV_REP, input->evbit);
305
306 error = clk_prepare_enable(keypad->pclk);
307 if (error) {
308 dev_err(&pdev->dev, "Failed to prepare/enable pclk\n");
309 goto err_clk;
310 }
311
312 error = clk_prepare_enable(keypad->clk);
313 if (error) {
314 dev_err(&pdev->dev, "Failed to prepare/enable clk\n");
315 goto err_pclk_disable;
316 }
317
318
319 /* go through board initialization helpers */
320 if (keypad->board->init)
321 keypad->board->init();
322
323 error = ske_keypad_chip_init(keypad);
324 if (error) {
325 dev_err(&pdev->dev, "unable to init keypad hardware\n");
326 goto err_clk_disable;
327 }
328
329 error = request_threaded_irq(keypad->irq, NULL, ske_keypad_irq,
330 IRQF_ONESHOT, "ske-keypad", keypad);
331 if (error) {
332 dev_err(&pdev->dev, "allocate irq %d failed\n", keypad->irq);
333 goto err_clk_disable;
334 }
335
336 error = input_register_device(input);
337 if (error) {
338 dev_err(&pdev->dev,
339 "unable to register input device: %d\n", error);
340 goto err_free_irq;
341 }
342
343 if (plat->wakeup_enable)
344 device_init_wakeup(&pdev->dev, true);
345
346 platform_set_drvdata(pdev, keypad);
347
348 return 0;
349
350err_free_irq:
351 free_irq(keypad->irq, keypad);
352err_clk_disable:
353 clk_disable_unprepare(keypad->clk);
354err_pclk_disable:
355 clk_disable_unprepare(keypad->pclk);
356err_clk:
357 clk_put(keypad->clk);
358err_pclk:
359 clk_put(keypad->pclk);
360err_iounmap:
361 iounmap(keypad->reg_base);
362err_free_mem_region:
363 release_mem_region(res->start, resource_size(res));
364err_free_mem:
365 input_free_device(input);
366 kfree(keypad);
367 return error;
368}
369
370static int ske_keypad_remove(struct platform_device *pdev)
371{
372 struct ske_keypad *keypad = platform_get_drvdata(pdev);
373 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
374
375 free_irq(keypad->irq, keypad);
376
377 input_unregister_device(keypad->input);
378
379 clk_disable_unprepare(keypad->clk);
380 clk_put(keypad->clk);
381
382 if (keypad->board->exit)
383 keypad->board->exit();
384
385 iounmap(keypad->reg_base);
386 release_mem_region(res->start, resource_size(res));
387 kfree(keypad);
388
389 return 0;
390}
391
392#ifdef CONFIG_PM_SLEEP
393static int ske_keypad_suspend(struct device *dev)
394{
395 struct platform_device *pdev = to_platform_device(dev);
396 struct ske_keypad *keypad = platform_get_drvdata(pdev);
397 int irq = platform_get_irq(pdev, 0);
398
399 if (device_may_wakeup(dev))
400 enable_irq_wake(irq);
401 else
402 ske_keypad_set_bits(keypad, SKE_IMSC, ~SKE_KPIMA, 0x0);
403
404 return 0;
405}
406
407static int ske_keypad_resume(struct device *dev)
408{
409 struct platform_device *pdev = to_platform_device(dev);
410 struct ske_keypad *keypad = platform_get_drvdata(pdev);
411 int irq = platform_get_irq(pdev, 0);
412
413 if (device_may_wakeup(dev))
414 disable_irq_wake(irq);
415 else
416 ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA);
417
418 return 0;
419}
420#endif
421
422static SIMPLE_DEV_PM_OPS(ske_keypad_dev_pm_ops,
423 ske_keypad_suspend, ske_keypad_resume);
424
425static struct platform_driver ske_keypad_driver = {
426 .driver = {
427 .name = "nmk-ske-keypad",
428 .pm = &ske_keypad_dev_pm_ops,
429 },
430 .remove = ske_keypad_remove,
431};
432
433module_platform_driver_probe(ske_keypad_driver, ske_keypad_probe);
434
435MODULE_LICENSE("GPL v2");
436MODULE_AUTHOR("Naveen Kumar <naveen.gaddipati@stericsson.com> / Sundar Iyer <sundar.iyer@stericsson.com>");
437MODULE_DESCRIPTION("Nomadik Scroll-Key-Encoder Keypad Driver");
438MODULE_ALIAS("platform:nomadik-ske-keypad");
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * Author: Naveen Kumar G <naveen.gaddipati@stericsson.com> for ST-Ericsson
5 * Author: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
6 *
7 * License terms:GNU General Public License (GPL) version 2
8 *
9 * Keypad controller driver for the SKE (Scroll Key Encoder) module used in
10 * the Nomadik 8815 and Ux500 platforms.
11 */
12
13#include <linux/platform_device.h>
14#include <linux/interrupt.h>
15#include <linux/spinlock.h>
16#include <linux/io.h>
17#include <linux/delay.h>
18#include <linux/input.h>
19#include <linux/slab.h>
20#include <linux/clk.h>
21#include <linux/module.h>
22
23#include <plat/ske.h>
24
25/* SKE_CR bits */
26#define SKE_KPMLT (0x1 << 6)
27#define SKE_KPCN (0x7 << 3)
28#define SKE_KPASEN (0x1 << 2)
29#define SKE_KPASON (0x1 << 7)
30
31/* SKE_IMSC bits */
32#define SKE_KPIMA (0x1 << 2)
33
34/* SKE_ICR bits */
35#define SKE_KPICS (0x1 << 3)
36#define SKE_KPICA (0x1 << 2)
37
38/* SKE_RIS bits */
39#define SKE_KPRISA (0x1 << 2)
40
41#define SKE_KEYPAD_ROW_SHIFT 3
42#define SKE_KPD_NUM_ROWS 8
43#define SKE_KPD_NUM_COLS 8
44
45/* keypad auto scan registers */
46#define SKE_ASR0 0x20
47#define SKE_ASR1 0x24
48#define SKE_ASR2 0x28
49#define SKE_ASR3 0x2C
50
51#define SKE_NUM_ASRX_REGISTERS (4)
52
53/**
54 * struct ske_keypad - data structure used by keypad driver
55 * @irq: irq no
56 * @reg_base: ske regsiters base address
57 * @input: pointer to input device object
58 * @board: keypad platform device
59 * @keymap: matrix scan code table for keycodes
60 * @clk: clock structure pointer
61 */
62struct ske_keypad {
63 int irq;
64 void __iomem *reg_base;
65 struct input_dev *input;
66 const struct ske_keypad_platform_data *board;
67 unsigned short keymap[SKE_KPD_NUM_ROWS * SKE_KPD_NUM_COLS];
68 struct clk *clk;
69 spinlock_t ske_keypad_lock;
70};
71
72static void ske_keypad_set_bits(struct ske_keypad *keypad, u16 addr,
73 u8 mask, u8 data)
74{
75 u32 ret;
76
77 spin_lock(&keypad->ske_keypad_lock);
78
79 ret = readl(keypad->reg_base + addr);
80 ret &= ~mask;
81 ret |= data;
82 writel(ret, keypad->reg_base + addr);
83
84 spin_unlock(&keypad->ske_keypad_lock);
85}
86
87/*
88 * ske_keypad_chip_init: init keypad controller configuration
89 *
90 * Enable Multi key press detection, auto scan mode
91 */
92static int __init ske_keypad_chip_init(struct ske_keypad *keypad)
93{
94 u32 value;
95 int timeout = 50;
96
97 /* check SKE_RIS to be 0 */
98 while ((readl(keypad->reg_base + SKE_RIS) != 0x00000000) && timeout--)
99 cpu_relax();
100
101 if (!timeout)
102 return -EINVAL;
103
104 /*
105 * set debounce value
106 * keypad dbounce is configured in DBCR[15:8]
107 * dbounce value in steps of 32/32.768 ms
108 */
109 spin_lock(&keypad->ske_keypad_lock);
110 value = readl(keypad->reg_base + SKE_DBCR);
111 value = value & 0xff;
112 value |= ((keypad->board->debounce_ms * 32000)/32768) << 8;
113 writel(value, keypad->reg_base + SKE_DBCR);
114 spin_unlock(&keypad->ske_keypad_lock);
115
116 /* enable multi key detection */
117 ske_keypad_set_bits(keypad, SKE_CR, 0x0, SKE_KPMLT);
118
119 /*
120 * set up the number of columns
121 * KPCN[5:3] defines no. of keypad columns to be auto scanned
122 */
123 value = (keypad->board->kcol - 1) << 3;
124 ske_keypad_set_bits(keypad, SKE_CR, SKE_KPCN, value);
125
126 /* clear keypad interrupt for auto(and pending SW) scans */
127 ske_keypad_set_bits(keypad, SKE_ICR, 0x0, SKE_KPICA | SKE_KPICS);
128
129 /* un-mask keypad interrupts */
130 ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA);
131
132 /* enable automatic scan */
133 ske_keypad_set_bits(keypad, SKE_CR, 0x0, SKE_KPASEN);
134
135 return 0;
136}
137
138static void ske_keypad_read_data(struct ske_keypad *keypad)
139{
140 struct input_dev *input = keypad->input;
141 u16 status;
142 int col = 0, row = 0, code;
143 int ske_asr, ske_ris, key_pressed, i;
144
145 /*
146 * Read the auto scan registers
147 *
148 * Each SKE_ASRx (x=0 to x=3) contains two row values.
149 * lower byte contains row value for column 2*x,
150 * upper byte contains row value for column 2*x + 1
151 */
152 for (i = 0; i < SKE_NUM_ASRX_REGISTERS; i++) {
153 ske_asr = readl(keypad->reg_base + SKE_ASR0 + (4 * i));
154 if (!ske_asr)
155 continue;
156
157 /* now that ASRx is zero, find out the column x and row y*/
158 if (ske_asr & 0xff) {
159 col = i * 2;
160 status = ske_asr & 0xff;
161 } else {
162 col = (i * 2) + 1;
163 status = (ske_asr & 0xff00) >> 8;
164 }
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 }
177}
178
179static irqreturn_t ske_keypad_irq(int irq, void *dev_id)
180{
181 struct ske_keypad *keypad = dev_id;
182 int retries = 20;
183
184 /* disable auto scan interrupt; mask the interrupt generated */
185 ske_keypad_set_bits(keypad, SKE_IMSC, ~SKE_KPIMA, 0x0);
186 ske_keypad_set_bits(keypad, SKE_ICR, 0x0, SKE_KPICA);
187
188 while ((readl(keypad->reg_base + SKE_CR) & SKE_KPASON) && --retries)
189 msleep(5);
190
191 if (retries) {
192 /* SKEx registers are stable and can be read */
193 ske_keypad_read_data(keypad);
194 }
195
196 /* enable auto scan interrupts */
197 ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA);
198
199 return IRQ_HANDLED;
200}
201
202static int __init ske_keypad_probe(struct platform_device *pdev)
203{
204 const struct ske_keypad_platform_data *plat = pdev->dev.platform_data;
205 struct ske_keypad *keypad;
206 struct input_dev *input;
207 struct resource *res;
208 int irq;
209 int error;
210
211 if (!plat) {
212 dev_err(&pdev->dev, "invalid keypad platform data\n");
213 return -EINVAL;
214 }
215
216 irq = platform_get_irq(pdev, 0);
217 if (irq < 0) {
218 dev_err(&pdev->dev, "failed to get keypad irq\n");
219 return -EINVAL;
220 }
221
222 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
223 if (!res) {
224 dev_err(&pdev->dev, "missing platform resources\n");
225 return -EINVAL;
226 }
227
228 keypad = kzalloc(sizeof(struct ske_keypad), GFP_KERNEL);
229 input = input_allocate_device();
230 if (!keypad || !input) {
231 dev_err(&pdev->dev, "failed to allocate keypad memory\n");
232 error = -ENOMEM;
233 goto err_free_mem;
234 }
235
236 keypad->irq = irq;
237 keypad->board = plat;
238 keypad->input = input;
239 spin_lock_init(&keypad->ske_keypad_lock);
240
241 if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
242 dev_err(&pdev->dev, "failed to request I/O memory\n");
243 error = -EBUSY;
244 goto err_free_mem;
245 }
246
247 keypad->reg_base = ioremap(res->start, resource_size(res));
248 if (!keypad->reg_base) {
249 dev_err(&pdev->dev, "failed to remap I/O memory\n");
250 error = -ENXIO;
251 goto err_free_mem_region;
252 }
253
254 keypad->clk = clk_get(&pdev->dev, NULL);
255 if (IS_ERR(keypad->clk)) {
256 dev_err(&pdev->dev, "failed to get clk\n");
257 error = PTR_ERR(keypad->clk);
258 goto err_iounmap;
259 }
260
261 input->id.bustype = BUS_HOST;
262 input->name = "ux500-ske-keypad";
263 input->dev.parent = &pdev->dev;
264
265 error = matrix_keypad_build_keymap(plat->keymap_data, NULL,
266 SKE_KPD_NUM_ROWS, SKE_KPD_NUM_COLS,
267 keypad->keymap, input);
268 if (error) {
269 dev_err(&pdev->dev, "Failed to build keymap\n");
270 goto err_iounmap;
271 }
272
273 input_set_capability(input, EV_MSC, MSC_SCAN);
274 if (!plat->no_autorepeat)
275 __set_bit(EV_REP, input->evbit);
276
277 clk_enable(keypad->clk);
278
279 /* go through board initialization helpers */
280 if (keypad->board->init)
281 keypad->board->init();
282
283 error = ske_keypad_chip_init(keypad);
284 if (error) {
285 dev_err(&pdev->dev, "unable to init keypad hardware\n");
286 goto err_clk_disable;
287 }
288
289 error = request_threaded_irq(keypad->irq, NULL, ske_keypad_irq,
290 IRQF_ONESHOT, "ske-keypad", keypad);
291 if (error) {
292 dev_err(&pdev->dev, "allocate irq %d failed\n", keypad->irq);
293 goto err_clk_disable;
294 }
295
296 error = input_register_device(input);
297 if (error) {
298 dev_err(&pdev->dev,
299 "unable to register input device: %d\n", error);
300 goto err_free_irq;
301 }
302
303 if (plat->wakeup_enable)
304 device_init_wakeup(&pdev->dev, true);
305
306 platform_set_drvdata(pdev, keypad);
307
308 return 0;
309
310err_free_irq:
311 free_irq(keypad->irq, keypad);
312err_clk_disable:
313 clk_disable(keypad->clk);
314 clk_put(keypad->clk);
315err_iounmap:
316 iounmap(keypad->reg_base);
317err_free_mem_region:
318 release_mem_region(res->start, resource_size(res));
319err_free_mem:
320 input_free_device(input);
321 kfree(keypad);
322 return error;
323}
324
325static int __devexit ske_keypad_remove(struct platform_device *pdev)
326{
327 struct ske_keypad *keypad = platform_get_drvdata(pdev);
328 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
329
330 free_irq(keypad->irq, keypad);
331
332 input_unregister_device(keypad->input);
333
334 clk_disable(keypad->clk);
335 clk_put(keypad->clk);
336
337 if (keypad->board->exit)
338 keypad->board->exit();
339
340 iounmap(keypad->reg_base);
341 release_mem_region(res->start, resource_size(res));
342 kfree(keypad);
343
344 return 0;
345}
346
347#ifdef CONFIG_PM_SLEEP
348static int ske_keypad_suspend(struct device *dev)
349{
350 struct platform_device *pdev = to_platform_device(dev);
351 struct ske_keypad *keypad = platform_get_drvdata(pdev);
352 int irq = platform_get_irq(pdev, 0);
353
354 if (device_may_wakeup(dev))
355 enable_irq_wake(irq);
356 else
357 ske_keypad_set_bits(keypad, SKE_IMSC, ~SKE_KPIMA, 0x0);
358
359 return 0;
360}
361
362static int ske_keypad_resume(struct device *dev)
363{
364 struct platform_device *pdev = to_platform_device(dev);
365 struct ske_keypad *keypad = platform_get_drvdata(pdev);
366 int irq = platform_get_irq(pdev, 0);
367
368 if (device_may_wakeup(dev))
369 disable_irq_wake(irq);
370 else
371 ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA);
372
373 return 0;
374}
375#endif
376
377static SIMPLE_DEV_PM_OPS(ske_keypad_dev_pm_ops,
378 ske_keypad_suspend, ske_keypad_resume);
379
380static struct platform_driver ske_keypad_driver = {
381 .driver = {
382 .name = "nmk-ske-keypad",
383 .owner = THIS_MODULE,
384 .pm = &ske_keypad_dev_pm_ops,
385 },
386 .remove = __devexit_p(ske_keypad_remove),
387};
388
389static int __init ske_keypad_init(void)
390{
391 return platform_driver_probe(&ske_keypad_driver, ske_keypad_probe);
392}
393module_init(ske_keypad_init);
394
395static void __exit ske_keypad_exit(void)
396{
397 platform_driver_unregister(&ske_keypad_driver);
398}
399module_exit(ske_keypad_exit);
400
401MODULE_LICENSE("GPL v2");
402MODULE_AUTHOR("Naveen Kumar <naveen.gaddipati@stericsson.com> / Sundar Iyer <sundar.iyer@stericsson.com>");
403MODULE_DESCRIPTION("Nomadik Scroll-Key-Encoder Keypad Driver");
404MODULE_ALIAS("platform:nomadik-ske-keypad");