diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/input/sparse-keymap.c | 81 |
1 files changed, 65 insertions, 16 deletions
diff --git a/drivers/input/sparse-keymap.c b/drivers/input/sparse-keymap.c index 014248344763..a29a7812bd46 100644 --- a/drivers/input/sparse-keymap.c +++ b/drivers/input/sparse-keymap.c | |||
@@ -22,6 +22,37 @@ MODULE_DESCRIPTION("Generic support for sparse keymaps"); | |||
22 | MODULE_LICENSE("GPL v2"); | 22 | MODULE_LICENSE("GPL v2"); |
23 | MODULE_VERSION("0.1"); | 23 | MODULE_VERSION("0.1"); |
24 | 24 | ||
25 | static unsigned int sparse_keymap_get_key_index(struct input_dev *dev, | ||
26 | const struct key_entry *k) | ||
27 | { | ||
28 | struct key_entry *key; | ||
29 | unsigned int idx = 0; | ||
30 | |||
31 | for (key = dev->keycode; key->type != KE_END; key++) { | ||
32 | if (key->type == KE_KEY) { | ||
33 | if (key == k) | ||
34 | break; | ||
35 | idx++; | ||
36 | } | ||
37 | } | ||
38 | |||
39 | return idx; | ||
40 | } | ||
41 | |||
42 | static struct key_entry *sparse_keymap_entry_by_index(struct input_dev *dev, | ||
43 | unsigned int index) | ||
44 | { | ||
45 | struct key_entry *key; | ||
46 | unsigned int key_cnt = 0; | ||
47 | |||
48 | for (key = dev->keycode; key->type != KE_END; key++) | ||
49 | if (key->type == KE_KEY) | ||
50 | if (key_cnt++ == index) | ||
51 | return key; | ||
52 | |||
53 | return NULL; | ||
54 | } | ||
55 | |||
25 | /** | 56 | /** |
26 | * sparse_keymap_entry_from_scancode - perform sparse keymap lookup | 57 | * sparse_keymap_entry_from_scancode - perform sparse keymap lookup |
27 | * @dev: Input device using sparse keymap | 58 | * @dev: Input device using sparse keymap |
@@ -64,16 +95,36 @@ struct key_entry *sparse_keymap_entry_from_keycode(struct input_dev *dev, | |||
64 | } | 95 | } |
65 | EXPORT_SYMBOL(sparse_keymap_entry_from_keycode); | 96 | EXPORT_SYMBOL(sparse_keymap_entry_from_keycode); |
66 | 97 | ||
98 | static struct key_entry *sparse_keymap_locate(struct input_dev *dev, | ||
99 | const struct input_keymap_entry *ke) | ||
100 | { | ||
101 | struct key_entry *key; | ||
102 | unsigned int scancode; | ||
103 | |||
104 | if (ke->flags & INPUT_KEYMAP_BY_INDEX) | ||
105 | key = sparse_keymap_entry_by_index(dev, ke->index); | ||
106 | else if (input_scancode_to_scalar(ke, &scancode) == 0) | ||
107 | key = sparse_keymap_entry_from_scancode(dev, scancode); | ||
108 | else | ||
109 | key = NULL; | ||
110 | |||
111 | return key; | ||
112 | } | ||
113 | |||
67 | static int sparse_keymap_getkeycode(struct input_dev *dev, | 114 | static int sparse_keymap_getkeycode(struct input_dev *dev, |
68 | unsigned int scancode, | 115 | struct input_keymap_entry *ke) |
69 | unsigned int *keycode) | ||
70 | { | 116 | { |
71 | const struct key_entry *key; | 117 | const struct key_entry *key; |
72 | 118 | ||
73 | if (dev->keycode) { | 119 | if (dev->keycode) { |
74 | key = sparse_keymap_entry_from_scancode(dev, scancode); | 120 | key = sparse_keymap_locate(dev, ke); |
75 | if (key && key->type == KE_KEY) { | 121 | if (key && key->type == KE_KEY) { |
76 | *keycode = key->keycode; | 122 | ke->keycode = key->keycode; |
123 | if (!(ke->flags & INPUT_KEYMAP_BY_INDEX)) | ||
124 | ke->index = | ||
125 | sparse_keymap_get_key_index(dev, key); | ||
126 | ke->len = sizeof(key->code); | ||
127 | memcpy(ke->scancode, &key->code, sizeof(key->code)); | ||
77 | return 0; | 128 | return 0; |
78 | } | 129 | } |
79 | } | 130 | } |
@@ -82,20 +133,19 @@ static int sparse_keymap_getkeycode(struct input_dev *dev, | |||
82 | } | 133 | } |
83 | 134 | ||
84 | static int sparse_keymap_setkeycode(struct input_dev *dev, | 135 | static int sparse_keymap_setkeycode(struct input_dev *dev, |
85 | unsigned int scancode, | 136 | const struct input_keymap_entry *ke, |
86 | unsigned int keycode) | 137 | unsigned int *old_keycode) |
87 | { | 138 | { |
88 | struct key_entry *key; | 139 | struct key_entry *key; |
89 | int old_keycode; | ||
90 | 140 | ||
91 | if (dev->keycode) { | 141 | if (dev->keycode) { |
92 | key = sparse_keymap_entry_from_scancode(dev, scancode); | 142 | key = sparse_keymap_locate(dev, ke); |
93 | if (key && key->type == KE_KEY) { | 143 | if (key && key->type == KE_KEY) { |
94 | old_keycode = key->keycode; | 144 | *old_keycode = key->keycode; |
95 | key->keycode = keycode; | 145 | key->keycode = ke->keycode; |
96 | set_bit(keycode, dev->keybit); | 146 | set_bit(ke->keycode, dev->keybit); |
97 | if (!sparse_keymap_entry_from_keycode(dev, old_keycode)) | 147 | if (!sparse_keymap_entry_from_keycode(dev, *old_keycode)) |
98 | clear_bit(old_keycode, dev->keybit); | 148 | clear_bit(*old_keycode, dev->keybit); |
99 | return 0; | 149 | return 0; |
100 | } | 150 | } |
101 | } | 151 | } |
@@ -159,15 +209,14 @@ int sparse_keymap_setup(struct input_dev *dev, | |||
159 | 209 | ||
160 | dev->keycode = map; | 210 | dev->keycode = map; |
161 | dev->keycodemax = map_size; | 211 | dev->keycodemax = map_size; |
162 | dev->getkeycode = sparse_keymap_getkeycode; | 212 | dev->getkeycode_new = sparse_keymap_getkeycode; |
163 | dev->setkeycode = sparse_keymap_setkeycode; | 213 | dev->setkeycode_new = sparse_keymap_setkeycode; |
164 | 214 | ||
165 | return 0; | 215 | return 0; |
166 | 216 | ||
167 | err_out: | 217 | err_out: |
168 | kfree(map); | 218 | kfree(map); |
169 | return error; | 219 | return error; |
170 | |||
171 | } | 220 | } |
172 | EXPORT_SYMBOL(sparse_keymap_setup); | 221 | EXPORT_SYMBOL(sparse_keymap_setup); |
173 | 222 | ||