aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/keyboard/ep93xx_keypad.c150
1 files changed, 49 insertions, 101 deletions
diff --git a/drivers/input/keyboard/ep93xx_keypad.c b/drivers/input/keyboard/ep93xx_keypad.c
index 181d30e3018e..e45740429f7e 100644
--- a/drivers/input/keyboard/ep93xx_keypad.c
+++ b/drivers/input/keyboard/ep93xx_keypad.c
@@ -22,11 +22,11 @@
22 22
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/interrupt.h> 24#include <linux/interrupt.h>
25#include <linux/input.h>
26#include <linux/clk.h> 25#include <linux/clk.h>
26#include <linux/io.h>
27#include <linux/input/matrix_keypad.h>
27 28
28#include <mach/hardware.h> 29#include <mach/hardware.h>
29#include <mach/gpio.h>
30#include <mach/ep93xx_keypad.h> 30#include <mach/ep93xx_keypad.h>
31 31
32/* 32/*
@@ -60,38 +60,37 @@
60#define KEY_REG_KEY1_MASK (0x0000003f) 60#define KEY_REG_KEY1_MASK (0x0000003f)
61#define KEY_REG_KEY1_SHIFT (0) 61#define KEY_REG_KEY1_SHIFT (0)
62 62
63#define keypad_readl(off) __raw_readl(keypad->mmio_base + (off)) 63#define EP93XX_MATRIX_SIZE (EP93XX_MATRIX_ROWS * EP93XX_MATRIX_COLS)
64#define keypad_writel(v, off) __raw_writel((v), keypad->mmio_base + (off))
65
66#define MAX_MATRIX_KEY_NUM (MAX_MATRIX_KEY_ROWS * MAX_MATRIX_KEY_COLS)
67 64
68struct ep93xx_keypad { 65struct ep93xx_keypad {
69 struct ep93xx_keypad_platform_data *pdata; 66 struct ep93xx_keypad_platform_data *pdata;
70
71 struct clk *clk;
72 struct input_dev *input_dev; 67 struct input_dev *input_dev;
68 struct clk *clk;
69
73 void __iomem *mmio_base; 70 void __iomem *mmio_base;
74 71
75 int irq; 72 unsigned int matrix_keycodes[EP93XX_MATRIX_SIZE];
76 int enabled;
77 73
78 int key1; 74 int key1;
79 int key2; 75 int key2;
80 76
81 unsigned int matrix_keycodes[MAX_MATRIX_KEY_NUM]; 77 int irq;
78
79 bool enabled;
82}; 80};
83 81
84static void ep93xx_keypad_build_keycode(struct ep93xx_keypad *keypad) 82static void ep93xx_keypad_build_keycode(struct ep93xx_keypad *keypad)
85{ 83{
86 struct ep93xx_keypad_platform_data *pdata = keypad->pdata; 84 struct ep93xx_keypad_platform_data *pdata = keypad->pdata;
87 struct input_dev *input_dev = keypad->input_dev; 85 struct input_dev *input_dev = keypad->input_dev;
86 unsigned int *key;
88 int i; 87 int i;
89 88
90 for (i = 0; i < pdata->matrix_key_map_size; i++) { 89 key = &pdata->matrix_key_map[0];
91 unsigned int key = pdata->matrix_key_map[i]; 90 for (i = 0; i < pdata->matrix_key_map_size; i++, key++) {
92 int row = (key >> 28) & 0xf; 91 int row = KEY_ROW(*key);
93 int col = (key >> 24) & 0xf; 92 int col = KEY_COL(*key);
94 int code = key & 0xffffff; 93 int code = KEY_VAL(*key);
95 94
96 keypad->matrix_keycodes[(row << 3) + col] = code; 95 keypad->matrix_keycodes[(row << 3) + col] = code;
97 __set_bit(code, input_dev->keybit); 96 __set_bit(code, input_dev->keybit);
@@ -102,9 +101,11 @@ static irqreturn_t ep93xx_keypad_irq_handler(int irq, void *dev_id)
102{ 101{
103 struct ep93xx_keypad *keypad = dev_id; 102 struct ep93xx_keypad *keypad = dev_id;
104 struct input_dev *input_dev = keypad->input_dev; 103 struct input_dev *input_dev = keypad->input_dev;
105 unsigned int status = keypad_readl(KEY_REG); 104 unsigned int status;
106 int keycode, key1, key2; 105 int keycode, key1, key2;
107 106
107 status = __raw_readl(keypad->mmio_base + KEY_REG);
108
108 keycode = (status & KEY_REG_KEY1_MASK) >> KEY_REG_KEY1_SHIFT; 109 keycode = (status & KEY_REG_KEY1_MASK) >> KEY_REG_KEY1_SHIFT;
109 key1 = keypad->matrix_keycodes[keycode]; 110 key1 = keypad->matrix_keycodes[keycode];
110 111
@@ -152,7 +153,10 @@ static void ep93xx_keypad_config(struct ep93xx_keypad *keypad)
152 struct ep93xx_keypad_platform_data *pdata = keypad->pdata; 153 struct ep93xx_keypad_platform_data *pdata = keypad->pdata;
153 unsigned int val = 0; 154 unsigned int val = 0;
154 155
155 clk_set_rate(keypad->clk, pdata->flags & EP93XX_KEYPAD_KDIV); 156 if (pdata->flags & EP93XX_KEYPAD_KDIV)
157 clk_set_rate(keypad->clk, EP93XX_KEYTCHCLK_DIV4);
158 else
159 clk_set_rate(keypad->clk, EP93XX_KEYTCHCLK_DIV16);
156 160
157 if (pdata->flags & EP93XX_KEYPAD_DISABLE_3_KEY) 161 if (pdata->flags & EP93XX_KEYPAD_DISABLE_3_KEY)
158 val |= KEY_INIT_DIS3KY; 162 val |= KEY_INIT_DIS3KY;
@@ -167,7 +171,7 @@ static void ep93xx_keypad_config(struct ep93xx_keypad *keypad)
167 171
168 val |= ((pdata->prescale << KEY_INIT_PRSCL_SHIFT) & KEY_INIT_PRSCL_MASK); 172 val |= ((pdata->prescale << KEY_INIT_PRSCL_SHIFT) & KEY_INIT_PRSCL_MASK);
169 173
170 keypad_writel(val, KEY_INIT); 174 __raw_writel(val, keypad->mmio_base + KEY_INIT);
171} 175}
172 176
173static int ep93xx_keypad_open(struct input_dev *pdev) 177static int ep93xx_keypad_open(struct input_dev *pdev)
@@ -177,7 +181,7 @@ static int ep93xx_keypad_open(struct input_dev *pdev)
177 if (!keypad->enabled) { 181 if (!keypad->enabled) {
178 ep93xx_keypad_config(keypad); 182 ep93xx_keypad_config(keypad);
179 clk_enable(keypad->clk); 183 clk_enable(keypad->clk);
180 keypad->enabled = 1; 184 keypad->enabled = true;
181 } 185 }
182 186
183 return 0; 187 return 0;
@@ -189,7 +193,7 @@ static void ep93xx_keypad_close(struct input_dev *pdev)
189 193
190 if (keypad->enabled) { 194 if (keypad->enabled) {
191 clk_disable(keypad->clk); 195 clk_disable(keypad->clk);
192 keypad->enabled = 0; 196 keypad->enabled = false;
193 } 197 }
194} 198}
195 199
@@ -211,7 +215,7 @@ static int ep93xx_keypad_suspend(struct platform_device *pdev,
211 215
212 if (keypad->enabled) { 216 if (keypad->enabled) {
213 clk_disable(keypad->clk); 217 clk_disable(keypad->clk);
214 keypad->enabled = 0; 218 keypad->enabled = false;
215 } 219 }
216 220
217 mutex_unlock(&input_dev->mutex); 221 mutex_unlock(&input_dev->mutex);
@@ -236,7 +240,7 @@ static int ep93xx_keypad_resume(struct platform_device *pdev)
236 if (!keypad->enabled) { 240 if (!keypad->enabled) {
237 ep93xx_keypad_config(keypad); 241 ep93xx_keypad_config(keypad);
238 clk_enable(keypad->clk); 242 clk_enable(keypad->clk);
239 keypad->enabled = 1; 243 keypad->enabled = true;
240 } 244 }
241 } 245 }
242 246
@@ -252,88 +256,56 @@ static int ep93xx_keypad_resume(struct platform_device *pdev)
252static int __devinit ep93xx_keypad_probe(struct platform_device *pdev) 256static int __devinit ep93xx_keypad_probe(struct platform_device *pdev)
253{ 257{
254 struct ep93xx_keypad *keypad; 258 struct ep93xx_keypad *keypad;
255 struct ep93xx_keypad_platform_data *pdata = pdev->dev.platform_data;
256 struct input_dev *input_dev; 259 struct input_dev *input_dev;
257 struct resource *res; 260 struct resource *res;
258 int irq, err, i, gpio; 261 int err;
259
260 if (!pdata ||
261 !pdata->matrix_key_rows ||
262 pdata->matrix_key_rows > MAX_MATRIX_KEY_ROWS ||
263 !pdata->matrix_key_cols ||
264 pdata->matrix_key_cols > MAX_MATRIX_KEY_COLS) {
265 dev_err(&pdev->dev, "invalid or missing platform data\n");
266 return -EINVAL;
267 }
268 262
269 keypad = kzalloc(sizeof(struct ep93xx_keypad), GFP_KERNEL); 263 keypad = kzalloc(sizeof(struct ep93xx_keypad), GFP_KERNEL);
270 if (!keypad) { 264 if (!keypad)
271 dev_err(&pdev->dev, "failed to allocate driver data\n");
272 return -ENOMEM; 265 return -ENOMEM;
273 }
274 266
275 keypad->pdata = pdata; 267 keypad->pdata = pdev->dev.platform_data;
268 if (!keypad->pdata) {
269 err = -EINVAL;
270 goto failed_free;
271 }
276 272
277 irq = platform_get_irq(pdev, 0); 273 keypad->irq = platform_get_irq(pdev, 0);
278 if (irq < 0) { 274 if (!keypad->irq) {
279 dev_err(&pdev->dev, "failed to get keypad irq\n");
280 err = -ENXIO; 275 err = -ENXIO;
281 goto failed_free; 276 goto failed_free;
282 } 277 }
283 278
284 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 279 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
285 if (!res) { 280 if (!res) {
286 dev_err(&pdev->dev, "failed to get I/O memory\n");
287 err = -ENXIO; 281 err = -ENXIO;
288 goto failed_free; 282 goto failed_free;
289 } 283 }
290 284
291 res = request_mem_region(res->start, resource_size(res), pdev->name); 285 res = request_mem_region(res->start, resource_size(res), pdev->name);
292 if (!res) { 286 if (!res) {
293 dev_err(&pdev->dev, "failed to request I/O memory\n");
294 err = -EBUSY; 287 err = -EBUSY;
295 goto failed_free; 288 goto failed_free;
296 } 289 }
297 290
298 keypad->mmio_base = ioremap(res->start, resource_size(res)); 291 keypad->mmio_base = ioremap(res->start, resource_size(res));
299 if (keypad->mmio_base == NULL) { 292 if (keypad->mmio_base == NULL) {
300 dev_err(&pdev->dev, "failed to remap I/O memory\n");
301 err = -ENXIO; 293 err = -ENXIO;
302 goto failed_free_mem; 294 goto failed_free_mem;
303 } 295 }
304 296
305 /* Request the needed GPIO's */ 297 err = ep93xx_keypad_acquire_gpio(pdev);
306 gpio = EP93XX_GPIO_LINE_ROW0; 298 if (err)
307 for (i = 0; i < keypad->pdata->matrix_key_rows; i++, gpio++) { 299 goto failed_free_io;
308 err = gpio_request(gpio, pdev->name);
309 if (err) {
310 dev_err(&pdev->dev, "failed to request gpio-%d\n",
311 gpio);
312 goto failed_free_rows;
313 }
314 }
315
316 gpio = EP93XX_GPIO_LINE_COL0;
317 for (i = 0; i < keypad->pdata->matrix_key_cols; i++, gpio++) {
318 err = gpio_request(gpio, pdev->name);
319 if (err) {
320 dev_err(&pdev->dev, "failed to request gpio-%d\n",
321 gpio);
322 goto failed_free_cols;
323 }
324 }
325 300
326 keypad->clk = clk_get(&pdev->dev, "key_clk"); 301 keypad->clk = clk_get(&pdev->dev, NULL);
327 if (IS_ERR(keypad->clk)) { 302 if (IS_ERR(keypad->clk)) {
328 dev_err(&pdev->dev, "failed to get keypad clock\n");
329 err = PTR_ERR(keypad->clk); 303 err = PTR_ERR(keypad->clk);
330 goto failed_free_io; 304 goto failed_free_gpio;
331 } 305 }
332 306
333 /* Create and register the input driver */
334 input_dev = input_allocate_device(); 307 input_dev = input_allocate_device();
335 if (!input_dev) { 308 if (!input_dev) {
336 dev_err(&pdev->dev, "failed to allocate input device\n");
337 err = -ENOMEM; 309 err = -ENOMEM;
338 goto failed_put_clk; 310 goto failed_put_clk;
339 } 311 }
@@ -358,44 +330,29 @@ static int __devinit ep93xx_keypad_probe(struct platform_device *pdev)
358 ep93xx_keypad_build_keycode(keypad); 330 ep93xx_keypad_build_keycode(keypad);
359 platform_set_drvdata(pdev, keypad); 331 platform_set_drvdata(pdev, keypad);
360 332
361 err = request_irq(irq, ep93xx_keypad_irq_handler, IRQF_DISABLED, 333 err = request_irq(keypad->irq, ep93xx_keypad_irq_handler,
362 pdev->name, keypad); 334 IRQF_DISABLED, pdev->name, keypad);
363 if (err) { 335 if (err)
364 dev_err(&pdev->dev, "failed to request IRQ\n");
365 goto failed_free_dev; 336 goto failed_free_dev;
366 }
367
368 keypad->irq = irq;
369 337
370 /* Register the input device */
371 err = input_register_device(input_dev); 338 err = input_register_device(input_dev);
372 if (err) { 339 if (err)
373 dev_err(&pdev->dev, "failed to register input device\n");
374 goto failed_free_irq; 340 goto failed_free_irq;
375 }
376 341
377 device_init_wakeup(&pdev->dev, 1); 342 device_init_wakeup(&pdev->dev, 1);
378 343
379 return 0; 344 return 0;
380 345
381failed_free_irq: 346failed_free_irq:
382 free_irq(irq, pdev); 347 free_irq(keypad->irq, pdev);
383 platform_set_drvdata(pdev, NULL); 348 platform_set_drvdata(pdev, NULL);
384failed_free_dev: 349failed_free_dev:
385 input_free_device(input_dev); 350 input_free_device(input_dev);
386failed_put_clk: 351failed_put_clk:
387 clk_put(keypad->clk); 352 clk_put(keypad->clk);
353failed_free_gpio:
354 ep93xx_keypad_release_gpio(pdev);
388failed_free_io: 355failed_free_io:
389 i = keypad->pdata->matrix_key_cols - 1;
390 gpio = EP93XX_GPIO_LINE_COL0 + i;
391failed_free_cols:
392 for ( ; i >= 0; i--, gpio--)
393 gpio_free(gpio);
394 i = keypad->pdata->matrix_key_rows - 1;
395 gpio = EP93XX_GPIO_LINE_ROW0 + i;
396failed_free_rows:
397 for ( ; i >= 0; i--, gpio--)
398 gpio_free(gpio);
399 iounmap(keypad->mmio_base); 356 iounmap(keypad->mmio_base);
400failed_free_mem: 357failed_free_mem:
401 release_mem_region(res->start, resource_size(res)); 358 release_mem_region(res->start, resource_size(res));
@@ -408,7 +365,6 @@ static int __devexit ep93xx_keypad_remove(struct platform_device *pdev)
408{ 365{
409 struct ep93xx_keypad *keypad = platform_get_drvdata(pdev); 366 struct ep93xx_keypad *keypad = platform_get_drvdata(pdev);
410 struct resource *res; 367 struct resource *res;
411 int i, gpio;
412 368
413 free_irq(keypad->irq, pdev); 369 free_irq(keypad->irq, pdev);
414 370
@@ -420,15 +376,7 @@ static int __devexit ep93xx_keypad_remove(struct platform_device *pdev)
420 376
421 input_unregister_device(keypad->input_dev); 377 input_unregister_device(keypad->input_dev);
422 378
423 i = keypad->pdata->matrix_key_cols - 1; 379 ep93xx_keypad_release_gpio(pdev);
424 gpio = EP93XX_GPIO_LINE_COL0 + i;
425 for ( ; i >= 0; i--, gpio--)
426 gpio_free(gpio);
427
428 i = keypad->pdata->matrix_key_rows - 1;
429 gpio = EP93XX_GPIO_LINE_ROW0 + i;
430 for ( ; i >= 0; i--, gpio--)
431 gpio_free(gpio);
432 380
433 iounmap(keypad->mmio_base); 381 iounmap(keypad->mmio_base);
434 382