pxa27x_keypad.c (5a2dd72abdae75ea2960145e0549635ce4e0be96) pxa27x_keypad.c (52ec7752b457311f10f5a8d16faa8ac2e684eb65)
1/*
2 * linux/drivers/input/keyboard/pxa27x_keypad.c
3 *
4 * Driver for the pxa27x matrix keyboard controller.
5 *
6 * Created: Feb 22, 2007
7 * Author: Rodolfo Giometti <giometti@linux.it>
8 *

--- 11 unchanged lines hidden (view full) ---

20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/interrupt.h>
23#include <linux/input.h>
24#include <linux/device.h>
25#include <linux/platform_device.h>
26#include <linux/clk.h>
27#include <linux/err.h>
1/*
2 * linux/drivers/input/keyboard/pxa27x_keypad.c
3 *
4 * Driver for the pxa27x matrix keyboard controller.
5 *
6 * Created: Feb 22, 2007
7 * Author: Rodolfo Giometti <giometti@linux.it>
8 *

--- 11 unchanged lines hidden (view full) ---

20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/interrupt.h>
23#include <linux/input.h>
24#include <linux/device.h>
25#include <linux/platform_device.h>
26#include <linux/clk.h>
27#include <linux/err.h>
28#include <linux/input/matrix_keypad.h>
28
29#include <asm/mach/arch.h>
30#include <asm/mach/map.h>
31
32#include <mach/hardware.h>
33#include <mach/pxa27x_keypad.h>
34
35/*

--- 66 unchanged lines hidden (view full) ---

102
103 struct clk *clk;
104 struct input_dev *input_dev;
105 void __iomem *mmio_base;
106
107 int irq;
108
109 /* matrix key code map */
29
30#include <asm/mach/arch.h>
31#include <asm/mach/map.h>
32
33#include <mach/hardware.h>
34#include <mach/pxa27x_keypad.h>
35
36/*

--- 66 unchanged lines hidden (view full) ---

103
104 struct clk *clk;
105 struct input_dev *input_dev;
106 void __iomem *mmio_base;
107
108 int irq;
109
110 /* matrix key code map */
110 unsigned int matrix_keycodes[MAX_MATRIX_KEY_NUM];
111 unsigned short matrix_keycodes[MAX_MATRIX_KEY_NUM];
111
112 /* state row bits of each column scan */
113 uint32_t matrix_key_state[MAX_MATRIX_KEY_COLS];
114 uint32_t direct_key_state;
115
116 unsigned int direct_key_mask;
117
118 int rotary_rel_code[2];
119 int rotary_up_key[2];
120 int rotary_down_key[2];
121};
122
123static void pxa27x_keypad_build_keycode(struct pxa27x_keypad *keypad)
124{
125 struct pxa27x_keypad_platform_data *pdata = keypad->pdata;
126 struct input_dev *input_dev = keypad->input_dev;
112
113 /* state row bits of each column scan */
114 uint32_t matrix_key_state[MAX_MATRIX_KEY_COLS];
115 uint32_t direct_key_state;
116
117 unsigned int direct_key_mask;
118
119 int rotary_rel_code[2];
120 int rotary_up_key[2];
121 int rotary_down_key[2];
122};
123
124static void pxa27x_keypad_build_keycode(struct pxa27x_keypad *keypad)
125{
126 struct pxa27x_keypad_platform_data *pdata = keypad->pdata;
127 struct input_dev *input_dev = keypad->input_dev;
127 unsigned int *key;
128 int i;
129
128 int i;
129
130 key = &pdata->matrix_key_map[0];
131 for (i = 0; i < pdata->matrix_key_map_size; i++, key++) {
132 int row = ((*key) >> 28) & 0xf;
133 int col = ((*key) >> 24) & 0xf;
134 int code = (*key) & 0xffffff;
130 for (i = 0; i < pdata->matrix_key_map_size; i++) {
131 unsigned int key = pdata->matrix_key_map[i];
132 unsigned int row = KEY_ROW(key);
133 unsigned int col = KEY_COL(key);
134 unsigned short code = KEY_VAL(key);
135
136 keypad->matrix_keycodes[(row << 3) + col] = code;
135
136 keypad->matrix_keycodes[(row << 3) + col] = code;
137 set_bit(code, input_dev->keybit);
137 __set_bit(code, input_dev->keybit);
138 }
138 }
139 __clear_bit(KEY_RESERVED, input_dev->keybit);
139
140 for (i = 0; i < pdata->direct_key_num; i++)
140
141 for (i = 0; i < pdata->direct_key_num; i++)
141 set_bit(pdata->direct_key_map[i], input_dev->keybit);
142 __set_bit(pdata->direct_key_map[i], input_dev->keybit);
142
143 keypad->rotary_up_key[0] = pdata->rotary0_up_key;
144 keypad->rotary_up_key[1] = pdata->rotary1_up_key;
145 keypad->rotary_down_key[0] = pdata->rotary0_down_key;
146 keypad->rotary_down_key[1] = pdata->rotary1_down_key;
147 keypad->rotary_rel_code[0] = pdata->rotary0_rel_code;
148 keypad->rotary_rel_code[1] = pdata->rotary1_rel_code;
149
150 if (pdata->enable_rotary0) {
151 if (pdata->rotary0_up_key && pdata->rotary0_down_key) {
143
144 keypad->rotary_up_key[0] = pdata->rotary0_up_key;
145 keypad->rotary_up_key[1] = pdata->rotary1_up_key;
146 keypad->rotary_down_key[0] = pdata->rotary0_down_key;
147 keypad->rotary_down_key[1] = pdata->rotary1_down_key;
148 keypad->rotary_rel_code[0] = pdata->rotary0_rel_code;
149 keypad->rotary_rel_code[1] = pdata->rotary1_rel_code;
150
151 if (pdata->enable_rotary0) {
152 if (pdata->rotary0_up_key && pdata->rotary0_down_key) {
152 set_bit(pdata->rotary0_up_key, input_dev->keybit);
153 set_bit(pdata->rotary0_down_key, input_dev->keybit);
153 __set_bit(pdata->rotary0_up_key, input_dev->keybit);
154 __set_bit(pdata->rotary0_down_key, input_dev->keybit);
154 } else
155 } else
155 set_bit(pdata->rotary0_rel_code, input_dev->relbit);
156 __set_bit(pdata->rotary0_rel_code, input_dev->relbit);
156 }
157
158 if (pdata->enable_rotary1) {
159 if (pdata->rotary1_up_key && pdata->rotary1_down_key) {
157 }
158
159 if (pdata->enable_rotary1) {
160 if (pdata->rotary1_up_key && pdata->rotary1_down_key) {
160 set_bit(pdata->rotary1_up_key, input_dev->keybit);
161 set_bit(pdata->rotary1_down_key, input_dev->keybit);
161 __set_bit(pdata->rotary1_up_key, input_dev->keybit);
162 __set_bit(pdata->rotary1_down_key, input_dev->keybit);
162 } else
163 } else
163 set_bit(pdata->rotary1_rel_code, input_dev->relbit);
164 __set_bit(pdata->rotary1_rel_code, input_dev->relbit);
164 }
165}
166
167static inline unsigned int lookup_matrix_keycode(
168 struct pxa27x_keypad *keypad, int row, int col)
169{
170 return keypad->matrix_keycodes[(row << 3) + col];
171}

--- 248 unchanged lines hidden (view full) ---

420
421 return 0;
422}
423#else
424#define pxa27x_keypad_suspend NULL
425#define pxa27x_keypad_resume NULL
426#endif
427
165 }
166}
167
168static inline unsigned int lookup_matrix_keycode(
169 struct pxa27x_keypad *keypad, int row, int col)
170{
171 return keypad->matrix_keycodes[(row << 3) + col];
172}

