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/mfd/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};
36
37
38static const struct key_entry dm355evm_keys[] = {
39
40
41
42
43
44
45
46
47 { KE_KEY, 0x00d8, { KEY_OK } },
48 { KE_KEY, 0x00b8, { KEY_UP } },
49 { KE_KEY, 0x00e8, { KEY_DOWN } },
50 { KE_KEY, 0x0078, { KEY_LEFT } },
51 { KE_KEY, 0x00f0, { KEY_RIGHT } },
52
53
54
55
56
57
58
59
60
61
62
63
64
65 { KE_KEY, 0x300c, { KEY_POWER } },
66 { KE_KEY, 0x3000, { KEY_NUMERIC_0 } },
67 { KE_KEY, 0x3001, { KEY_NUMERIC_1 } },
68 { KE_KEY, 0x3002, { KEY_NUMERIC_2 } },
69 { KE_KEY, 0x3003, { KEY_NUMERIC_3 } },
70 { KE_KEY, 0x3004, { KEY_NUMERIC_4 } },
71 { KE_KEY, 0x3005, { KEY_NUMERIC_5 } },
72 { KE_KEY, 0x3006, { KEY_NUMERIC_6 } },
73 { KE_KEY, 0x3007, { KEY_NUMERIC_7 } },
74 { KE_KEY, 0x3008, { KEY_NUMERIC_8 } },
75 { KE_KEY, 0x3009, { KEY_NUMERIC_9 } },
76 { KE_KEY, 0x3022, { KEY_ENTER } },
77 { KE_KEY, 0x30ec, { KEY_MODE } },
78 { KE_KEY, 0x300f, { KEY_SELECT } },
79 { KE_KEY, 0x3020, { KEY_CHANNELUP } },
80 { KE_KEY, 0x302e, { KEY_MENU } },
81 { KE_KEY, 0x3011, { KEY_VOLUMEDOWN } },
82 { KE_KEY, 0x300d, { KEY_MUTE } },
83 { KE_KEY, 0x3010, { KEY_VOLUMEUP } },
84 { KE_KEY, 0x301e, { KEY_SUBTITLE } },
85 { KE_KEY, 0x3021, { KEY_CHANNELDOWN } },
86 { KE_KEY, 0x3022, { KEY_PREVIOUS } },
87 { KE_KEY, 0x3026, { KEY_SLEEP } },
88 { KE_KEY, 0x3172, { KEY_REWIND } },
89 { KE_KEY, 0x3175, { KEY_PLAY } },
90 { KE_KEY, 0x3174, { KEY_FASTFORWARD } },
91 { KE_KEY, 0x3177, { KEY_RECORD } },
92 { KE_KEY, 0x3176, { KEY_STOP } },
93 { KE_KEY, 0x3169, { KEY_PAUSE } },
94};
95
96
97
98
99
100
101
102
103static irqreturn_t dm355evm_keys_irq(int irq, void *_keys)
104{
105 static u16 last_event;
106 struct dm355evm_keys *keys = _keys;
107 const struct key_entry *ke;
108 unsigned int keycode;
109 int status;
110 u16 event;
111
112
113
114
115
116 for (;;) {
117 status = dm355evm_msp_read(DM355EVM_MSP_INPUT_HIGH);
118 if (status < 0) {
119 dev_dbg(keys->dev, "input high err %d\n",
120 status);
121 break;
122 }
123 event = status << 8;
124
125 status = dm355evm_msp_read(DM355EVM_MSP_INPUT_LOW);
126 if (status < 0) {
127 dev_dbg(keys->dev, "input low err %d\n",
128 status);
129 break;
130 }
131 event |= status;
132 if (event == 0xdead)
133 break;
134
135
136
137
138
139
140
141
142
143
144
145
146 if (event == last_event) {
147 last_event = 0;
148 continue;
149 }
150 last_event = event;
151
152
153 event &= ~0x0800;
154
155
156 ke = sparse_keymap_entry_from_scancode(keys->input, event);
157 keycode = ke ? ke->keycode : KEY_UNKNOWN;
158 dev_dbg(keys->dev,
159 "input event 0x%04x--> keycode %d\n",
160 event, keycode);
161
162
163 input_report_key(keys->input, keycode, 1);
164 input_sync(keys->input);
165 input_report_key(keys->input, keycode, 0);
166 input_sync(keys->input);
167 }
168
169 return IRQ_HANDLED;
170}
171
172
173
174static int dm355evm_keys_probe(struct platform_device *pdev)
175{
176 struct dm355evm_keys *keys;
177 struct input_dev *input;
178 int irq;
179 int error;
180
181 keys = devm_kzalloc(&pdev->dev, sizeof (*keys), GFP_KERNEL);
182 if (!keys)
183 return -ENOMEM;
184
185 input = devm_input_allocate_device(&pdev->dev);
186 if (!input)
187 return -ENOMEM;
188
189 keys->dev = &pdev->dev;
190 keys->input = input;
191
192 input->name = "DM355 EVM Controls";
193 input->phys = "dm355evm/input0";
194
195 input->id.bustype = BUS_I2C;
196 input->id.product = 0x0355;
197 input->id.version = dm355evm_msp_read(DM355EVM_MSP_FIRMREV);
198
199 error = sparse_keymap_setup(input, dm355evm_keys, NULL);
200 if (error)
201 return error;
202
203
204
205
206 irq = platform_get_irq(pdev, 0);
207 if (irq < 0)
208 return irq;
209
210 error = devm_request_threaded_irq(&pdev->dev, irq,
211 NULL, dm355evm_keys_irq,
212 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
213 dev_name(&pdev->dev), keys);
214 if (error)
215 return error;
216
217
218 error = input_register_device(input);
219 if (error)
220 return error;
221
222 return 0;
223}
224
225
226
227
228
229
230
231
232
233
234static struct platform_driver dm355evm_keys_driver = {
235 .probe = dm355evm_keys_probe,
236 .driver = {
237 .name = "dm355evm_keys",
238 },
239};
240module_platform_driver(dm355evm_keys_driver);
241
242MODULE_LICENSE("GPL");
243