1
2
3
4
5
6
7
8
9
10
11#include <linux/kernel.h>
12#include <linux/slab.h>
13#include <linux/input.h>
14#include <linux/input/sparse-keymap.h>
15#include <linux/platform_device.h>
16#include <linux/interrupt.h>
17
18#include <linux/i2c/dm355evm_msp.h>
19#include <linux/module.h>
20
21
22
23
24
25
26
27
28
29
30
31
32struct dm355evm_keys {
33 struct input_dev *input;
34 struct device *dev;
35 int irq;
36};
37
38
39static const struct key_entry dm355evm_keys[] = {
40
41
42
43
44
45
46
47
48 { KE_KEY, 0x00d8, { KEY_OK } },
49 { KE_KEY, 0x00b8, { KEY_UP } },
50 { KE_KEY, 0x00e8, { KEY_DOWN } },
51 { KE_KEY, 0x0078, { KEY_LEFT } },
52 { KE_KEY, 0x00f0, { KEY_RIGHT } },
53
54
55
56
57
58
59
60
61
62
63
64
65
66 { KE_KEY, 0x300c, { KEY_POWER } },
67 { KE_KEY, 0x3000, { KEY_NUMERIC_0 } },
68 { KE_KEY, 0x3001, { KEY_NUMERIC_1 } },
69 { KE_KEY, 0x3002, { KEY_NUMERIC_2 } },
70 { KE_KEY, 0x3003, { KEY_NUMERIC_3 } },
71 { KE_KEY, 0x3004, { KEY_NUMERIC_4 } },
72 { KE_KEY, 0x3005, { KEY_NUMERIC_5 } },
73 { KE_KEY, 0x3006, { KEY_NUMERIC_6 } },
74 { KE_KEY, 0x3007, { KEY_NUMERIC_7 } },
75 { KE_KEY, 0x3008, { KEY_NUMERIC_8 } },
76 { KE_KEY, 0x3009, { KEY_NUMERIC_9 } },
77 { KE_KEY, 0x3022, { KEY_ENTER } },
78 { KE_KEY, 0x30ec, { KEY_MODE } },
79 { KE_KEY, 0x300f, { KEY_SELECT } },
80 { KE_KEY, 0x3020, { KEY_CHANNELUP } },
81 { KE_KEY, 0x302e, { KEY_MENU } },
82 { KE_KEY, 0x3011, { KEY_VOLUMEDOWN } },
83 { KE_KEY, 0x300d, { KEY_MUTE } },
84 { KE_KEY, 0x3010, { KEY_VOLUMEUP } },
85 { KE_KEY, 0x301e, { KEY_SUBTITLE } },
86 { KE_KEY, 0x3021, { KEY_CHANNELDOWN } },
87 { KE_KEY, 0x3022, { KEY_PREVIOUS } },
88 { KE_KEY, 0x3026, { KEY_SLEEP } },
89 { KE_KEY, 0x3172, { KEY_REWIND } },
90 { KE_KEY, 0x3175, { KEY_PLAY } },
91 { KE_KEY, 0x3174, { KEY_FASTFORWARD } },
92 { KE_KEY, 0x3177, { KEY_RECORD } },
93 { KE_KEY, 0x3176, { KEY_STOP } },
94 { KE_KEY, 0x3169, { KEY_PAUSE } },
95};
96
97
98
99
100
101
102
103
104static irqreturn_t dm355evm_keys_irq(int irq, void *_keys)
105{
106 static u16 last_event;
107 struct dm355evm_keys *keys = _keys;
108 const struct key_entry *ke;
109 unsigned int keycode;
110 int status;
111 u16 event;
112
113
114
115
116
117 for (;;) {
118 status = dm355evm_msp_read(DM355EVM_MSP_INPUT_HIGH);
119 if (status < 0) {
120 dev_dbg(keys->dev, "input high err %d\n",
121 status);
122 break;
123 }
124 event = status << 8;
125
126 status = dm355evm_msp_read(DM355EVM_MSP_INPUT_LOW);
127 if (status < 0) {
128 dev_dbg(keys->dev, "input low err %d\n",
129 status);
130 break;
131 }
132 event |= status;
133 if (event == 0xdead)
134 break;
135
136
137
138
139
140
141
142
143
144
145
146
147 if (event == last_event) {
148 last_event = 0;
149 continue;
150 }
151 last_event = event;
152
153
154 event &= ~0x0800;
155
156
157 ke = sparse_keymap_entry_from_scancode(keys->input, event);
158 keycode = ke ? ke->keycode : KEY_UNKNOWN;
159 dev_dbg(keys->dev,
160 "input event 0x%04x--> keycode %d\n",
161 event, keycode);
162
163
164 input_report_key(keys->input, keycode, 1);
165 input_sync(keys->input);
166 input_report_key(keys->input, keycode, 0);
167 input_sync(keys->input);
168 }
169
170 return IRQ_HANDLED;
171}
172
173
174
175static int dm355evm_keys_probe(struct platform_device *pdev)
176{
177 struct dm355evm_keys *keys;
178 struct input_dev *input;
179 int status;
180
181
182 keys = kzalloc(sizeof *keys, GFP_KERNEL);
183 input = input_allocate_device();
184 if (!keys || !input) {
185 status = -ENOMEM;
186 goto fail1;
187 }
188
189 keys->dev = &pdev->dev;
190 keys->input = input;
191
192
193 status = platform_get_irq(pdev, 0);
194 if (status < 0)
195 goto fail1;
196 keys->irq = status;
197
198 input_set_drvdata(input, keys);
199
200 input->name = "DM355 EVM Controls";
201 input->phys = "dm355evm/input0";
202 input->dev.parent = &pdev->dev;
203
204 input->id.bustype = BUS_I2C;
205 input->id.product = 0x0355;
206 input->id.version = dm355evm_msp_read(DM355EVM_MSP_FIRMREV);
207
208 status = sparse_keymap_setup(input, dm355evm_keys, NULL);
209 if (status)
210 goto fail1;
211
212
213
214 status = request_threaded_irq(keys->irq, NULL, dm355evm_keys_irq,
215 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
216 dev_name(&pdev->dev), keys);
217 if (status < 0)
218 goto fail2;
219
220
221 status = input_register_device(input);
222 if (status < 0)
223 goto fail3;
224
225 platform_set_drvdata(pdev, keys);
226
227 return 0;
228
229fail3:
230 free_irq(keys->irq, keys);
231fail2:
232 sparse_keymap_free(input);
233fail1:
234 input_free_device(input);
235 kfree(keys);
236 dev_err(&pdev->dev, "can't register, err %d\n", status);
237
238 return status;
239}
240
241static int dm355evm_keys_remove(struct platform_device *pdev)
242{
243 struct dm355evm_keys *keys = platform_get_drvdata(pdev);
244
245 free_irq(keys->irq, keys);
246 sparse_keymap_free(keys->input);
247 input_unregister_device(keys->input);
248 kfree(keys);
249
250 return 0;
251}
252
253
254
255
256
257
258
259
260
261
262static struct platform_driver dm355evm_keys_driver = {
263 .probe = dm355evm_keys_probe,
264 .remove = dm355evm_keys_remove,
265 .driver = {
266 .name = "dm355evm_keys",
267 },
268};
269module_platform_driver(dm355evm_keys_driver);
270
271MODULE_LICENSE("GPL");
272