--- 248 unchanged lines hidden (view full) ---

421
422 return 0;
423}
424#else
425#define pxa27x_keypad_suspend NULL
426#define pxa27x_keypad_resume NULL
427#endif
428
428#define res_size(res) ((res)->end - (res)->start + 1)
429
430static int __devinit pxa27x_keypad_probe(struct platform_device *pdev)
431{
432 struct pxa27x_keypad *keypad;
433 struct input_dev *input_dev;
434 struct resource *res;
435 int irq, error;
436
437 keypad = kzalloc(sizeof(struct pxa27x_keypad), GFP_KERNEL);

--- 18 unchanged lines hidden (view full) ---

456
457 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
458 if (res == NULL) {
459 dev_err(&pdev->dev, "failed to get I/O memory\n");
460 error = -ENXIO;
461 goto failed_free;
462 }
463
429static int __devinit pxa27x_keypad_probe(struct platform_device *pdev)
430{
431 struct pxa27x_keypad *keypad;
432 struct input_dev *input_dev;
433 struct resource *res;
434 int irq, error;
435
436 keypad = kzalloc(sizeof(struct pxa27x_keypad), GFP_KERNEL);

--- 18 unchanged lines hidden (view full) ---

455
456 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
457 if (res == NULL) {
458 dev_err(&pdev->dev, "failed to get I/O memory\n");
459 error = -ENXIO;
460 goto failed_free;
461 }
462
464 res = request_mem_region(res->start, res_size(res), pdev->name);
463 res = request_mem_region(res->start, resource_size(res), pdev->name);
465 if (res == NULL) {
466 dev_err(&pdev->dev, "failed to request I/O memory\n");
467 error = -EBUSY;
468 goto failed_free;
469 }
470
464 if (res == NULL) {
465 dev_err(&pdev->dev, "failed to request I/O memory\n");
466 error = -EBUSY;
467 goto failed_free;
468 }
469
471 keypad->mmio_base = ioremap(res->start, res_size(res));
470 keypad->mmio_base = ioremap(res->start, resource_size(res));
472 if (keypad->mmio_base == NULL) {
473 dev_err(&pdev->dev, "failed to remap I/O memory\n");
474 error = -ENXIO;
475 goto failed_free_mem;
476 }
477
478 keypad->clk = clk_get(&pdev->dev, NULL);
479 if (IS_ERR(keypad->clk)) {

--- 55 unchanged lines hidden (view full) ---

535 platform_set_drvdata(pdev, NULL);
536failed_free_dev:
537 input_free_device(input_dev);
538failed_put_clk:
539 clk_put(keypad->clk);
540failed_free_io:
541 iounmap(keypad->mmio_base);
542failed_free_mem:
471 if (keypad->mmio_base == NULL) {
472 dev_err(&pdev->dev, "failed to remap I/O memory\n");
473 error = -ENXIO;
474 goto failed_free_mem;
475 }
476
477 keypad->clk = clk_get(&pdev->dev, NULL);
478 if (IS_ERR(keypad->clk)) {

--- 55 unchanged lines hidden (view full) ---

534 platform_set_drvdata(pdev, NULL);
535failed_free_dev:
536 input_free_device(input_dev);
537failed_put_clk:
538 clk_put(keypad->clk);
539failed_free_io:
540 iounmap(keypad->mmio_base);
541failed_free_mem:
543 release_mem_region(res->start, res_size(res));
542 release_mem_region(res->start, resource_size(res));
544failed_free:
545 kfree(keypad);
546 return error;
547}
548
549static int __devexit pxa27x_keypad_remove(struct platform_device *pdev)
550{
551 struct pxa27x_keypad *keypad = platform_get_drvdata(pdev);
552 struct resource *res;
553
554 free_irq(keypad->irq, pdev);
543failed_free:
544 kfree(keypad);
545 return error;
546}
547
548static int __devexit pxa27x_keypad_remove(struct platform_device *pdev)
549{
550 struct pxa27x_keypad *keypad = platform_get_drvdata(pdev);
551 struct resource *res;
552
553 free_irq(keypad->irq, pdev);
555
556 clk_disable(keypad->clk);
557 clk_put(keypad->clk);
558
559 input_unregister_device(keypad->input_dev);
560 input_free_device(keypad->input_dev);
561
562 iounmap(keypad->mmio_base);
563
564 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
554 clk_put(keypad->clk);
555
556 input_unregister_device(keypad->input_dev);
557 input_free_device(keypad->input_dev);
558
559 iounmap(keypad->mmio_base);
560
561 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
565 release_mem_region(res->start, res_size(res));
562 release_mem_region(res->start, resource_size(res));
566
567 platform_set_drvdata(pdev, NULL);
568 kfree(keypad);
569 return 0;
570}
571
572/* work with hotplug and coldplug */
573MODULE_ALIAS("platform:pxa27x-keypad");

--- 27 unchanged lines hidden ---
563
564 platform_set_drvdata(pdev, NULL);
565 kfree(keypad);
566 return 0;
567}
568
569/* work with hotplug and coldplug */
570MODULE_ALIAS("platform:pxa27x-keypad");

--- 27 unchanged lines hidden ---