aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2007-11-04 00:41:36 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2008-01-21 01:11:06 -0500
commitb037b08e59633d939d79f1df9c43c6625f8db904 (patch)
treeb594b434d8ac0cf489b12bb629ddb2bc1bd40120 /drivers/input
parent72341eea6f62a91f270157d86c0c82d832627dfd (diff)
Input: cobalt_btns - add support for loadable keymaps
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/misc/cobalt_btns.c73
1 files changed, 36 insertions, 37 deletions
diff --git a/drivers/input/misc/cobalt_btns.c b/drivers/input/misc/cobalt_btns.c
index 1aef97ed5e84..4833b1a82623 100644
--- a/drivers/input/misc/cobalt_btns.c
+++ b/drivers/input/misc/cobalt_btns.c
@@ -27,55 +27,48 @@
27#define BUTTONS_COUNT_THRESHOLD 3 27#define BUTTONS_COUNT_THRESHOLD 3
28#define BUTTONS_STATUS_MASK 0xfe000000 28#define BUTTONS_STATUS_MASK 0xfe000000
29 29
30static const unsigned short cobalt_map[] = {
31 KEY_RESERVED,
32 KEY_RESTART,
33 KEY_LEFT,
34 KEY_UP,
35 KEY_DOWN,
36 KEY_RIGHT,
37 KEY_ENTER,
38 KEY_SELECT
39};
40
30struct buttons_dev { 41struct buttons_dev {
31 struct input_polled_dev *poll_dev; 42 struct input_polled_dev *poll_dev;
43 unsigned short keymap[ARRAY_SIZE(cobalt_map)];
44 int count[ARRAY_SIZE(cobalt_map)];
32 void __iomem *reg; 45 void __iomem *reg;
33}; 46};
34 47
35struct buttons_map {
36 uint32_t mask;
37 int keycode;
38 int count;
39};
40
41static struct buttons_map buttons_map[] = {
42 { 0x02000000, KEY_RESTART, },
43 { 0x04000000, KEY_LEFT, },
44 { 0x08000000, KEY_UP, },
45 { 0x10000000, KEY_DOWN, },
46 { 0x20000000, KEY_RIGHT, },
47 { 0x40000000, KEY_ENTER, },
48 { 0x80000000, KEY_SELECT, },
49};
50
51static void handle_buttons(struct input_polled_dev *dev) 48static void handle_buttons(struct input_polled_dev *dev)
52{ 49{
53 struct buttons_map *button = buttons_map;
54 struct buttons_dev *bdev = dev->private; 50 struct buttons_dev *bdev = dev->private;
55 struct input_dev *input = dev->input; 51 struct input_dev *input = dev->input;
56 uint32_t status; 52 uint32_t status;
57 int i; 53 int i;
58 54
59 status = readl(bdev->reg); 55 status = ~readl(bdev->reg) >> 24;
60 status = ~status & BUTTONS_STATUS_MASK;
61 56
62 for (i = 0; i < ARRAY_SIZE(buttons_map); i++) { 57 for (i = 0; i < ARRAY_SIZE(bdev->keymap); i++) {
63 if (status & button->mask) { 58 if (status & (1UL << i)) {
64 button->count++; 59 if (++bdev->count[i] == BUTTONS_COUNT_THRESHOLD) {
60 input_event(input, EV_MSC, MSC_SCAN, i);
61 input_report_key(input, bdev->keymap[i], 1);
62 input_sync(input);
63 }
65 } else { 64 } else {
66 if (button->count >= BUTTONS_COUNT_THRESHOLD) { 65 if (bdev->count[i] >= BUTTONS_COUNT_THRESHOLD) {
67 input_report_key(input, button->keycode, 0); 66 input_event(input, EV_MSC, MSC_SCAN, i);
67 input_report_key(input, bdev->keymap[i], 0);
68 input_sync(input); 68 input_sync(input);
69 } 69 }
70 button->count = 0; 70 bdev->count[i] = 0;
71 }
72
73 if (button->count == BUTTONS_COUNT_THRESHOLD) {
74 input_report_key(input, button->keycode, 1);
75 input_sync(input);
76 } 71 }
77
78 button++;
79 } 72 }
80} 73}
81 74
@@ -94,6 +87,8 @@ static int __devinit cobalt_buttons_probe(struct platform_device *pdev)
94 goto err_free_mem; 87 goto err_free_mem;
95 } 88 }
96 89
90 memcpy(bdev->keymap, cobalt_map, sizeof(bdev->keymap));
91
97 poll_dev->private = bdev; 92 poll_dev->private = bdev;
98 poll_dev->poll = handle_buttons; 93 poll_dev->poll = handle_buttons;
99 poll_dev->poll_interval = BUTTONS_POLL_INTERVAL; 94 poll_dev->poll_interval = BUTTONS_POLL_INTERVAL;
@@ -104,11 +99,15 @@ static int __devinit cobalt_buttons_probe(struct platform_device *pdev)
104 input->id.bustype = BUS_HOST; 99 input->id.bustype = BUS_HOST;
105 input->cdev.dev = &pdev->dev; 100 input->cdev.dev = &pdev->dev;
106 101
107 input->evbit[0] = BIT_MASK(EV_KEY); 102 input->keycode = pdev->keymap;
108 for (i = 0; i < ARRAY_SIZE(buttons_map); i++) { 103 input->keycodemax = ARRAY_SIZE(pdev->keymap);
109 set_bit(buttons_map[i].keycode, input->keybit); 104 input->keycodesize = sizeof(unsigned short);
110 buttons_map[i].count = 0; 105
111 } 106 input_set_capability(input, EV_MSC, MSC_SCAN);
107 __set_bit(EV_KEY, input->evbit);
108 for (i = 0; i < ARRAY_SIZE(buttons_map); i++)
109 __set_bit(input->keycode[i], input->keybit);
110 __clear_bit(KEY_RESERVED, input->keybit);
112 111
113 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 112 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
114 if (!res) { 113 if (!res) {