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