1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2 /*
3 * cec-htng-funcs - HDMI CEC wrapper functions for Hospitality Profile
4 *
5 * Copyright 2016-2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
6 */
7
8 #ifndef _CEC_HTNG_FUNCS_H
9 #define _CEC_HTNG_FUNCS_H
10
11 #include "cec-htng.h"
12
cec_msg_htng_init(struct cec_msg * msg,uint8_t op)13 static inline void cec_msg_htng_init(struct cec_msg *msg, uint8_t op)
14 {
15 msg->len = 6;
16 msg->msg[1] = CEC_MSG_VENDOR_COMMAND_WITH_ID;
17 msg->msg[2] = VENDOR_ID_HTNG >> 16;
18 msg->msg[3] = (VENDOR_ID_HTNG >> 8) & 0xff;
19 msg->msg[4] = VENDOR_ID_HTNG & 0xff;
20 msg->msg[5] = op;
21 }
22
23 /* HTNG Feature */
cec_msg_htng_tuner_1part_chan(struct cec_msg * msg,uint8_t htng_tuner_type,uint16_t chan)24 static inline void cec_msg_htng_tuner_1part_chan(struct cec_msg *msg,
25 uint8_t htng_tuner_type,
26 uint16_t chan)
27 {
28 cec_msg_htng_init(msg, CEC_MSG_HTNG_TUNER_1PART_CHAN);
29 msg->msg[msg->len++] = htng_tuner_type;
30 msg->msg[msg->len++] = chan >> 8;
31 msg->msg[msg->len++] = chan & 0xff;
32 }
33
cec_ops_htng_tuner_1part_chan(const struct cec_msg * msg,uint8_t * htng_tuner_type,uint16_t * chan)34 static inline void cec_ops_htng_tuner_1part_chan(const struct cec_msg *msg,
35 uint8_t *htng_tuner_type,
36 uint16_t *chan)
37 {
38 *htng_tuner_type = msg->msg[6];
39 *chan = (msg->msg[7] << 8) | msg->msg[8];
40 }
41
cec_msg_htng_tuner_2part_chan(struct cec_msg * msg,uint8_t htng_tuner_type,uint8_t major_chan,uint16_t minor_chan)42 static inline void cec_msg_htng_tuner_2part_chan(struct cec_msg *msg,
43 uint8_t htng_tuner_type,
44 uint8_t major_chan,
45 uint16_t minor_chan)
46 {
47 cec_msg_htng_init(msg, CEC_MSG_HTNG_TUNER_2PART_CHAN);
48 msg->msg[msg->len++] = htng_tuner_type;
49 msg->msg[msg->len++] = major_chan;
50 msg->msg[msg->len++] = minor_chan >> 8;
51 msg->msg[msg->len++] = minor_chan & 0xff;
52 }
53
cec_ops_htng_tuner_2part_chan(const struct cec_msg * msg,uint8_t * htng_tuner_type,uint8_t * major_chan,uint16_t * minor_chan)54 static inline void cec_ops_htng_tuner_2part_chan(const struct cec_msg *msg,
55 uint8_t *htng_tuner_type,
56 uint8_t *major_chan,
57 uint16_t *minor_chan)
58 {
59 *htng_tuner_type = msg->msg[6];
60 *major_chan = msg->msg[7];
61 *minor_chan = (msg->msg[8] << 8) | msg->msg[9];
62 }
63
cec_msg_htng_input_sel_av(struct cec_msg * msg,uint16_t input)64 static inline void cec_msg_htng_input_sel_av(struct cec_msg *msg,
65 uint16_t input)
66 {
67 cec_msg_htng_init(msg, CEC_MSG_HTNG_INPUT_SEL_AV);
68 msg->msg[msg->len++] = input >> 8;
69 msg->msg[msg->len++] = input & 0xff;
70 }
71
cec_ops_htng_input_sel_av(const struct cec_msg * msg,uint16_t * input)72 static inline void cec_ops_htng_input_sel_av(const struct cec_msg *msg,
73 uint16_t *input)
74 {
75 *input = (msg->msg[6] << 8) | msg->msg[7];
76 }
77
cec_msg_htng_input_sel_pc(struct cec_msg * msg,uint16_t input)78 static inline void cec_msg_htng_input_sel_pc(struct cec_msg *msg,
79 uint16_t input)
80 {
81 cec_msg_htng_init(msg, CEC_MSG_HTNG_INPUT_SEL_PC);
82 msg->msg[msg->len++] = input >> 8;
83 msg->msg[msg->len++] = input & 0xff;
84 }
85
cec_ops_htng_input_sel_pc(const struct cec_msg * msg,uint16_t * input)86 static inline void cec_ops_htng_input_sel_pc(const struct cec_msg *msg,
87 uint16_t *input)
88 {
89 *input = (msg->msg[6] << 8) | msg->msg[7];
90 }
91
cec_msg_htng_input_sel_hdmi(struct cec_msg * msg,uint16_t input)92 static inline void cec_msg_htng_input_sel_hdmi(struct cec_msg *msg,
93 uint16_t input)
94 {
95 cec_msg_htng_init(msg, CEC_MSG_HTNG_INPUT_SEL_HDMI);
96 msg->msg[msg->len++] = input >> 8;
97 msg->msg[msg->len++] = input & 0xff;
98 }
99
cec_ops_htng_input_sel_hdmi(const struct cec_msg * msg,uint16_t * input)100 static inline void cec_ops_htng_input_sel_hdmi(const struct cec_msg *msg,
101 uint16_t *input)
102 {
103 *input = (msg->msg[6] << 8) | msg->msg[7];
104 }
105
cec_msg_htng_input_sel_component(struct cec_msg * msg,uint16_t input)106 static inline void cec_msg_htng_input_sel_component(struct cec_msg *msg,
107 uint16_t input)
108 {
109 cec_msg_htng_init(msg, CEC_MSG_HTNG_INPUT_SEL_COMPONENT);
110 msg->msg[msg->len++] = input >> 8;
111 msg->msg[msg->len++] = input & 0xff;
112 }
113
cec_ops_htng_input_sel_component(const struct cec_msg * msg,uint16_t * input)114 static inline void cec_ops_htng_input_sel_component(const struct cec_msg *msg,
115 uint16_t *input)
116 {
117 *input = (msg->msg[6] << 8) | msg->msg[7];
118 }
119
cec_msg_htng_input_sel_dvi(struct cec_msg * msg,uint16_t input)120 static inline void cec_msg_htng_input_sel_dvi(struct cec_msg *msg,
121 uint16_t input)
122 {
123 cec_msg_htng_init(msg, CEC_MSG_HTNG_INPUT_SEL_DVI);
124 msg->msg[msg->len++] = input >> 8;
125 msg->msg[msg->len++] = input & 0xff;
126 }
127
cec_ops_htng_input_sel_dvi(const struct cec_msg * msg,uint16_t * input)128 static inline void cec_ops_htng_input_sel_dvi(const struct cec_msg *msg,
129 uint16_t *input)
130 {
131 *input = (msg->msg[6] << 8) | msg->msg[7];
132 }
133
cec_msg_htng_input_sel_dp(struct cec_msg * msg,uint16_t input)134 static inline void cec_msg_htng_input_sel_dp(struct cec_msg *msg,
135 uint16_t input)
136 {
137 cec_msg_htng_init(msg, CEC_MSG_HTNG_INPUT_SEL_DP);
138 msg->msg[msg->len++] = input >> 8;
139 msg->msg[msg->len++] = input & 0xff;
140 }
141
cec_ops_htng_input_sel_dp(const struct cec_msg * msg,uint16_t * input)142 static inline void cec_ops_htng_input_sel_dp(const struct cec_msg *msg,
143 uint16_t *input)
144 {
145 *input = (msg->msg[6] << 8) | msg->msg[7];
146 }
147
cec_msg_htng_input_sel_usb(struct cec_msg * msg,uint16_t input)148 static inline void cec_msg_htng_input_sel_usb(struct cec_msg *msg,
149 uint16_t input)
150 {
151 cec_msg_htng_init(msg, CEC_MSG_HTNG_INPUT_SEL_USB);
152 msg->msg[msg->len++] = input >> 8;
153 msg->msg[msg->len++] = input & 0xff;
154 }
155
cec_ops_htng_input_sel_usb(const struct cec_msg * msg,uint16_t * input)156 static inline void cec_ops_htng_input_sel_usb(const struct cec_msg *msg,
157 uint16_t *input)
158 {
159 *input = (msg->msg[6] << 8) | msg->msg[7];
160 }
161
cec_msg_htng_set_def_pwr_on_input_src(struct cec_msg * msg,uint8_t htng_input_src,uint8_t htng_tuner_type,uint8_t major,uint16_t input)162 static inline void cec_msg_htng_set_def_pwr_on_input_src(struct cec_msg *msg,
163 uint8_t htng_input_src,
164 uint8_t htng_tuner_type,
165 uint8_t major,
166 uint16_t input)
167 {
168 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_DEF_PWR_ON_INPUT_SRC);
169 msg->msg[msg->len++] = htng_input_src;
170 msg->msg[msg->len++] = htng_tuner_type;
171 if (htng_input_src == CEC_OP_HTNG_INPUT_SRC_TUNER_2PART)
172 msg->msg[msg->len++] = major;
173 msg->msg[msg->len++] = input >> 8;
174 msg->msg[msg->len++] = input & 0xff;
175 if (htng_input_src != CEC_OP_HTNG_INPUT_SRC_TUNER_2PART)
176 msg->msg[msg->len++] = 0;
177 }
178
cec_ops_htng_set_def_pwr_on_input_src(const struct cec_msg * msg,uint8_t * htng_input_src,uint8_t * htng_tuner_type,uint8_t * major,uint16_t * input)179 static inline void cec_ops_htng_set_def_pwr_on_input_src(const struct cec_msg *msg,
180 uint8_t *htng_input_src,
181 uint8_t *htng_tuner_type,
182 uint8_t *major,
183 uint16_t *input)
184 {
185 *htng_input_src = msg->msg[6];
186 *htng_tuner_type = msg->msg[7];
187 if (*htng_input_src == CEC_OP_HTNG_INPUT_SRC_TUNER_2PART) {
188 *major = msg->msg[8];
189 *input = (msg->msg[9] << 8) | msg->msg[10];
190 } else {
191 *major = 0;
192 *input = (msg->msg[8] << 8) | msg->msg[9];
193 }
194 }
195
cec_msg_htng_set_tv_speakers(struct cec_msg * msg,uint8_t on)196 static inline void cec_msg_htng_set_tv_speakers(struct cec_msg *msg,
197 uint8_t on)
198 {
199 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_TV_SPEAKERS);
200 msg->msg[msg->len++] = on;
201 }
202
cec_ops_htng_set_tv_speakers(const struct cec_msg * msg,uint8_t * on)203 static inline void cec_ops_htng_set_tv_speakers(const struct cec_msg *msg,
204 uint8_t *on)
205 {
206 *on = msg->msg[6];
207 }
208
cec_msg_htng_set_dig_audio(struct cec_msg * msg,uint8_t on)209 static inline void cec_msg_htng_set_dig_audio(struct cec_msg *msg,
210 uint8_t on)
211 {
212 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_DIG_AUDIO);
213 msg->msg[msg->len++] = on;
214 }
215
cec_ops_htng_set_dig_audio(const struct cec_msg * msg,uint8_t * on)216 static inline void cec_ops_htng_set_dig_audio(const struct cec_msg *msg,
217 uint8_t *on)
218 {
219 *on = msg->msg[6];
220 }
221
cec_msg_htng_set_ana_audio(struct cec_msg * msg,uint8_t on)222 static inline void cec_msg_htng_set_ana_audio(struct cec_msg *msg,
223 uint8_t on)
224 {
225 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_ANA_AUDIO);
226 msg->msg[msg->len++] = on;
227 }
228
cec_ops_htng_set_ana_audio(const struct cec_msg * msg,uint8_t * on)229 static inline void cec_ops_htng_set_ana_audio(const struct cec_msg *msg,
230 uint8_t *on)
231 {
232 *on = msg->msg[6];
233 }
234
cec_msg_htng_set_def_pwr_on_vol(struct cec_msg * msg,uint8_t vol)235 static inline void cec_msg_htng_set_def_pwr_on_vol(struct cec_msg *msg,
236 uint8_t vol)
237 {
238 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_DEF_PWR_ON_VOL);
239 msg->msg[msg->len++] = vol;
240 }
241
cec_ops_htng_set_def_pwr_on_vol(const struct cec_msg * msg,uint8_t * vol)242 static inline void cec_ops_htng_set_def_pwr_on_vol(const struct cec_msg *msg,
243 uint8_t *vol)
244 {
245 *vol = msg->msg[6];
246 }
247
cec_msg_htng_set_max_vol(struct cec_msg * msg,uint8_t vol)248 static inline void cec_msg_htng_set_max_vol(struct cec_msg *msg,
249 uint8_t vol)
250 {
251 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_MAX_VOL);
252 msg->msg[msg->len++] = vol;
253 }
254
cec_ops_htng_set_max_vol(const struct cec_msg * msg,uint8_t * vol)255 static inline void cec_ops_htng_set_max_vol(const struct cec_msg *msg,
256 uint8_t *vol)
257 {
258 *vol = msg->msg[6];
259 }
260
cec_msg_htng_set_min_vol(struct cec_msg * msg,uint8_t vol)261 static inline void cec_msg_htng_set_min_vol(struct cec_msg *msg,
262 uint8_t vol)
263 {
264 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_MIN_VOL);
265 msg->msg[msg->len++] = vol;
266 }
267
cec_ops_htng_set_min_vol(const struct cec_msg * msg,uint8_t * vol)268 static inline void cec_ops_htng_set_min_vol(const struct cec_msg *msg,
269 uint8_t *vol)
270 {
271 *vol = msg->msg[6];
272 }
273
cec_msg_htng_set_blue_screen(struct cec_msg * msg,uint8_t blue)274 static inline void cec_msg_htng_set_blue_screen(struct cec_msg *msg,
275 uint8_t blue)
276 {
277 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_BLUE_SCREEN);
278 msg->msg[msg->len++] = blue;
279 }
280
cec_ops_htng_set_blue_screen(const struct cec_msg * msg,uint8_t * blue)281 static inline void cec_ops_htng_set_blue_screen(const struct cec_msg *msg,
282 uint8_t *blue)
283 {
284 *blue = msg->msg[6];
285 }
286
cec_msg_htng_set_brightness(struct cec_msg * msg,uint8_t brightness)287 static inline void cec_msg_htng_set_brightness(struct cec_msg *msg,
288 uint8_t brightness)
289 {
290 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_BRIGHTNESS);
291 msg->msg[msg->len++] = brightness;
292 }
293
cec_ops_htng_set_brightness(const struct cec_msg * msg,uint8_t * brightness)294 static inline void cec_ops_htng_set_brightness(const struct cec_msg *msg,
295 uint8_t *brightness)
296 {
297 *brightness = msg->msg[6];
298 }
299
cec_msg_htng_set_color(struct cec_msg * msg,uint8_t color)300 static inline void cec_msg_htng_set_color(struct cec_msg *msg,
301 uint8_t color)
302 {
303 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_COLOR);
304 msg->msg[msg->len++] = color;
305 }
306
cec_ops_htng_set_color(const struct cec_msg * msg,uint8_t * color)307 static inline void cec_ops_htng_set_color(const struct cec_msg *msg,
308 uint8_t *color)
309 {
310 *color = msg->msg[6];
311 }
312
cec_msg_htng_set_contrast(struct cec_msg * msg,uint8_t contrast)313 static inline void cec_msg_htng_set_contrast(struct cec_msg *msg,
314 uint8_t contrast)
315 {
316 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_CONTRAST);
317 msg->msg[msg->len++] = contrast;
318 }
319
cec_ops_htng_set_contrast(const struct cec_msg * msg,uint8_t * contrast)320 static inline void cec_ops_htng_set_contrast(const struct cec_msg *msg,
321 uint8_t *contrast)
322 {
323 *contrast = msg->msg[6];
324 }
325
cec_msg_htng_set_sharpness(struct cec_msg * msg,uint8_t sharpness)326 static inline void cec_msg_htng_set_sharpness(struct cec_msg *msg,
327 uint8_t sharpness)
328 {
329 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_SHARPNESS);
330 msg->msg[msg->len++] = sharpness;
331 }
332
cec_ops_htng_set_sharpness(const struct cec_msg * msg,uint8_t * sharpness)333 static inline void cec_ops_htng_set_sharpness(const struct cec_msg *msg,
334 uint8_t *sharpness)
335 {
336 *sharpness = msg->msg[6];
337 }
338
cec_msg_htng_set_hue(struct cec_msg * msg,uint8_t hue)339 static inline void cec_msg_htng_set_hue(struct cec_msg *msg,
340 uint8_t hue)
341 {
342 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_HUE);
343 msg->msg[msg->len++] = hue;
344 }
345
cec_ops_htng_set_hue(const struct cec_msg * msg,uint8_t * hue)346 static inline void cec_ops_htng_set_hue(const struct cec_msg *msg,
347 uint8_t *hue)
348 {
349 *hue = msg->msg[6];
350 }
351
cec_msg_htng_set_led_backlight(struct cec_msg * msg,uint8_t led_backlight)352 static inline void cec_msg_htng_set_led_backlight(struct cec_msg *msg,
353 uint8_t led_backlight)
354 {
355 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_LED_BACKLIGHT);
356 msg->msg[msg->len++] = led_backlight;
357 }
358
cec_ops_htng_set_led_backlight(const struct cec_msg * msg,uint8_t * led_backlight)359 static inline void cec_ops_htng_set_led_backlight(const struct cec_msg *msg,
360 uint8_t *led_backlight)
361 {
362 *led_backlight = msg->msg[6];
363 }
364
cec_msg_htng_set_tv_osd_control(struct cec_msg * msg,uint8_t on)365 static inline void cec_msg_htng_set_tv_osd_control(struct cec_msg *msg,
366 uint8_t on)
367 {
368 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_TV_OSD_CONTROL);
369 msg->msg[msg->len++] = on;
370 }
371
cec_ops_htng_set_tv_osd_control(const struct cec_msg * msg,uint8_t * on)372 static inline void cec_ops_htng_set_tv_osd_control(const struct cec_msg *msg,
373 uint8_t *on)
374 {
375 *on = msg->msg[6];
376 }
377
cec_msg_htng_set_audio_only_display(struct cec_msg * msg,uint8_t on)378 static inline void cec_msg_htng_set_audio_only_display(struct cec_msg *msg,
379 uint8_t on)
380 {
381 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_AUDIO_ONLY_DISPLAY);
382 msg->msg[msg->len++] = on;
383 }
384
cec_ops_htng_set_audio_only_display(const struct cec_msg * msg,uint8_t * on)385 static inline void cec_ops_htng_set_audio_only_display(const struct cec_msg *msg,
386 uint8_t *on)
387 {
388 *on = msg->msg[6];
389 }
390
cec_msg_htng_set_date(struct cec_msg * msg,const char * date)391 static inline void cec_msg_htng_set_date(struct cec_msg *msg,
392 const char *date)
393 {
394 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_DATE);
395 memcpy(msg->msg + msg->len, date, 8);
396 msg->len += 8;
397 }
398
cec_ops_htng_set_date(const struct cec_msg * msg,char * date)399 static inline void cec_ops_htng_set_date(const struct cec_msg *msg,
400 char *date)
401 {
402 memcpy(date, msg->msg + 6, 8);
403 date[8] = '\0';
404 }
405
cec_msg_htng_set_date_format(struct cec_msg * msg,uint8_t ddmm)406 static inline void cec_msg_htng_set_date_format(struct cec_msg *msg,
407 uint8_t ddmm)
408 {
409 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_DATE_FORMAT);
410 msg->msg[msg->len++] = ddmm;
411 }
412
cec_ops_htng_set_date_format(const struct cec_msg * msg,uint8_t * ddmm)413 static inline void cec_ops_htng_set_date_format(const struct cec_msg *msg,
414 uint8_t *ddmm)
415 {
416 *ddmm = msg->msg[6];
417 }
418
cec_msg_htng_set_time(struct cec_msg * msg,const char * time)419 static inline void cec_msg_htng_set_time(struct cec_msg *msg,
420 const char *time)
421 {
422 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_TIME);
423 memcpy(msg->msg + msg->len, time, 6);
424 msg->len += 6;
425 }
426
cec_ops_htng_set_time(const struct cec_msg * msg,char * time)427 static inline void cec_ops_htng_set_time(const struct cec_msg *msg,
428 char *time)
429 {
430 memcpy(time, msg->msg + 6, 6);
431 time[6] = '\0';
432 }
433
cec_msg_htng_set_clk_brightness_standby(struct cec_msg * msg,uint8_t brightness)434 static inline void cec_msg_htng_set_clk_brightness_standby(struct cec_msg *msg,
435 uint8_t brightness)
436 {
437 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_CLK_BRIGHTNESS_STANDBY);
438 msg->msg[msg->len++] = brightness;
439 }
440
cec_ops_htng_set_clk_brightness_standby(const struct cec_msg * msg,uint8_t * brightness)441 static inline void cec_ops_htng_set_clk_brightness_standby(const struct cec_msg *msg,
442 uint8_t *brightness)
443 {
444 *brightness = msg->msg[6];
445 }
446
cec_msg_htng_set_clk_brightness_on(struct cec_msg * msg,uint8_t brightness)447 static inline void cec_msg_htng_set_clk_brightness_on(struct cec_msg *msg,
448 uint8_t brightness)
449 {
450 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_CLK_BRIGHTNESS_ON);
451 msg->msg[msg->len++] = brightness;
452 }
453
cec_ops_htng_set_clk_brightness_on(const struct cec_msg * msg,uint8_t * brightness)454 static inline void cec_ops_htng_set_clk_brightness_on(const struct cec_msg *msg,
455 uint8_t *brightness)
456 {
457 *brightness = msg->msg[6];
458 }
459
cec_msg_htng_led_control(struct cec_msg * msg,uint8_t htng_led_control)460 static inline void cec_msg_htng_led_control(struct cec_msg *msg,
461 uint8_t htng_led_control)
462 {
463 cec_msg_htng_init(msg, CEC_MSG_HTNG_LED_CONTROL);
464 msg->msg[msg->len++] = htng_led_control;
465 }
466
cec_ops_htng_led_control(const struct cec_msg * msg,uint8_t * htng_led_control)467 static inline void cec_ops_htng_led_control(const struct cec_msg *msg,
468 uint8_t *htng_led_control)
469 {
470 *htng_led_control = msg->msg[6];
471 }
472
cec_msg_htng_lock_tv_pwr_button(struct cec_msg * msg,uint8_t on)473 static inline void cec_msg_htng_lock_tv_pwr_button(struct cec_msg *msg,
474 uint8_t on)
475 {
476 cec_msg_htng_init(msg, CEC_MSG_HTNG_LOCK_TV_PWR_BUTTON);
477 msg->msg[msg->len++] = on;
478 }
479
cec_ops_htng_lock_tv_pwr_button(const struct cec_msg * msg,uint8_t * on)480 static inline void cec_ops_htng_lock_tv_pwr_button(const struct cec_msg *msg,
481 uint8_t *on)
482 {
483 *on = msg->msg[6];
484 }
485
cec_msg_htng_lock_tv_vol_buttons(struct cec_msg * msg,uint8_t on)486 static inline void cec_msg_htng_lock_tv_vol_buttons(struct cec_msg *msg,
487 uint8_t on)
488 {
489 cec_msg_htng_init(msg, CEC_MSG_HTNG_LOCK_TV_VOL_BUTTONS);
490 msg->msg[msg->len++] = on;
491 }
492
cec_ops_htng_lock_tv_vol_buttons(const struct cec_msg * msg,uint8_t * on)493 static inline void cec_ops_htng_lock_tv_vol_buttons(const struct cec_msg *msg,
494 uint8_t *on)
495 {
496 *on = msg->msg[6];
497 }
498
cec_msg_htng_lock_tv_chan_buttons(struct cec_msg * msg,uint8_t on)499 static inline void cec_msg_htng_lock_tv_chan_buttons(struct cec_msg *msg,
500 uint8_t on)
501 {
502 cec_msg_htng_init(msg, CEC_MSG_HTNG_LOCK_TV_CHAN_BUTTONS);
503 msg->msg[msg->len++] = on;
504 }
505
cec_ops_htng_lock_tv_chan_buttons(const struct cec_msg * msg,uint8_t * on)506 static inline void cec_ops_htng_lock_tv_chan_buttons(const struct cec_msg *msg,
507 uint8_t *on)
508 {
509 *on = msg->msg[6];
510 }
511
cec_msg_htng_lock_tv_input_buttons(struct cec_msg * msg,uint8_t on)512 static inline void cec_msg_htng_lock_tv_input_buttons(struct cec_msg *msg,
513 uint8_t on)
514 {
515 cec_msg_htng_init(msg, CEC_MSG_HTNG_LOCK_TV_INPUT_BUTTONS);
516 msg->msg[msg->len++] = on;
517 }
518
cec_ops_htng_lock_tv_input_buttons(const struct cec_msg * msg,uint8_t * on)519 static inline void cec_ops_htng_lock_tv_input_buttons(const struct cec_msg *msg,
520 uint8_t *on)
521 {
522 *on = msg->msg[6];
523 }
524
cec_msg_htng_lock_tv_other_buttons(struct cec_msg * msg,uint8_t on)525 static inline void cec_msg_htng_lock_tv_other_buttons(struct cec_msg *msg,
526 uint8_t on)
527 {
528 cec_msg_htng_init(msg, CEC_MSG_HTNG_LOCK_TV_OTHER_BUTTONS);
529 msg->msg[msg->len++] = on;
530 }
531
cec_ops_htng_lock_tv_other_buttons(const struct cec_msg * msg,uint8_t * on)532 static inline void cec_ops_htng_lock_tv_other_buttons(const struct cec_msg *msg,
533 uint8_t *on)
534 {
535 *on = msg->msg[6];
536 }
537
cec_msg_htng_lock_everything(struct cec_msg * msg,uint8_t on)538 static inline void cec_msg_htng_lock_everything(struct cec_msg *msg,
539 uint8_t on)
540 {
541 cec_msg_htng_init(msg, CEC_MSG_HTNG_LOCK_EVERYTHING);
542 msg->msg[msg->len++] = on;
543 }
544
cec_ops_htng_lock_everything(const struct cec_msg * msg,uint8_t * on)545 static inline void cec_ops_htng_lock_everything(const struct cec_msg *msg,
546 uint8_t *on)
547 {
548 *on = msg->msg[6];
549 }
550
cec_msg_htng_lock_everything_but_pwr(struct cec_msg * msg,uint8_t on)551 static inline void cec_msg_htng_lock_everything_but_pwr(struct cec_msg *msg,
552 uint8_t on)
553 {
554 cec_msg_htng_init(msg, CEC_MSG_HTNG_LOCK_EVERYTHING_BUT_PWR);
555 msg->msg[msg->len++] = on;
556 }
557
cec_ops_htng_lock_everything_but_pwr(const struct cec_msg * msg,uint8_t * on)558 static inline void cec_ops_htng_lock_everything_but_pwr(const struct cec_msg *msg,
559 uint8_t *on)
560 {
561 *on = msg->msg[6];
562 }
563
cec_msg_htng_hotel_mode(struct cec_msg * msg,uint8_t on,uint8_t options)564 static inline void cec_msg_htng_hotel_mode(struct cec_msg *msg,
565 uint8_t on, uint8_t options)
566 {
567 cec_msg_htng_init(msg, CEC_MSG_HTNG_HOTEL_MODE);
568 msg->msg[msg->len++] = on;
569 msg->msg[msg->len++] = options;
570 }
571
cec_ops_htng_hotel_mode(const struct cec_msg * msg,uint8_t * on,uint8_t * options)572 static inline void cec_ops_htng_hotel_mode(const struct cec_msg *msg,
573 uint8_t *on, uint8_t *options)
574 {
575 *on = msg->msg[6];
576 *options = msg->msg[7];
577 }
578
cec_msg_htng_set_pwr_saving_profile(struct cec_msg * msg,uint8_t on,uint8_t val)579 static inline void cec_msg_htng_set_pwr_saving_profile(struct cec_msg *msg,
580 uint8_t on, uint8_t val)
581 {
582 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_PWR_SAVING_PROFILE);
583 msg->msg[msg->len++] = on;
584 msg->msg[msg->len++] = val;
585 }
586
cec_ops_htng_set_pwr_saving_profile(const struct cec_msg * msg,uint8_t * on,uint8_t * val)587 static inline void cec_ops_htng_set_pwr_saving_profile(const struct cec_msg *msg,
588 uint8_t *on, uint8_t *val)
589 {
590 *on = msg->msg[6];
591 *val = msg->msg[7];
592 }
593
cec_msg_htng_set_sleep_timer(struct cec_msg * msg,uint8_t minutes)594 static inline void cec_msg_htng_set_sleep_timer(struct cec_msg *msg,
595 uint8_t minutes)
596 {
597 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_SLEEP_TIMER);
598 msg->msg[msg->len++] = minutes;
599 }
600
cec_ops_htng_set_sleep_timer(const struct cec_msg * msg,uint8_t * minutes)601 static inline void cec_ops_htng_set_sleep_timer(const struct cec_msg *msg,
602 uint8_t *minutes)
603 {
604 *minutes = msg->msg[6];
605 }
606
cec_msg_htng_set_wakeup_time(struct cec_msg * msg,const char * time)607 static inline void cec_msg_htng_set_wakeup_time(struct cec_msg *msg,
608 const char *time)
609 {
610 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_WAKEUP_TIME);
611 memcpy(msg->msg + 6, time, 4);
612 msg->len += 4;
613 }
614
cec_ops_htng_set_wakeup_time(const struct cec_msg * msg,char * time)615 static inline void cec_ops_htng_set_wakeup_time(const struct cec_msg *msg,
616 char *time)
617 {
618 memcpy(time, msg->msg + 6, 4);
619 time[4] = '\0';
620 }
621
cec_msg_htng_set_auto_off_time(struct cec_msg * msg,const char * time)622 static inline void cec_msg_htng_set_auto_off_time(struct cec_msg *msg,
623 const char *time)
624 {
625 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_AUTO_OFF_TIME);
626 memcpy(msg->msg + 6, time, 4);
627 msg->len += 4;
628 }
629
cec_ops_htng_set_auto_off_time(const struct cec_msg * msg,char * time)630 static inline void cec_ops_htng_set_auto_off_time(const struct cec_msg *msg,
631 char *time)
632 {
633 memcpy(time, msg->msg + 6, 4);
634 time[4] = '\0';
635 }
636
cec_msg_htng_set_wakeup_src(struct cec_msg * msg,uint8_t htng_input_src,uint8_t htng_tuner_type,uint8_t major,uint16_t input)637 static inline void cec_msg_htng_set_wakeup_src(struct cec_msg *msg,
638 uint8_t htng_input_src,
639 uint8_t htng_tuner_type,
640 uint8_t major,
641 uint16_t input)
642 {
643 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_WAKEUP_SRC);
644 msg->msg[msg->len++] = htng_input_src;
645 msg->msg[msg->len++] = htng_tuner_type;
646 if (htng_input_src == CEC_OP_HTNG_INPUT_SRC_TUNER_2PART)
647 msg->msg[msg->len++] = major;
648 msg->msg[msg->len++] = input >> 8;
649 msg->msg[msg->len++] = input & 0xff;
650 if (htng_input_src != CEC_OP_HTNG_INPUT_SRC_TUNER_2PART)
651 msg->msg[msg->len++] = 0;
652 }
653
cec_ops_htng_set_wakeup_src(const struct cec_msg * msg,uint8_t * htng_input_src,uint8_t * htng_tuner_type,uint8_t * major,uint16_t * input)654 static inline void cec_ops_htng_set_wakeup_src(const struct cec_msg *msg,
655 uint8_t *htng_input_src,
656 uint8_t *htng_tuner_type,
657 uint8_t *major,
658 uint16_t *input)
659 {
660 *htng_input_src = msg->msg[6];
661 *htng_tuner_type = msg->msg[7];
662 if (*htng_input_src == CEC_OP_HTNG_INPUT_SRC_TUNER_2PART) {
663 *major = msg->msg[8];
664 *input = (msg->msg[9] << 8) | msg->msg[10];
665 } else {
666 *major = 0;
667 *input = (msg->msg[8] << 8) | msg->msg[9];
668 }
669 }
670
cec_msg_htng_set_init_wakeup_vol(struct cec_msg * msg,uint8_t vol,uint8_t minutes)671 static inline void cec_msg_htng_set_init_wakeup_vol(struct cec_msg *msg,
672 uint8_t vol,
673 uint8_t minutes)
674 {
675 cec_msg_htng_init(msg, CEC_MSG_HTNG_SET_INIT_WAKEUP_VOL);
676 msg->msg[msg->len++] = vol;
677 msg->msg[msg->len++] = minutes;
678 }
679
cec_ops_htng_set_init_wakeup_vol(const struct cec_msg * msg,uint8_t * vol,uint8_t * minutes)680 static inline void cec_ops_htng_set_init_wakeup_vol(const struct cec_msg *msg,
681 uint8_t *vol,
682 uint8_t *minutes)
683 {
684 *vol = msg->msg[6];
685 *minutes = msg->msg[7];
686 }
687
cec_msg_htng_clr_all_sleep_wake(struct cec_msg * msg)688 static inline void cec_msg_htng_clr_all_sleep_wake(struct cec_msg *msg)
689 {
690 cec_msg_htng_init(msg, CEC_MSG_HTNG_CLR_ALL_SLEEP_WAKE);
691 }
692
cec_msg_htng_global_direct_tune_freq(struct cec_msg * msg,uint8_t htng_chan_type,uint8_t htng_prog_type,uint8_t htng_system_type,uint16_t freq,uint16_t service_id,uint8_t htng_mod_type,uint8_t htng_symbol_rate,uint16_t symbol_rate)693 static inline void cec_msg_htng_global_direct_tune_freq(struct cec_msg *msg,
694 uint8_t htng_chan_type,
695 uint8_t htng_prog_type,
696 uint8_t htng_system_type,
697 uint16_t freq,
698 uint16_t service_id,
699 uint8_t htng_mod_type,
700 uint8_t htng_symbol_rate,
701 uint16_t symbol_rate)
702 {
703 cec_msg_htng_init(msg, CEC_MSG_HTNG_GLOBAL_DIRECT_TUNE_FREQ);
704 msg->msg[msg->len++] = (htng_chan_type & 7) |
705 ((htng_prog_type & 1) << 3) |
706 (htng_system_type << 4);
707 msg->msg[msg->len++] = freq >> 8;
708 msg->msg[msg->len++] = freq & 0xff;
709 msg->msg[msg->len++] = service_id >> 8;
710 msg->msg[msg->len++] = service_id & 0xff;
711 msg->msg[msg->len++] = (htng_mod_type & 0xf) |
712 ((htng_symbol_rate & 1) << 7);
713 if (htng_symbol_rate == CEC_OP_HTNG_SYMBOL_RATE_MANUAL) {
714 msg->msg[msg->len++] = symbol_rate >> 8;
715 msg->msg[msg->len++] = symbol_rate & 0xff;
716 }
717 }
718
cec_ops_htng_global_direct_tune_freq(const struct cec_msg * msg,uint8_t * htng_chan_type,uint8_t * htng_prog_type,uint8_t * htng_system_type,uint16_t * freq,uint16_t * service_id,uint8_t * htng_mod_type,uint8_t * htng_symbol_rate,uint16_t * symbol_rate)719 static inline void cec_ops_htng_global_direct_tune_freq(const struct cec_msg *msg,
720 uint8_t *htng_chan_type,
721 uint8_t *htng_prog_type,
722 uint8_t *htng_system_type,
723 uint16_t *freq,
724 uint16_t *service_id,
725 uint8_t *htng_mod_type,
726 uint8_t *htng_symbol_rate,
727 uint16_t *symbol_rate)
728 {
729 *htng_chan_type = msg->msg[6] & 7;
730 *htng_prog_type = (msg->msg[6] >> 3) & 1;
731 *htng_system_type = (msg->msg[6] >> 4) & 0xf;
732 *freq = (msg->msg[7] << 8) | msg->msg[8];
733 *service_id = (msg->msg[9] << 8) | msg->msg[10];
734 *htng_mod_type = msg->msg[11] & 0xf;
735 *htng_symbol_rate = (msg->msg[11] >> 7) & 1;
736 if (*htng_symbol_rate == CEC_OP_HTNG_SYMBOL_RATE_MANUAL)
737 *symbol_rate = (msg->msg[12] << 8) | msg->msg[13];
738 else
739 *symbol_rate = 0;
740 }
741
cec_msg_htng_global_direct_tune_chan(struct cec_msg * msg,uint8_t htng_chan_type,uint8_t htng_prog_type,uint16_t chan)742 static inline void cec_msg_htng_global_direct_tune_chan(struct cec_msg *msg,
743 uint8_t htng_chan_type,
744 uint8_t htng_prog_type,
745 uint16_t chan)
746 {
747 cec_msg_htng_init(msg, CEC_MSG_HTNG_GLOBAL_DIRECT_TUNE_CHAN);
748 msg->msg[msg->len++] = (htng_chan_type & 7) |
749 ((htng_prog_type & 1) << 3);
750 msg->msg[msg->len++] = chan >> 8;
751 msg->msg[msg->len++] = chan & 0xff;
752 }
753
cec_ops_htng_global_direct_tune_chan(const struct cec_msg * msg,uint8_t * htng_chan_type,uint8_t * htng_prog_type,uint16_t * chan)754 static inline void cec_ops_htng_global_direct_tune_chan(const struct cec_msg *msg,
755 uint8_t *htng_chan_type,
756 uint8_t *htng_prog_type,
757 uint16_t *chan)
758 {
759 *htng_chan_type = msg->msg[6] & 7;
760 *htng_prog_type = (msg->msg[6] >> 3) & 1;
761 *chan = (msg->msg[7] << 8) | msg->msg[8];
762 }
763
cec_msg_htng_global_direct_tune_ext_freq(struct cec_msg * msg,uint8_t htng_ext_chan_type,uint8_t htng_prog_type,uint8_t htng_system_type,uint16_t freq,uint16_t service_id,uint8_t htng_mod_type,uint8_t htng_onid,uint16_t onid,uint8_t htng_nid,uint16_t nid,uint8_t htng_tsid_plp,uint16_t tsid_plp,uint8_t htng_symbol_rate,uint16_t symbol_rate)764 static inline void cec_msg_htng_global_direct_tune_ext_freq(struct cec_msg *msg,
765 uint8_t htng_ext_chan_type,
766 uint8_t htng_prog_type,
767 uint8_t htng_system_type,
768 uint16_t freq,
769 uint16_t service_id,
770 uint8_t htng_mod_type,
771 uint8_t htng_onid,
772 uint16_t onid,
773 uint8_t htng_nid,
774 uint16_t nid,
775 uint8_t htng_tsid_plp,
776 uint16_t tsid_plp,
777 uint8_t htng_symbol_rate,
778 uint16_t symbol_rate)
779 {
780 cec_msg_htng_init(msg, CEC_MSG_HTNG_GLOBAL_DIRECT_TUNE_EXT_FREQ);
781 msg->msg[msg->len++] = (htng_ext_chan_type & 7) |
782 ((htng_prog_type & 1) << 3) |
783 (htng_system_type << 4);
784 msg->msg[msg->len++] = freq >> 8;
785 msg->msg[msg->len++] = freq & 0xff;
786 msg->msg[msg->len++] = service_id >> 8;
787 msg->msg[msg->len++] = service_id & 0xff;
788 msg->msg[msg->len++] = (htng_mod_type & 0xf) |
789 ((htng_onid & 1) << 4) |
790 ((htng_nid & 1) << 5) |
791 ((htng_tsid_plp & 1) << 6) |
792 ((htng_symbol_rate & 1) << 7);
793 if (htng_onid == CEC_OP_HTNG_ONID_MANUAL) {
794 msg->msg[msg->len++] = onid >> 8;
795 msg->msg[msg->len++] = onid & 0xff;
796 }
797 if (htng_nid == CEC_OP_HTNG_NID_MANUAL) {
798 msg->msg[msg->len++] = nid >> 8;
799 msg->msg[msg->len++] = nid & 0xff;
800 }
801 if (msg->len < CEC_MAX_MSG_SIZE &&
802 htng_tsid_plp == CEC_OP_HTNG_TSID_PLP_MANUAL) {
803 msg->msg[msg->len++] = tsid_plp >> 8;
804 msg->msg[msg->len++] = tsid_plp & 0xff;
805 }
806 if (msg->len < CEC_MAX_MSG_SIZE &&
807 htng_symbol_rate == CEC_OP_HTNG_SYMBOL_RATE_MANUAL) {
808 msg->msg[msg->len++] = symbol_rate >> 8;
809 msg->msg[msg->len++] = symbol_rate & 0xff;
810 }
811 }
812
cec_ops_htng_global_direct_tune_ext_freq(const struct cec_msg * msg,uint8_t * htng_ext_chan_type,uint8_t * htng_prog_type,uint8_t * htng_system_type,uint16_t * freq,uint16_t * service_id,uint8_t * htng_mod_type,uint8_t * htng_onid,uint16_t * onid,uint8_t * htng_nid,uint16_t * nid,uint8_t * htng_tsid_plp,uint16_t * tsid_plp,uint8_t * htng_symbol_rate,uint16_t * symbol_rate)813 static inline void cec_ops_htng_global_direct_tune_ext_freq(const struct cec_msg *msg,
814 uint8_t *htng_ext_chan_type,
815 uint8_t *htng_prog_type,
816 uint8_t *htng_system_type,
817 uint16_t *freq,
818 uint16_t *service_id,
819 uint8_t *htng_mod_type,
820 uint8_t *htng_onid,
821 uint16_t *onid,
822 uint8_t *htng_nid,
823 uint16_t *nid,
824 uint8_t *htng_tsid_plp,
825 uint16_t *tsid_plp,
826 uint8_t *htng_symbol_rate,
827 uint16_t *symbol_rate)
828 {
829 unsigned offset = 12;
830
831 *htng_ext_chan_type = msg->msg[6] & 7;
832 *htng_prog_type = (msg->msg[6] >> 3) & 1;
833 *htng_system_type = (msg->msg[6] >> 4) & 0xf;
834 *freq = (msg->msg[7] << 8) | msg->msg[8];
835 *service_id = (msg->msg[9] << 8) | msg->msg[10];
836 *htng_mod_type = msg->msg[11] & 0xf;
837 *htng_onid = (msg->msg[11] >> 4) & 1;
838 *htng_nid = (msg->msg[11] >> 5) & 1;
839 *htng_tsid_plp = (msg->msg[11] >> 6) & 1;
840 *htng_symbol_rate = (msg->msg[11] >> 7) & 1;
841 if (*htng_onid == CEC_OP_HTNG_ONID_MANUAL) {
842 *onid = (msg->msg[offset] << 8) | msg->msg[offset + 1];
843 offset += 2;
844 } else {
845 *onid = 0;
846 }
847 if (*htng_nid == CEC_OP_HTNG_NID_MANUAL) {
848 *nid = (msg->msg[offset] << 8) | msg->msg[offset + 1];
849 offset += 2;
850 } else {
851 *nid = 0;
852 }
853 if (offset < CEC_MAX_MSG_SIZE &&
854 *htng_tsid_plp == CEC_OP_HTNG_TSID_PLP_MANUAL) {
855 *tsid_plp = (msg->msg[offset] << 8) | msg->msg[offset + 1];
856 offset += 2;
857 } else {
858 *tsid_plp = 0;
859 }
860 if (offset < CEC_MAX_MSG_SIZE &&
861 *htng_symbol_rate == CEC_OP_HTNG_SYMBOL_RATE_MANUAL) {
862 *symbol_rate = (msg->msg[offset] << 8) | msg->msg[offset + 1];
863 offset += 2;
864 } else {
865 *symbol_rate = 0;
866 }
867 }
868
869 #endif
870