1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
/*
* SiI8620 Linux Driver
*
* Copyright (C) 2013-2014 Silicon Image, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation version 2.
* This program is distributed AS-IS WITHOUT ANY WARRANTY of any
* kind, whether express or implied; INCLUDING without the implied warranty
* of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE or NON-INFRINGEMENT.
* See the GNU General Public License for more details at
* http://www.gnu.org/licenses/gpl-2.0.html.
*/
#if (INCLUDE_RBP == 1)
#include <linux/input.h>
#include <linux/cdev.h>
#include <linux/hrtimer.h>
#include "si_fw_macros.h"
#include "si_infoframe.h"
#include "si_edid.h"
#include "si_mhl_defs.h"
#include "si_mhl2_edid_3d_api.h"
#include "si_mhl_tx_hw_drv_api.h"
#ifdef MEDIA_DATA_TUNNEL_SUPPORT
#include "si_mdt_inputdev.h"
#endif
#include "mhl_linux_tx.h"
#include "platform.h"
#include "mhl_rbp_inputdev.h"
enum rbp_state_e {
ph0_idle,
ph3_press_and_hold_button,
ph8_hold_mode,
num_rbp_states
};
static char *state_strings[num_rbp_states] = {
"idle",
"press_and_hold_button",
"hold_mode"
};
enum rbp_event_e {
rbp_normal_button_press,
rbp_normal_button_press_same,
rbp_normal_button_release,
rbp_normal_button_release_same,
rbp_press_and_hold_button_press,
rbp_press_and_hold_button_press_same,
rbp_press_and_hold_button_release,
rbp_press_and_hold_button_release_same,
rbp_T_hold_maintain_expired,
rbp_T_press_mode_expired,
num_rbp_events
};
static char *event_strings[num_rbp_events] = {
"normal_button_press",
"normal_button_press_same",
"normal_button_release",
"normal_button_release_same",
"press_and_hold_button_press",
"press_and_hold_button_press_same",
"press_and_hold_button_release",
"press_and_hold_button_release_same",
"rbp_T_hold_maintain_expired",
"rbp_T_press_mode_expired"
};
enum rbp_state_e current_rbp_state = ph0_idle;
uint8_t rbp_previous_button = 0, rbp_current_button = 0;
static int rbp_trigger_button_action(struct mhl_dev_context *dev_context,
uint8_t index, bool press_release)
{
int status = -EINVAL;
if (dev_context->rbp_input_dev) {
input_report_key(dev_context->rbp_input_dev, index,
press_release);
input_sync(dev_context->rbp_input_dev);
status = 0;
}
return status;
}
static int handle_rbp_event(struct mhl_dev_context *dev_context,
uint8_t current_button, uint8_t prev_button, enum rbp_event_e event)
{
int status = 0;
uint8_t current_index = current_button & MHL_RBP_BUTTON_ID_MASK;
uint8_t prev_index = prev_button & MHL_RBP_BUTTON_ID_MASK;
MHL_TX_DBG_ERR("received 0x%02x: %s(%d) in state: %s(%d)\n",
current_button, event_strings[event], event,
state_strings[current_rbp_state], current_rbp_state);
/* now process the event according to the current state */
switch (current_rbp_state) {
case ph0_idle:
switch (event) {
case rbp_normal_button_press:
case rbp_normal_button_press_same:
status =
rbp_trigger_button_action(dev_context,
current_index, 1);
/* no update for current_rbp_state */
break;
case rbp_normal_button_release:
case rbp_normal_button_release_same:
status =
rbp_trigger_button_action(dev_context,
current_index, 0);
/* no update for current_rbp_state */
break;
case rbp_press_and_hold_button_press:
case rbp_press_and_hold_button_press_same:
mhl_tx_start_timer(dev_context,
dev_context->timer_T_press_mode,
T_PRESS_MODE);
current_rbp_state = ph3_press_and_hold_button;
break;
case rbp_press_and_hold_button_release:
case rbp_press_and_hold_button_release_same:
MHL_TX_DBG_ERR("unexpected %s(%d) in state: %s(%d)\n",
event_strings[event], event,
state_strings[current_rbp_state],
current_rbp_state);
break;
default:
MHL_TX_DBG_ERR("unexpected event: %d in state: %d\n",
event, current_rbp_state);
/* no update for current_rbp_state */
status = -EINVAL;
}
break;
case ph3_press_and_hold_button:
switch (event) {
case rbp_normal_button_press:
case rbp_normal_button_press_same:
mhl_tx_stop_timer(dev_context,
dev_context->timer_T_press_mode);
rbp_trigger_button_action(dev_context, prev_index, 0);
/* OK to overwrite status */
status =
rbp_trigger_button_action(dev_context,
current_index, 1);
current_rbp_state = ph0_idle;
break;
case rbp_normal_button_release:
case rbp_normal_button_release_same:
mhl_tx_stop_timer(dev_context,
dev_context->timer_T_press_mode);
rbp_trigger_button_action(dev_context, prev_index, 0);
rbp_trigger_button_action(dev_context, current_index,
1);
status =
rbp_trigger_button_action(dev_context,
current_index, 0);
current_rbp_state = ph0_idle;
break;
case rbp_press_and_hold_button_press:
mhl_tx_start_timer(dev_context,
dev_context->timer_T_press_mode,
T_PRESS_MODE);
status =
rbp_trigger_button_action(dev_context, prev_index,
1);
/* no update for current_rbp_state */
break;
case rbp_press_and_hold_button_press_same:
mhl_tx_stop_timer(dev_context,
dev_context->timer_T_press_mode);
mhl_tx_start_timer(dev_context,
dev_context->timer_T_hold_maintain,
T_HOLD_MAINTAIN);
status =
rbp_trigger_button_action(dev_context, prev_index,
1);
current_rbp_state = ph8_hold_mode;
break;
case rbp_press_and_hold_button_release:
case rbp_press_and_hold_button_release_same:
mhl_tx_stop_timer(dev_context,
dev_context->timer_T_press_mode);
status =
rbp_trigger_button_action(dev_context, prev_index,
0);
current_rbp_state = ph0_idle;
break;
case rbp_T_press_mode_expired:
mhl_tx_start_timer(dev_context,
dev_context->timer_T_hold_maintain,
T_HOLD_MAINTAIN);
status =
rbp_trigger_button_action(dev_context, prev_index,
0);
current_rbp_state = ph8_hold_mode;
break;
default:
MHL_TX_DBG_ERR("unexpected event: %d in state: %d\n",
event, current_rbp_state);
/* no update for current_rbp_state */
status = -EINVAL;
}
break;
case ph8_hold_mode:
switch (event) {
case rbp_normal_button_press:
case rbp_normal_button_press_same:
mhl_tx_stop_timer(dev_context,
dev_context->timer_T_hold_maintain);
rbp_trigger_button_action(dev_context, prev_index, 0);
status =
rbp_trigger_button_action(dev_context,
current_index, 1);
current_rbp_state = ph0_idle;
break;
case rbp_normal_button_release:
case rbp_normal_button_release_same:
mhl_tx_stop_timer(dev_context,
dev_context->timer_T_hold_maintain);
rbp_trigger_button_action(dev_context, prev_index, 0);
rbp_trigger_button_action(dev_context, current_index,
1);
status =
rbp_trigger_button_action(dev_context,
current_index, 0);
current_rbp_state = ph0_idle;
break;
case rbp_press_and_hold_button_press:
mhl_tx_stop_timer(dev_context,
dev_context->timer_T_hold_maintain);
mhl_tx_start_timer(dev_context,
dev_context->timer_T_press_mode,
T_PRESS_MODE);
status =
rbp_trigger_button_action(dev_context, prev_index,
1);
current_rbp_state = ph3_press_and_hold_button;
break;
case rbp_press_and_hold_button_press_same:
mhl_tx_start_timer(dev_context,
dev_context->timer_T_hold_maintain,
T_HOLD_MAINTAIN);
status =
rbp_trigger_button_action(dev_context, prev_index,
1);
/* no update for current_rbp_state */
break;
case rbp_press_and_hold_button_release:
mhl_tx_stop_timer(dev_context,
dev_context->timer_T_hold_maintain);
rbp_trigger_button_action(dev_context, prev_index, 0);
rbp_trigger_button_action(dev_context, current_index,
1);
status =
rbp_trigger_button_action(dev_context,
current_index, 0);
current_rbp_state = ph0_idle;
break;
case rbp_press_and_hold_button_release_same:
mhl_tx_stop_timer(dev_context,
dev_context->timer_T_hold_maintain);
status =
rbp_trigger_button_action(dev_context, prev_index,
0);
current_rbp_state = ph0_idle;
break;
case rbp_T_hold_maintain_expired:
status =
rbp_trigger_button_action(dev_context, prev_index,
0);
current_rbp_state = ph0_idle;
break;
default:
MHL_TX_DBG_ERR("unexpected event: %d in state: %d\n",
event, current_rbp_state);
/* no update for current_rbp_state */
status = -EINVAL;
}
break;
default:
MHL_TX_DBG_ERR("irrational state value:%d\n",
current_rbp_state);
}
return status;
}
int generate_rbp_input_event(struct mhl_dev_context *dev_context,
uint8_t rbp_buttoncode)
{
/*
Since, in MHL, bit 7 == 1 indicates button release,
and, in Linux, zero means button release,
we use XOR (^) to invert the sense.
*/
enum rbp_event_e event;
int mhl_button_press;
int status = -EINVAL;
int index = rbp_buttoncode & MHL_RBP_BUTTON_ID_MASK;
switch (index) {
case RBP_CALL_ANSWER:
case RBP_CALL_END:
case RBP_CALL_TOGGLE:
case RBP_CALL_MUTE:
case RBP_CALL_DECLINE:
case RBP_OCTOTHORPE:
case RBP_ASTERISK:
case RBP_ROTATE_CLKWISE:
case RBP_ROTATE_COUNTERCLKWISE:
case RBP_SCREEN_PAGE_NEXT:
case RBP_SCREEN_PAGE_PREV:
case RBP_SCREEN_PAGE_UP:
case RBP_SCREEN_PAGE_DN:
case RBP_SCREEN_PAGE_LEFT:
case RBP_SCREEN_PAGE_RIGHT:
break;
default:
return 1;
}
mhl_button_press =
(rbp_buttoncode & MHL_RBP_BUTTON_RELEASED_MASK) ? 0 : 1;
if (mhl_button_press) {
if (index == rbp_previous_button)
event = rbp_press_and_hold_button_press_same;
else
event = rbp_press_and_hold_button_press;
} else {
if (index == rbp_previous_button)
event = rbp_press_and_hold_button_release_same;
else
event = rbp_press_and_hold_button_release;
}
status = handle_rbp_event(dev_context, rbp_buttoncode,
rbp_current_button, event);
rbp_previous_button = rbp_current_button;
rbp_current_button = rbp_buttoncode;
return status;
}
#endif
|