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