aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/misc
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2009-12-04 13:22:25 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2009-12-07 12:26:50 -0500
commit6604072798da52547111cc06afacb8d9f2a907cf (patch)
tree11e4024e1e8a87f367f1901983e5b41064483615 /drivers/input/misc
parente97af4cbbe500e6a3f4e189fe9324c5b99192dd6 (diff)
Input: dm355evm_kbd - switch to using sparse keymap library
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input/misc')
-rw-r--r--drivers/input/misc/Kconfig1
-rw-r--r--drivers/input/misc/dm355evm_keys.c150
2 files changed, 57 insertions, 94 deletions
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index d25ecbb87bfc..16ec5233441c 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -282,6 +282,7 @@ config INPUT_RB532_BUTTON
282config INPUT_DM355EVM 282config INPUT_DM355EVM
283 tristate "TI DaVinci DM355 EVM Keypad and IR Remote" 283 tristate "TI DaVinci DM355 EVM Keypad and IR Remote"
284 depends on MFD_DM355EVM_MSP 284 depends on MFD_DM355EVM_MSP
285 select INPUT_SPARSEKMAP
285 help 286 help
286 Supports the pushbuttons and IR remote used with 287 Supports the pushbuttons and IR remote used with
287 the DM355 EVM board. 288 the DM355 EVM board.
diff --git a/drivers/input/misc/dm355evm_keys.c b/drivers/input/misc/dm355evm_keys.c
index f2b67dc81d80..766c06911f41 100644
--- a/drivers/input/misc/dm355evm_keys.c
+++ b/drivers/input/misc/dm355evm_keys.c
@@ -11,6 +11,7 @@
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/input.h> 13#include <linux/input.h>
14#include <linux/input/sparse-keymap.h>
14#include <linux/platform_device.h> 15#include <linux/platform_device.h>
15#include <linux/interrupt.h> 16#include <linux/interrupt.h>
16 17
@@ -33,12 +34,8 @@ struct dm355evm_keys {
33 int irq; 34 int irq;
34}; 35};
35 36
36/* These initial keycodes can be remapped by dm355evm_setkeycode(). */ 37/* These initial keycodes can be remapped */
37static struct { 38static const struct key_entry dm355evm_keys[] = {
38 u16 event;
39 u16 keycode;
40} dm355evm_keys[] = {
41
42 /* 39 /*
43 * Pushbuttons on the EVM board ... note that the labels for these 40 * Pushbuttons on the EVM board ... note that the labels for these
44 * are SW10/SW11/etc on the PC board. The left/right orientation 41 * are SW10/SW11/etc on the PC board. The left/right orientation
@@ -47,11 +44,11 @@ static struct {
47 * is to the right. (That is, rotate the board counter-clockwise 44 * is to the right. (That is, rotate the board counter-clockwise
48 * by 90 degrees from the SW10/etc and "DM355 EVM" labels.) 45 * by 90 degrees from the SW10/etc and "DM355 EVM" labels.)
49 */ 46 */
50 { 0x00d8, KEY_OK, }, /* SW12 */ 47 { KE_KEY, 0x00d8, { KEY_OK } }, /* SW12 */
51 { 0x00b8, KEY_UP, }, /* SW13 */ 48 { KE_KEY, 0x00b8, { KEY_UP } }, /* SW13 */
52 { 0x00e8, KEY_DOWN, }, /* SW11 */ 49 { KE_KEY, 0x00e8, { KEY_DOWN } }, /* SW11 */
53 { 0x0078, KEY_LEFT, }, /* SW14 */ 50 { KE_KEY, 0x0078, { KEY_LEFT } }, /* SW14 */
54 { 0x00f0, KEY_RIGHT, }, /* SW10 */ 51 { KE_KEY, 0x00f0, { KEY_RIGHT } }, /* SW10 */
55 52
56 /* 53 /*
57 * IR buttons ... codes assigned to match the universal remote 54 * IR buttons ... codes assigned to match the universal remote
@@ -65,35 +62,35 @@ static struct {
65 * RC5 codes are 14 bits, with two start bits (0x3 prefix) 62 * RC5 codes are 14 bits, with two start bits (0x3 prefix)
66 * and a toggle bit (masked out below). 63 * and a toggle bit (masked out below).
67 */ 64 */
68 { 0x300c, KEY_POWER, }, /* NOTE: docs omit this */ 65 { KE_KEY, 0x300c, { KEY_POWER } }, /* NOTE: docs omit this */
69 { 0x3000, KEY_NUMERIC_0, }, 66 { KE_KEY, 0x3000, { KEY_NUMERIC_0 } },
70 { 0x3001, KEY_NUMERIC_1, }, 67 { KE_KEY, 0x3001, { KEY_NUMERIC_1 } },
71 { 0x3002, KEY_NUMERIC_2, }, 68 { KE_KEY, 0x3002, { KEY_NUMERIC_2 } },
72 { 0x3003, KEY_NUMERIC_3, }, 69 { KE_KEY, 0x3003, { KEY_NUMERIC_3 } },
73 { 0x3004, KEY_NUMERIC_4, }, 70 { KE_KEY, 0x3004, { KEY_NUMERIC_4 } },
74 { 0x3005, KEY_NUMERIC_5, }, 71 { KE_KEY, 0x3005, { KEY_NUMERIC_5 } },
75 { 0x3006, KEY_NUMERIC_6, }, 72 { KE_KEY, 0x3006, { KEY_NUMERIC_6 } },
76 { 0x3007, KEY_NUMERIC_7, }, 73 { KE_KEY, 0x3007, { KEY_NUMERIC_7 } },
77 { 0x3008, KEY_NUMERIC_8, }, 74 { KE_KEY, 0x3008, { KEY_NUMERIC_8 } },
78 { 0x3009, KEY_NUMERIC_9, }, 75 { KE_KEY, 0x3009, { KEY_NUMERIC_9 } },
79 { 0x3022, KEY_ENTER, }, 76 { KE_KEY, 0x3022, { KEY_ENTER } },
80 { 0x30ec, KEY_MODE, }, /* "tv/vcr/..." */ 77 { KE_KEY, 0x30ec, { KEY_MODE } }, /* "tv/vcr/..." */
81 { 0x300f, KEY_SELECT, }, /* "info" */ 78 { KE_KEY, 0x300f, { KEY_SELECT } }, /* "info" */
82 { 0x3020, KEY_CHANNELUP, }, /* "up" */ 79 { KE_KEY, 0x3020, { KEY_CHANNELUP } }, /* "up" */
83 { 0x302e, KEY_MENU, }, /* "in/out" */ 80 { KE_KEY, 0x302e, { KEY_MENU } }, /* "in/out" */
84 { 0x3011, KEY_VOLUMEDOWN, }, /* "left" */ 81 { KE_KEY, 0x3011, { KEY_VOLUMEDOWN } }, /* "left" */
85 { 0x300d, KEY_MUTE, }, /* "ok" */ 82 { KE_KEY, 0x300d, { KEY_MUTE } }, /* "ok" */
86 { 0x3010, KEY_VOLUMEUP, }, /* "right" */ 83 { KE_KEY, 0x3010, { KEY_VOLUMEUP } }, /* "right" */
87 { 0x301e, KEY_SUBTITLE, }, /* "cc" */ 84 { KE_KEY, 0x301e, { KEY_SUBTITLE } }, /* "cc" */
88 { 0x3021, KEY_CHANNELDOWN, }, /* "down" */ 85 { KE_KEY, 0x3021, { KEY_CHANNELDOWN } },/* "down" */
89 { 0x3022, KEY_PREVIOUS, }, 86 { KE_KEY, 0x3022, { KEY_PREVIOUS } },
90 { 0x3026, KEY_SLEEP, }, 87 { KE_KEY, 0x3026, { KEY_SLEEP } },
91 { 0x3172, KEY_REWIND, }, /* NOTE: docs wrongly say 0x30ca */ 88 { KE_KEY, 0x3172, { KEY_REWIND } }, /* NOTE: docs wrongly say 0x30ca */
92 { 0x3175, KEY_PLAY, }, 89 { KE_KEY, 0x3175, { KEY_PLAY } },
93 { 0x3174, KEY_FASTFORWARD, }, 90 { KE_KEY, 0x3174, { KEY_FASTFORWARD } },
94 { 0x3177, KEY_RECORD, }, 91 { KE_KEY, 0x3177, { KEY_RECORD } },
95 { 0x3176, KEY_STOP, }, 92 { KE_KEY, 0x3176, { KEY_STOP } },
96 { 0x3169, KEY_PAUSE, }, 93 { KE_KEY, 0x3169, { KEY_PAUSE } },
97}; 94};
98 95
99/* 96/*
@@ -105,19 +102,18 @@ static struct {
105 */ 102 */
106static irqreturn_t dm355evm_keys_irq(int irq, void *_keys) 103static irqreturn_t dm355evm_keys_irq(int irq, void *_keys)
107{ 104{
108 struct dm355evm_keys *keys = _keys; 105 static u16 last_event;
109 int status; 106 struct dm355evm_keys *keys = _keys;
107 const struct key_entry *ke;
108 unsigned int keycode;
109 int status;
110 u16 event;
110 111
111 /* For simplicity we ignore INPUT_COUNT and just read 112 /* For simplicity we ignore INPUT_COUNT and just read
112 * events until we get the "queue empty" indicator. 113 * events until we get the "queue empty" indicator.
113 * Reading INPUT_LOW decrements the count. 114 * Reading INPUT_LOW decrements the count.
114 */ 115 */
115 for (;;) { 116 for (;;) {
116 static u16 last_event;
117 u16 event;
118 int keycode;
119 int i;
120
121 status = dm355evm_msp_read(DM355EVM_MSP_INPUT_HIGH); 117 status = dm355evm_msp_read(DM355EVM_MSP_INPUT_HIGH);
122 if (status < 0) { 118 if (status < 0) {
123 dev_dbg(keys->dev, "input high err %d\n", 119 dev_dbg(keys->dev, "input high err %d\n",
@@ -156,14 +152,9 @@ static irqreturn_t dm355evm_keys_irq(int irq, void *_keys)
156 /* ignore the RC5 toggle bit */ 152 /* ignore the RC5 toggle bit */
157 event &= ~0x0800; 153 event &= ~0x0800;
158 154
159 /* find the key, or leave it as unknown */ 155 /* find the key, or report it as unknown */
160 keycode = KEY_UNKNOWN; 156 ke = sparse_keymap_entry_from_scancode(keys->input, event);
161 for (i = 0; i < ARRAY_SIZE(dm355evm_keys); i++) { 157 keycode = ke ? ke->keycode : KEY_UNKNOWN;
162 if (dm355evm_keys[i].event != event)
163 continue;
164 keycode = dm355evm_keys[i].keycode;
165 break;
166 }
167 dev_dbg(keys->dev, 158 dev_dbg(keys->dev,
168 "input event 0x%04x--> keycode %d\n", 159 "input event 0x%04x--> keycode %d\n",
169 event, keycode); 160 event, keycode);
@@ -174,36 +165,8 @@ static irqreturn_t dm355evm_keys_irq(int irq, void *_keys)
174 input_report_key(keys->input, keycode, 0); 165 input_report_key(keys->input, keycode, 0);
175 input_sync(keys->input); 166 input_sync(keys->input);
176 } 167 }
177 return IRQ_HANDLED;
178}
179 168
180static int dm355evm_setkeycode(struct input_dev *dev, int index, int keycode) 169 return IRQ_HANDLED;
181{
182 u16 old_keycode;
183 unsigned i;
184
185 if (((unsigned)index) >= ARRAY_SIZE(dm355evm_keys))
186 return -EINVAL;
187
188 old_keycode = dm355evm_keys[index].keycode;
189 dm355evm_keys[index].keycode = keycode;
190 set_bit(keycode, dev->keybit);
191
192 for (i = 0; i < ARRAY_SIZE(dm355evm_keys); i++) {
193 if (dm355evm_keys[index].keycode == old_keycode)
194 goto done;
195 }
196 clear_bit(old_keycode, dev->keybit);
197done:
198 return 0;
199}
200
201static int dm355evm_getkeycode(struct input_dev *dev, int index, int *keycode)
202{
203 if (((unsigned)index) >= ARRAY_SIZE(dm355evm_keys))
204 return -EINVAL;
205
206 return dm355evm_keys[index].keycode;
207} 170}
208 171
209/*----------------------------------------------------------------------*/ 172/*----------------------------------------------------------------------*/
@@ -213,7 +176,6 @@ static int __devinit dm355evm_keys_probe(struct platform_device *pdev)
213 struct dm355evm_keys *keys; 176 struct dm355evm_keys *keys;
214 struct input_dev *input; 177 struct input_dev *input;
215 int status; 178 int status;
216 int i;
217 179
218 /* allocate instance struct and input dev */ 180 /* allocate instance struct and input dev */
219 keys = kzalloc(sizeof *keys, GFP_KERNEL); 181 keys = kzalloc(sizeof *keys, GFP_KERNEL);
@@ -242,31 +204,30 @@ static int __devinit dm355evm_keys_probe(struct platform_device *pdev)
242 input->id.product = 0x0355; 204 input->id.product = 0x0355;
243 input->id.version = dm355evm_msp_read(DM355EVM_MSP_FIRMREV); 205 input->id.version = dm355evm_msp_read(DM355EVM_MSP_FIRMREV);
244 206
245 input->evbit[0] = BIT(EV_KEY); 207 status = sparse_keymap_setup(input, dm355evm_keys, NULL);
246 for (i = 0; i < ARRAY_SIZE(dm355evm_keys); i++) 208 if (status)
247 __set_bit(dm355evm_keys[i].keycode, input->keybit); 209 goto fail1;
248
249 input->setkeycode = dm355evm_setkeycode;
250 input->getkeycode = dm355evm_getkeycode;
251 210
252 /* REVISIT: flush the event queue? */ 211 /* REVISIT: flush the event queue? */
253 212
254 status = request_threaded_irq(keys->irq, NULL, dm355evm_keys_irq, 213 status = request_threaded_irq(keys->irq, NULL, dm355evm_keys_irq,
255 IRQF_TRIGGER_FALLING, dev_name(&pdev->dev), keys); 214 IRQF_TRIGGER_FALLING, dev_name(&pdev->dev), keys);
256 if (status < 0) 215 if (status < 0)
257 goto fail1; 216 goto fail2;
258 217
259 /* register */ 218 /* register */
260 status = input_register_device(input); 219 status = input_register_device(input);
261 if (status < 0) 220 if (status < 0)
262 goto fail2; 221 goto fail3;
263 222
264 platform_set_drvdata(pdev, keys); 223 platform_set_drvdata(pdev, keys);
265 224
266 return 0; 225 return 0;
267 226
268fail2: 227fail3:
269 free_irq(keys->irq, keys); 228 free_irq(keys->irq, keys);
229fail2:
230 sparse_keymap_free(input);
270fail1: 231fail1:
271 input_free_device(input); 232 input_free_device(input);
272 kfree(keys); 233 kfree(keys);
@@ -280,6 +241,7 @@ static int __devexit dm355evm_keys_remove(struct platform_device *pdev)
280 struct dm355evm_keys *keys = platform_get_drvdata(pdev); 241 struct dm355evm_keys *keys = platform_get_drvdata(pdev);
281 242
282 free_irq(keys->irq, keys); 243 free_irq(keys->irq, keys);
244 sparse_keymap_free(keys->input);
283 input_unregister_device(keys->input); 245 input_unregister_device(keys->input);
284 kfree(keys); 246 kfree(keys);
285 247