2 * cec - HDMI Consumer Electronics Control message functions
4 * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
6 * This program is free software; you may redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * Alternatively you can redistribute this file under the terms of the
11 * BSD license as stated below:
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in
20 * the documentation and/or other materials provided with the
22 * 3. The names of its contributors may not be used to endorse or promote
23 * products derived from this software without specific prior written
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37 * Note: this framework is still in staging and it is likely the API
38 * will change before it goes out of staging.
40 * Once it is moved out of staging this header will move to uapi.
42 #ifndef _CEC_UAPI_FUNCS_H
43 #define _CEC_UAPI_FUNCS_H
45 #include <linux/cec.h>
47 /* One Touch Play Feature */
48 static inline void cec_msg_active_source(struct cec_msg *msg, __u16 phys_addr)
51 msg->msg[0] |= 0xf; /* broadcast */
52 msg->msg[1] = CEC_MSG_ACTIVE_SOURCE;
53 msg->msg[2] = phys_addr >> 8;
54 msg->msg[3] = phys_addr & 0xff;
57 static inline void cec_ops_active_source(const struct cec_msg *msg,
60 *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
63 static inline void cec_msg_image_view_on(struct cec_msg *msg)
66 msg->msg[1] = CEC_MSG_IMAGE_VIEW_ON;
69 static inline void cec_msg_text_view_on(struct cec_msg *msg)
72 msg->msg[1] = CEC_MSG_TEXT_VIEW_ON;
76 /* Routing Control Feature */
77 static inline void cec_msg_inactive_source(struct cec_msg *msg,
81 msg->msg[1] = CEC_MSG_INACTIVE_SOURCE;
82 msg->msg[2] = phys_addr >> 8;
83 msg->msg[3] = phys_addr & 0xff;
86 static inline void cec_ops_inactive_source(const struct cec_msg *msg,
89 *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
92 static inline void cec_msg_request_active_source(struct cec_msg *msg,
96 msg->msg[0] |= 0xf; /* broadcast */
97 msg->msg[1] = CEC_MSG_REQUEST_ACTIVE_SOURCE;
98 msg->reply = reply ? CEC_MSG_ACTIVE_SOURCE : 0;
101 static inline void cec_msg_routing_information(struct cec_msg *msg,
105 msg->msg[0] |= 0xf; /* broadcast */
106 msg->msg[1] = CEC_MSG_ROUTING_INFORMATION;
107 msg->msg[2] = phys_addr >> 8;
108 msg->msg[3] = phys_addr & 0xff;
111 static inline void cec_ops_routing_information(const struct cec_msg *msg,
114 *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
117 static inline void cec_msg_routing_change(struct cec_msg *msg,
119 __u16 orig_phys_addr,
123 msg->msg[0] |= 0xf; /* broadcast */
124 msg->msg[1] = CEC_MSG_ROUTING_CHANGE;
125 msg->msg[2] = orig_phys_addr >> 8;
126 msg->msg[3] = orig_phys_addr & 0xff;
127 msg->msg[4] = new_phys_addr >> 8;
128 msg->msg[5] = new_phys_addr & 0xff;
129 msg->reply = reply ? CEC_MSG_ROUTING_INFORMATION : 0;
132 static inline void cec_ops_routing_change(const struct cec_msg *msg,
133 __u16 *orig_phys_addr,
134 __u16 *new_phys_addr)
136 *orig_phys_addr = (msg->msg[2] << 8) | msg->msg[3];
137 *new_phys_addr = (msg->msg[4] << 8) | msg->msg[5];
140 static inline void cec_msg_set_stream_path(struct cec_msg *msg, __u16 phys_addr)
143 msg->msg[0] |= 0xf; /* broadcast */
144 msg->msg[1] = CEC_MSG_SET_STREAM_PATH;
145 msg->msg[2] = phys_addr >> 8;
146 msg->msg[3] = phys_addr & 0xff;
149 static inline void cec_ops_set_stream_path(const struct cec_msg *msg,
152 *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
156 /* Standby Feature */
157 static inline void cec_msg_standby(struct cec_msg *msg)
160 msg->msg[1] = CEC_MSG_STANDBY;
164 /* One Touch Record Feature */
165 static inline void cec_msg_record_off(struct cec_msg *msg, bool reply)
168 msg->msg[1] = CEC_MSG_RECORD_OFF;
169 msg->reply = reply ? CEC_MSG_RECORD_STATUS : 0;
172 struct cec_op_arib_data {
175 __u16 orig_network_id;
178 struct cec_op_atsc_data {
180 __u16 program_number;
183 struct cec_op_dvb_data {
186 __u16 orig_network_id;
189 struct cec_op_channel_data {
190 __u8 channel_number_fmt;
195 struct cec_op_digital_service_id {
196 __u8 service_id_method;
197 __u8 dig_bcast_system;
199 struct cec_op_arib_data arib;
200 struct cec_op_atsc_data atsc;
201 struct cec_op_dvb_data dvb;
202 struct cec_op_channel_data channel;
206 struct cec_op_record_src {
209 struct cec_op_digital_service_id digital;
224 static inline void cec_set_digital_service_id(__u8 *msg,
225 const struct cec_op_digital_service_id *digital)
227 *msg++ = (digital->service_id_method << 7) | digital->dig_bcast_system;
228 if (digital->service_id_method == CEC_OP_SERVICE_ID_METHOD_BY_CHANNEL) {
229 *msg++ = (digital->channel.channel_number_fmt << 2) |
230 (digital->channel.major >> 8);
231 *msg++ = digital->channel.major & 0xff;
232 *msg++ = digital->channel.minor >> 8;
233 *msg++ = digital->channel.minor & 0xff;
238 switch (digital->dig_bcast_system) {
239 case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_GEN:
240 case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_CABLE:
241 case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_SAT:
242 case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_T:
243 *msg++ = digital->atsc.transport_id >> 8;
244 *msg++ = digital->atsc.transport_id & 0xff;
245 *msg++ = digital->atsc.program_number >> 8;
246 *msg++ = digital->atsc.program_number & 0xff;
251 *msg++ = digital->dvb.transport_id >> 8;
252 *msg++ = digital->dvb.transport_id & 0xff;
253 *msg++ = digital->dvb.service_id >> 8;
254 *msg++ = digital->dvb.service_id & 0xff;
255 *msg++ = digital->dvb.orig_network_id >> 8;
256 *msg++ = digital->dvb.orig_network_id & 0xff;
261 static inline void cec_get_digital_service_id(const __u8 *msg,
262 struct cec_op_digital_service_id *digital)
264 digital->service_id_method = msg[0] >> 7;
265 digital->dig_bcast_system = msg[0] & 0x7f;
266 if (digital->service_id_method == CEC_OP_SERVICE_ID_METHOD_BY_CHANNEL) {
267 digital->channel.channel_number_fmt = msg[1] >> 2;
268 digital->channel.major = ((msg[1] & 3) << 6) | msg[2];
269 digital->channel.minor = (msg[3] << 8) | msg[4];
272 digital->dvb.transport_id = (msg[1] << 8) | msg[2];
273 digital->dvb.service_id = (msg[3] << 8) | msg[4];
274 digital->dvb.orig_network_id = (msg[5] << 8) | msg[6];
277 static inline void cec_msg_record_on_own(struct cec_msg *msg)
280 msg->msg[1] = CEC_MSG_RECORD_ON;
281 msg->msg[2] = CEC_OP_RECORD_SRC_OWN;
284 static inline void cec_msg_record_on_digital(struct cec_msg *msg,
285 const struct cec_op_digital_service_id *digital)
288 msg->msg[1] = CEC_MSG_RECORD_ON;
289 msg->msg[2] = CEC_OP_RECORD_SRC_DIGITAL;
290 cec_set_digital_service_id(msg->msg + 3, digital);
293 static inline void cec_msg_record_on_analog(struct cec_msg *msg,
299 msg->msg[1] = CEC_MSG_RECORD_ON;
300 msg->msg[2] = CEC_OP_RECORD_SRC_ANALOG;
301 msg->msg[3] = ana_bcast_type;
302 msg->msg[4] = ana_freq >> 8;
303 msg->msg[5] = ana_freq & 0xff;
304 msg->msg[6] = bcast_system;
307 static inline void cec_msg_record_on_plug(struct cec_msg *msg,
311 msg->msg[1] = CEC_MSG_RECORD_ON;
312 msg->msg[2] = CEC_OP_RECORD_SRC_EXT_PLUG;
316 static inline void cec_msg_record_on_phys_addr(struct cec_msg *msg,
320 msg->msg[1] = CEC_MSG_RECORD_ON;
321 msg->msg[2] = CEC_OP_RECORD_SRC_EXT_PHYS_ADDR;
322 msg->msg[3] = phys_addr >> 8;
323 msg->msg[4] = phys_addr & 0xff;
326 static inline void cec_msg_record_on(struct cec_msg *msg,
328 const struct cec_op_record_src *rec_src)
330 switch (rec_src->type) {
331 case CEC_OP_RECORD_SRC_OWN:
332 cec_msg_record_on_own(msg);
334 case CEC_OP_RECORD_SRC_DIGITAL:
335 cec_msg_record_on_digital(msg, &rec_src->digital);
337 case CEC_OP_RECORD_SRC_ANALOG:
338 cec_msg_record_on_analog(msg,
339 rec_src->analog.ana_bcast_type,
340 rec_src->analog.ana_freq,
341 rec_src->analog.bcast_system);
343 case CEC_OP_RECORD_SRC_EXT_PLUG:
344 cec_msg_record_on_plug(msg, rec_src->ext_plug.plug);
346 case CEC_OP_RECORD_SRC_EXT_PHYS_ADDR:
347 cec_msg_record_on_phys_addr(msg,
348 rec_src->ext_phys_addr.phys_addr);
351 msg->reply = reply ? CEC_MSG_RECORD_STATUS : 0;
354 static inline void cec_ops_record_on(const struct cec_msg *msg,
355 struct cec_op_record_src *rec_src)
357 rec_src->type = msg->msg[2];
358 switch (rec_src->type) {
359 case CEC_OP_RECORD_SRC_OWN:
361 case CEC_OP_RECORD_SRC_DIGITAL:
362 cec_get_digital_service_id(msg->msg + 3, &rec_src->digital);
364 case CEC_OP_RECORD_SRC_ANALOG:
365 rec_src->analog.ana_bcast_type = msg->msg[3];
366 rec_src->analog.ana_freq =
367 (msg->msg[4] << 8) | msg->msg[5];
368 rec_src->analog.bcast_system = msg->msg[6];
370 case CEC_OP_RECORD_SRC_EXT_PLUG:
371 rec_src->ext_plug.plug = msg->msg[3];
373 case CEC_OP_RECORD_SRC_EXT_PHYS_ADDR:
374 rec_src->ext_phys_addr.phys_addr =
375 (msg->msg[3] << 8) | msg->msg[4];
380 static inline void cec_msg_record_status(struct cec_msg *msg, __u8 rec_status)
383 msg->msg[1] = CEC_MSG_RECORD_STATUS;
384 msg->msg[2] = rec_status;
387 static inline void cec_ops_record_status(const struct cec_msg *msg,
390 *rec_status = msg->msg[2];
393 static inline void cec_msg_record_tv_screen(struct cec_msg *msg,
397 msg->msg[1] = CEC_MSG_RECORD_TV_SCREEN;
398 msg->reply = reply ? CEC_MSG_RECORD_ON : 0;
402 /* Timer Programming Feature */
403 static inline void cec_msg_timer_status(struct cec_msg *msg,
404 __u8 timer_overlap_warning,
412 msg->msg[1] = CEC_MSG_TIMER_STATUS;
413 msg->msg[2] = (timer_overlap_warning << 7) |
415 (prog_info ? 0x10 : 0) |
416 (prog_info ? prog_info : prog_error);
417 if (prog_info == CEC_OP_PROG_INFO_NOT_ENOUGH_SPACE ||
418 prog_info == CEC_OP_PROG_INFO_MIGHT_NOT_BE_ENOUGH_SPACE ||
419 prog_error == CEC_OP_PROG_ERROR_DUPLICATE) {
421 msg->msg[3] = ((duration_hr / 10) << 4) | (duration_hr % 10);
422 msg->msg[4] = ((duration_min / 10) << 4) | (duration_min % 10);
426 static inline void cec_ops_timer_status(const struct cec_msg *msg,
427 __u8 *timer_overlap_warning,
434 *timer_overlap_warning = msg->msg[2] >> 7;
435 *media_info = (msg->msg[2] >> 5) & 3;
436 if (msg->msg[2] & 0x10) {
437 *prog_info = msg->msg[2] & 0xf;
441 *prog_error = msg->msg[2] & 0xf;
443 if (*prog_info == CEC_OP_PROG_INFO_NOT_ENOUGH_SPACE ||
444 *prog_info == CEC_OP_PROG_INFO_MIGHT_NOT_BE_ENOUGH_SPACE ||
445 *prog_error == CEC_OP_PROG_ERROR_DUPLICATE) {
446 *duration_hr = (msg->msg[3] >> 4) * 10 + (msg->msg[3] & 0xf);
447 *duration_min = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
449 *duration_hr = *duration_min = 0;
453 static inline void cec_msg_timer_cleared_status(struct cec_msg *msg,
454 __u8 timer_cleared_status)
457 msg->msg[1] = CEC_MSG_TIMER_CLEARED_STATUS;
458 msg->msg[2] = timer_cleared_status;
461 static inline void cec_ops_timer_cleared_status(const struct cec_msg *msg,
462 __u8 *timer_cleared_status)
464 *timer_cleared_status = msg->msg[2];
467 static inline void cec_msg_clear_analogue_timer(struct cec_msg *msg,
481 msg->msg[1] = CEC_MSG_CLEAR_ANALOGUE_TIMER;
484 /* Hours and minutes are in BCD format */
485 msg->msg[4] = ((start_hr / 10) << 4) | (start_hr % 10);
486 msg->msg[5] = ((start_min / 10) << 4) | (start_min % 10);
487 msg->msg[6] = ((duration_hr / 10) << 4) | (duration_hr % 10);
488 msg->msg[7] = ((duration_min / 10) << 4) | (duration_min % 10);
489 msg->msg[8] = recording_seq;
490 msg->msg[9] = ana_bcast_type;
491 msg->msg[10] = ana_freq >> 8;
492 msg->msg[11] = ana_freq & 0xff;
493 msg->msg[12] = bcast_system;
494 msg->reply = reply ? CEC_MSG_TIMER_CLEARED_STATUS : 0;
497 static inline void cec_ops_clear_analogue_timer(const struct cec_msg *msg,
505 __u8 *ana_bcast_type,
510 *month = msg->msg[3];
511 /* Hours and minutes are in BCD format */
512 *start_hr = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
513 *start_min = (msg->msg[5] >> 4) * 10 + (msg->msg[5] & 0xf);
514 *duration_hr = (msg->msg[6] >> 4) * 10 + (msg->msg[6] & 0xf);
515 *duration_min = (msg->msg[7] >> 4) * 10 + (msg->msg[7] & 0xf);
516 *recording_seq = msg->msg[8];
517 *ana_bcast_type = msg->msg[9];
518 *ana_freq = (msg->msg[10] << 8) | msg->msg[11];
519 *bcast_system = msg->msg[12];
522 static inline void cec_msg_clear_digital_timer(struct cec_msg *msg,
531 const struct cec_op_digital_service_id *digital)
534 msg->reply = reply ? CEC_MSG_TIMER_CLEARED_STATUS : 0;
535 msg->msg[1] = CEC_MSG_CLEAR_DIGITAL_TIMER;
538 /* Hours and minutes are in BCD format */
539 msg->msg[4] = ((start_hr / 10) << 4) | (start_hr % 10);
540 msg->msg[5] = ((start_min / 10) << 4) | (start_min % 10);
541 msg->msg[6] = ((duration_hr / 10) << 4) | (duration_hr % 10);
542 msg->msg[7] = ((duration_min / 10) << 4) | (duration_min % 10);
543 msg->msg[8] = recording_seq;
544 cec_set_digital_service_id(msg->msg + 9, digital);
547 static inline void cec_ops_clear_digital_timer(const struct cec_msg *msg,
555 struct cec_op_digital_service_id *digital)
558 *month = msg->msg[3];
559 /* Hours and minutes are in BCD format */
560 *start_hr = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
561 *start_min = (msg->msg[5] >> 4) * 10 + (msg->msg[5] & 0xf);
562 *duration_hr = (msg->msg[6] >> 4) * 10 + (msg->msg[6] & 0xf);
563 *duration_min = (msg->msg[7] >> 4) * 10 + (msg->msg[7] & 0xf);
564 *recording_seq = msg->msg[8];
565 cec_get_digital_service_id(msg->msg + 9, digital);
568 static inline void cec_msg_clear_ext_timer(struct cec_msg *msg,
582 msg->msg[1] = CEC_MSG_CLEAR_EXT_TIMER;
585 /* Hours and minutes are in BCD format */
586 msg->msg[4] = ((start_hr / 10) << 4) | (start_hr % 10);
587 msg->msg[5] = ((start_min / 10) << 4) | (start_min % 10);
588 msg->msg[6] = ((duration_hr / 10) << 4) | (duration_hr % 10);
589 msg->msg[7] = ((duration_min / 10) << 4) | (duration_min % 10);
590 msg->msg[8] = recording_seq;
591 msg->msg[9] = ext_src_spec;
593 msg->msg[11] = phys_addr >> 8;
594 msg->msg[12] = phys_addr & 0xff;
595 msg->reply = reply ? CEC_MSG_TIMER_CLEARED_STATUS : 0;
598 static inline void cec_ops_clear_ext_timer(const struct cec_msg *msg,
611 *month = msg->msg[3];
612 /* Hours and minutes are in BCD format */
613 *start_hr = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
614 *start_min = (msg->msg[5] >> 4) * 10 + (msg->msg[5] & 0xf);
615 *duration_hr = (msg->msg[6] >> 4) * 10 + (msg->msg[6] & 0xf);
616 *duration_min = (msg->msg[7] >> 4) * 10 + (msg->msg[7] & 0xf);
617 *recording_seq = msg->msg[8];
618 *ext_src_spec = msg->msg[9];
619 *plug = msg->msg[10];
620 *phys_addr = (msg->msg[11] << 8) | msg->msg[12];
623 static inline void cec_msg_set_analogue_timer(struct cec_msg *msg,
637 msg->msg[1] = CEC_MSG_SET_ANALOGUE_TIMER;
640 /* Hours and minutes are in BCD format */
641 msg->msg[4] = ((start_hr / 10) << 4) | (start_hr % 10);
642 msg->msg[5] = ((start_min / 10) << 4) | (start_min % 10);
643 msg->msg[6] = ((duration_hr / 10) << 4) | (duration_hr % 10);
644 msg->msg[7] = ((duration_min / 10) << 4) | (duration_min % 10);
645 msg->msg[8] = recording_seq;
646 msg->msg[9] = ana_bcast_type;
647 msg->msg[10] = ana_freq >> 8;
648 msg->msg[11] = ana_freq & 0xff;
649 msg->msg[12] = bcast_system;
650 msg->reply = reply ? CEC_MSG_TIMER_STATUS : 0;
653 static inline void cec_ops_set_analogue_timer(const struct cec_msg *msg,
661 __u8 *ana_bcast_type,
666 *month = msg->msg[3];
667 /* Hours and minutes are in BCD format */
668 *start_hr = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
669 *start_min = (msg->msg[5] >> 4) * 10 + (msg->msg[5] & 0xf);
670 *duration_hr = (msg->msg[6] >> 4) * 10 + (msg->msg[6] & 0xf);
671 *duration_min = (msg->msg[7] >> 4) * 10 + (msg->msg[7] & 0xf);
672 *recording_seq = msg->msg[8];
673 *ana_bcast_type = msg->msg[9];
674 *ana_freq = (msg->msg[10] << 8) | msg->msg[11];
675 *bcast_system = msg->msg[12];
678 static inline void cec_msg_set_digital_timer(struct cec_msg *msg,
687 const struct cec_op_digital_service_id *digital)
690 msg->reply = reply ? CEC_MSG_TIMER_STATUS : 0;
691 msg->msg[1] = CEC_MSG_SET_DIGITAL_TIMER;
694 /* Hours and minutes are in BCD format */
695 msg->msg[4] = ((start_hr / 10) << 4) | (start_hr % 10);
696 msg->msg[5] = ((start_min / 10) << 4) | (start_min % 10);
697 msg->msg[6] = ((duration_hr / 10) << 4) | (duration_hr % 10);
698 msg->msg[7] = ((duration_min / 10) << 4) | (duration_min % 10);
699 msg->msg[8] = recording_seq;
700 cec_set_digital_service_id(msg->msg + 9, digital);
703 static inline void cec_ops_set_digital_timer(const struct cec_msg *msg,
711 struct cec_op_digital_service_id *digital)
714 *month = msg->msg[3];
715 /* Hours and minutes are in BCD format */
716 *start_hr = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
717 *start_min = (msg->msg[5] >> 4) * 10 + (msg->msg[5] & 0xf);
718 *duration_hr = (msg->msg[6] >> 4) * 10 + (msg->msg[6] & 0xf);
719 *duration_min = (msg->msg[7] >> 4) * 10 + (msg->msg[7] & 0xf);
720 *recording_seq = msg->msg[8];
721 cec_get_digital_service_id(msg->msg + 9, digital);
724 static inline void cec_msg_set_ext_timer(struct cec_msg *msg,
738 msg->msg[1] = CEC_MSG_SET_EXT_TIMER;
741 /* Hours and minutes are in BCD format */
742 msg->msg[4] = ((start_hr / 10) << 4) | (start_hr % 10);
743 msg->msg[5] = ((start_min / 10) << 4) | (start_min % 10);
744 msg->msg[6] = ((duration_hr / 10) << 4) | (duration_hr % 10);
745 msg->msg[7] = ((duration_min / 10) << 4) | (duration_min % 10);
746 msg->msg[8] = recording_seq;
747 msg->msg[9] = ext_src_spec;
749 msg->msg[11] = phys_addr >> 8;
750 msg->msg[12] = phys_addr & 0xff;
751 msg->reply = reply ? CEC_MSG_TIMER_STATUS : 0;
754 static inline void cec_ops_set_ext_timer(const struct cec_msg *msg,
767 *month = msg->msg[3];
768 /* Hours and minutes are in BCD format */
769 *start_hr = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
770 *start_min = (msg->msg[5] >> 4) * 10 + (msg->msg[5] & 0xf);
771 *duration_hr = (msg->msg[6] >> 4) * 10 + (msg->msg[6] & 0xf);
772 *duration_min = (msg->msg[7] >> 4) * 10 + (msg->msg[7] & 0xf);
773 *recording_seq = msg->msg[8];
774 *ext_src_spec = msg->msg[9];
775 *plug = msg->msg[10];
776 *phys_addr = (msg->msg[11] << 8) | msg->msg[12];
779 static inline void cec_msg_set_timer_program_title(struct cec_msg *msg,
780 const char *prog_title)
782 unsigned int len = strlen(prog_title);
787 msg->msg[1] = CEC_MSG_SET_TIMER_PROGRAM_TITLE;
788 memcpy(msg->msg + 2, prog_title, len);
791 static inline void cec_ops_set_timer_program_title(const struct cec_msg *msg,
794 unsigned int len = msg->len > 2 ? msg->len - 2 : 0;
798 memcpy(prog_title, msg->msg + 2, len);
799 prog_title[len] = '\0';
802 /* System Information Feature */
803 static inline void cec_msg_cec_version(struct cec_msg *msg, __u8 cec_version)
806 msg->msg[1] = CEC_MSG_CEC_VERSION;
807 msg->msg[2] = cec_version;
810 static inline void cec_ops_cec_version(const struct cec_msg *msg,
813 *cec_version = msg->msg[2];
816 static inline void cec_msg_get_cec_version(struct cec_msg *msg,
820 msg->msg[1] = CEC_MSG_GET_CEC_VERSION;
821 msg->reply = reply ? CEC_MSG_CEC_VERSION : 0;
824 static inline void cec_msg_report_physical_addr(struct cec_msg *msg,
825 __u16 phys_addr, __u8 prim_devtype)
828 msg->msg[0] |= 0xf; /* broadcast */
829 msg->msg[1] = CEC_MSG_REPORT_PHYSICAL_ADDR;
830 msg->msg[2] = phys_addr >> 8;
831 msg->msg[3] = phys_addr & 0xff;
832 msg->msg[4] = prim_devtype;
835 static inline void cec_ops_report_physical_addr(const struct cec_msg *msg,
836 __u16 *phys_addr, __u8 *prim_devtype)
838 *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
839 *prim_devtype = msg->msg[4];
842 static inline void cec_msg_give_physical_addr(struct cec_msg *msg,
846 msg->msg[1] = CEC_MSG_GIVE_PHYSICAL_ADDR;
847 msg->reply = reply ? CEC_MSG_REPORT_PHYSICAL_ADDR : 0;
850 static inline void cec_msg_set_menu_language(struct cec_msg *msg,
851 const char *language)
854 msg->msg[0] |= 0xf; /* broadcast */
855 msg->msg[1] = CEC_MSG_SET_MENU_LANGUAGE;
856 memcpy(msg->msg + 2, language, 3);
859 static inline void cec_ops_set_menu_language(const struct cec_msg *msg,
862 memcpy(language, msg->msg + 2, 3);
866 static inline void cec_msg_get_menu_language(struct cec_msg *msg,
870 msg->msg[1] = CEC_MSG_GET_MENU_LANGUAGE;
871 msg->reply = reply ? CEC_MSG_SET_MENU_LANGUAGE : 0;
875 * Assumes a single RC Profile byte and a single Device Features byte,
876 * i.e. no extended features are supported by this helper function.
878 * As of CEC 2.0 no extended features are defined, should those be added
879 * in the future, then this function needs to be adapted or a new function
882 static inline void cec_msg_report_features(struct cec_msg *msg,
883 __u8 cec_version, __u8 all_device_types,
884 __u8 rc_profile, __u8 dev_features)
887 msg->msg[0] |= 0xf; /* broadcast */
888 msg->msg[1] = CEC_MSG_REPORT_FEATURES;
889 msg->msg[2] = cec_version;
890 msg->msg[3] = all_device_types;
891 msg->msg[4] = rc_profile;
892 msg->msg[5] = dev_features;
895 static inline void cec_ops_report_features(const struct cec_msg *msg,
896 __u8 *cec_version, __u8 *all_device_types,
897 const __u8 **rc_profile, const __u8 **dev_features)
899 const __u8 *p = &msg->msg[4];
901 *cec_version = msg->msg[2];
902 *all_device_types = msg->msg[3];
904 while (p < &msg->msg[14] && (*p & CEC_OP_FEAT_EXT))
906 if (!(*p & CEC_OP_FEAT_EXT)) {
907 *dev_features = p + 1;
908 while (p < &msg->msg[15] && (*p & CEC_OP_FEAT_EXT))
911 if (*p & CEC_OP_FEAT_EXT)
912 *rc_profile = *dev_features = NULL;
915 static inline void cec_msg_give_features(struct cec_msg *msg,
919 msg->msg[1] = CEC_MSG_GIVE_FEATURES;
920 msg->reply = reply ? CEC_MSG_REPORT_FEATURES : 0;
923 /* Deck Control Feature */
924 static inline void cec_msg_deck_control(struct cec_msg *msg,
925 __u8 deck_control_mode)
928 msg->msg[1] = CEC_MSG_DECK_CONTROL;
929 msg->msg[2] = deck_control_mode;
932 static inline void cec_ops_deck_control(const struct cec_msg *msg,
933 __u8 *deck_control_mode)
935 *deck_control_mode = msg->msg[2];
938 static inline void cec_msg_deck_status(struct cec_msg *msg,
942 msg->msg[1] = CEC_MSG_DECK_STATUS;
943 msg->msg[2] = deck_info;
946 static inline void cec_ops_deck_status(const struct cec_msg *msg,
949 *deck_info = msg->msg[2];
952 static inline void cec_msg_give_deck_status(struct cec_msg *msg,
957 msg->msg[1] = CEC_MSG_GIVE_DECK_STATUS;
958 msg->msg[2] = status_req;
959 msg->reply = reply ? CEC_MSG_DECK_STATUS : 0;
962 static inline void cec_ops_give_deck_status(const struct cec_msg *msg,
965 *status_req = msg->msg[2];
968 static inline void cec_msg_play(struct cec_msg *msg,
972 msg->msg[1] = CEC_MSG_PLAY;
973 msg->msg[2] = play_mode;
976 static inline void cec_ops_play(const struct cec_msg *msg,
979 *play_mode = msg->msg[2];
983 /* Tuner Control Feature */
984 struct cec_op_tuner_device_info {
986 __u8 tuner_display_info;
989 struct cec_op_digital_service_id digital;
998 static inline void cec_msg_tuner_device_status_analog(struct cec_msg *msg,
1000 __u8 tuner_display_info,
1001 __u8 ana_bcast_type,
1006 msg->msg[1] = CEC_MSG_TUNER_DEVICE_STATUS;
1007 msg->msg[2] = (rec_flag << 7) | tuner_display_info;
1008 msg->msg[3] = ana_bcast_type;
1009 msg->msg[4] = ana_freq >> 8;
1010 msg->msg[5] = ana_freq & 0xff;
1011 msg->msg[6] = bcast_system;
1014 static inline void cec_msg_tuner_device_status_digital(struct cec_msg *msg,
1015 __u8 rec_flag, __u8 tuner_display_info,
1016 const struct cec_op_digital_service_id *digital)
1019 msg->msg[1] = CEC_MSG_TUNER_DEVICE_STATUS;
1020 msg->msg[2] = (rec_flag << 7) | tuner_display_info;
1021 cec_set_digital_service_id(msg->msg + 3, digital);
1024 static inline void cec_msg_tuner_device_status(struct cec_msg *msg,
1025 const struct cec_op_tuner_device_info *tuner_dev_info)
1027 if (tuner_dev_info->is_analog)
1028 cec_msg_tuner_device_status_analog(msg,
1029 tuner_dev_info->rec_flag,
1030 tuner_dev_info->tuner_display_info,
1031 tuner_dev_info->analog.ana_bcast_type,
1032 tuner_dev_info->analog.ana_freq,
1033 tuner_dev_info->analog.bcast_system);
1035 cec_msg_tuner_device_status_digital(msg,
1036 tuner_dev_info->rec_flag,
1037 tuner_dev_info->tuner_display_info,
1038 &tuner_dev_info->digital);
1041 static inline void cec_ops_tuner_device_status(const struct cec_msg *msg,
1042 struct cec_op_tuner_device_info *tuner_dev_info)
1044 tuner_dev_info->is_analog = msg->len < 10;
1045 tuner_dev_info->rec_flag = msg->msg[2] >> 7;
1046 tuner_dev_info->tuner_display_info = msg->msg[2] & 0x7f;
1047 if (tuner_dev_info->is_analog) {
1048 tuner_dev_info->analog.ana_bcast_type = msg->msg[3];
1049 tuner_dev_info->analog.ana_freq = (msg->msg[4] << 8) | msg->msg[5];
1050 tuner_dev_info->analog.bcast_system = msg->msg[6];
1053 cec_get_digital_service_id(msg->msg + 3, &tuner_dev_info->digital);
1056 static inline void cec_msg_give_tuner_device_status(struct cec_msg *msg,
1061 msg->msg[1] = CEC_MSG_GIVE_TUNER_DEVICE_STATUS;
1062 msg->msg[2] = status_req;
1063 msg->reply = reply ? CEC_MSG_TUNER_DEVICE_STATUS : 0;
1066 static inline void cec_ops_give_tuner_device_status(const struct cec_msg *msg,
1069 *status_req = msg->msg[2];
1072 static inline void cec_msg_select_analogue_service(struct cec_msg *msg,
1073 __u8 ana_bcast_type,
1078 msg->msg[1] = CEC_MSG_SELECT_ANALOGUE_SERVICE;
1079 msg->msg[2] = ana_bcast_type;
1080 msg->msg[3] = ana_freq >> 8;
1081 msg->msg[4] = ana_freq & 0xff;
1082 msg->msg[5] = bcast_system;
1085 static inline void cec_ops_select_analogue_service(const struct cec_msg *msg,
1086 __u8 *ana_bcast_type,
1090 *ana_bcast_type = msg->msg[2];
1091 *ana_freq = (msg->msg[3] << 8) | msg->msg[4];
1092 *bcast_system = msg->msg[5];
1095 static inline void cec_msg_select_digital_service(struct cec_msg *msg,
1096 const struct cec_op_digital_service_id *digital)
1099 msg->msg[1] = CEC_MSG_SELECT_DIGITAL_SERVICE;
1100 cec_set_digital_service_id(msg->msg + 2, digital);
1103 static inline void cec_ops_select_digital_service(const struct cec_msg *msg,
1104 struct cec_op_digital_service_id *digital)
1106 cec_get_digital_service_id(msg->msg + 2, digital);
1109 static inline void cec_msg_tuner_step_decrement(struct cec_msg *msg)
1112 msg->msg[1] = CEC_MSG_TUNER_STEP_DECREMENT;
1115 static inline void cec_msg_tuner_step_increment(struct cec_msg *msg)
1118 msg->msg[1] = CEC_MSG_TUNER_STEP_INCREMENT;
1122 /* Vendor Specific Commands Feature */
1123 static inline void cec_msg_device_vendor_id(struct cec_msg *msg, __u32 vendor_id)
1126 msg->msg[0] |= 0xf; /* broadcast */
1127 msg->msg[1] = CEC_MSG_DEVICE_VENDOR_ID;
1128 msg->msg[2] = vendor_id >> 16;
1129 msg->msg[3] = (vendor_id >> 8) & 0xff;
1130 msg->msg[4] = vendor_id & 0xff;
1133 static inline void cec_ops_device_vendor_id(const struct cec_msg *msg,
1136 *vendor_id = (msg->msg[2] << 16) | (msg->msg[3] << 8) | msg->msg[4];
1139 static inline void cec_msg_give_device_vendor_id(struct cec_msg *msg,
1143 msg->msg[1] = CEC_MSG_GIVE_DEVICE_VENDOR_ID;
1144 msg->reply = reply ? CEC_MSG_DEVICE_VENDOR_ID : 0;
1147 static inline void cec_msg_vendor_command(struct cec_msg *msg,
1148 __u8 size, const __u8 *vendor_cmd)
1152 msg->len = 2 + size;
1153 msg->msg[1] = CEC_MSG_VENDOR_COMMAND;
1154 memcpy(msg->msg + 2, vendor_cmd, size);
1157 static inline void cec_ops_vendor_command(const struct cec_msg *msg,
1159 const __u8 **vendor_cmd)
1161 *size = msg->len - 2;
1165 *vendor_cmd = msg->msg + 2;
1168 static inline void cec_msg_vendor_command_with_id(struct cec_msg *msg,
1169 __u32 vendor_id, __u8 size,
1170 const __u8 *vendor_cmd)
1174 msg->len = 5 + size;
1175 msg->msg[1] = CEC_MSG_VENDOR_COMMAND_WITH_ID;
1176 msg->msg[2] = vendor_id >> 16;
1177 msg->msg[3] = (vendor_id >> 8) & 0xff;
1178 msg->msg[4] = vendor_id & 0xff;
1179 memcpy(msg->msg + 5, vendor_cmd, size);
1182 static inline void cec_ops_vendor_command_with_id(const struct cec_msg *msg,
1183 __u32 *vendor_id, __u8 *size,
1184 const __u8 **vendor_cmd)
1186 *size = msg->len - 5;
1190 *vendor_id = (msg->msg[2] << 16) | (msg->msg[3] << 8) | msg->msg[4];
1191 *vendor_cmd = msg->msg + 5;
1194 static inline void cec_msg_vendor_remote_button_down(struct cec_msg *msg,
1196 const __u8 *rc_code)
1200 msg->len = 2 + size;
1201 msg->msg[1] = CEC_MSG_VENDOR_REMOTE_BUTTON_DOWN;
1202 memcpy(msg->msg + 2, rc_code, size);
1205 static inline void cec_ops_vendor_remote_button_down(const struct cec_msg *msg,
1207 const __u8 **rc_code)
1209 *size = msg->len - 2;
1213 *rc_code = msg->msg + 2;
1216 static inline void cec_msg_vendor_remote_button_up(struct cec_msg *msg)
1219 msg->msg[1] = CEC_MSG_VENDOR_REMOTE_BUTTON_UP;
1223 /* OSD Display Feature */
1224 static inline void cec_msg_set_osd_string(struct cec_msg *msg,
1228 unsigned int len = strlen(osd);
1233 msg->msg[1] = CEC_MSG_SET_OSD_STRING;
1234 msg->msg[2] = disp_ctl;
1235 memcpy(msg->msg + 3, osd, len);
1238 static inline void cec_ops_set_osd_string(const struct cec_msg *msg,
1242 unsigned int len = msg->len > 3 ? msg->len - 3 : 0;
1244 *disp_ctl = msg->msg[2];
1247 memcpy(osd, msg->msg + 3, len);
1252 /* Device OSD Transfer Feature */
1253 static inline void cec_msg_set_osd_name(struct cec_msg *msg, const char *name)
1255 unsigned int len = strlen(name);
1260 msg->msg[1] = CEC_MSG_SET_OSD_NAME;
1261 memcpy(msg->msg + 2, name, len);
1264 static inline void cec_ops_set_osd_name(const struct cec_msg *msg,
1267 unsigned int len = msg->len > 2 ? msg->len - 2 : 0;
1271 memcpy(name, msg->msg + 2, len);
1275 static inline void cec_msg_give_osd_name(struct cec_msg *msg,
1279 msg->msg[1] = CEC_MSG_GIVE_OSD_NAME;
1280 msg->reply = reply ? CEC_MSG_SET_OSD_NAME : 0;
1284 /* Device Menu Control Feature */
1285 static inline void cec_msg_menu_status(struct cec_msg *msg,
1289 msg->msg[1] = CEC_MSG_MENU_STATUS;
1290 msg->msg[2] = menu_state;
1293 static inline void cec_ops_menu_status(const struct cec_msg *msg,
1296 *menu_state = msg->msg[2];
1299 static inline void cec_msg_menu_request(struct cec_msg *msg,
1304 msg->msg[1] = CEC_MSG_MENU_REQUEST;
1305 msg->msg[2] = menu_req;
1306 msg->reply = reply ? CEC_MSG_MENU_STATUS : 0;
1309 static inline void cec_ops_menu_request(const struct cec_msg *msg,
1312 *menu_req = msg->msg[2];
1315 struct cec_op_ui_command {
1319 struct cec_op_channel_data channel_identifier;
1320 __u8 ui_broadcast_type;
1321 __u8 ui_sound_presentation_control;
1323 __u8 ui_function_media;
1324 __u8 ui_function_select_av_input;
1325 __u8 ui_function_select_audio_input;
1329 static inline void cec_msg_user_control_pressed(struct cec_msg *msg,
1330 const struct cec_op_ui_command *ui_cmd)
1333 msg->msg[1] = CEC_MSG_USER_CONTROL_PRESSED;
1334 msg->msg[2] = ui_cmd->ui_cmd;
1335 if (!ui_cmd->has_opt_arg)
1337 switch (ui_cmd->ui_cmd) {
1344 /* The optional operand is one byte for all these ui commands */
1346 msg->msg[3] = ui_cmd->play_mode;
1350 msg->msg[3] = (ui_cmd->channel_identifier.channel_number_fmt << 2) |
1351 (ui_cmd->channel_identifier.major >> 8);
1352 msg->msg[4] = ui_cmd->channel_identifier.major & 0xff;
1353 msg->msg[5] = ui_cmd->channel_identifier.minor >> 8;
1354 msg->msg[6] = ui_cmd->channel_identifier.minor & 0xff;
1359 static inline void cec_ops_user_control_pressed(const struct cec_msg *msg,
1360 struct cec_op_ui_command *ui_cmd)
1362 ui_cmd->ui_cmd = msg->msg[2];
1363 ui_cmd->has_opt_arg = false;
1366 switch (ui_cmd->ui_cmd) {
1373 /* The optional operand is one byte for all these ui commands */
1374 ui_cmd->play_mode = msg->msg[3];
1375 ui_cmd->has_opt_arg = true;
1380 ui_cmd->has_opt_arg = true;
1381 ui_cmd->channel_identifier.channel_number_fmt = msg->msg[3] >> 2;
1382 ui_cmd->channel_identifier.major = ((msg->msg[3] & 3) << 6) | msg->msg[4];
1383 ui_cmd->channel_identifier.minor = (msg->msg[5] << 8) | msg->msg[6];
1388 static inline void cec_msg_user_control_released(struct cec_msg *msg)
1391 msg->msg[1] = CEC_MSG_USER_CONTROL_RELEASED;
1394 /* Remote Control Passthrough Feature */
1396 /* Power Status Feature */
1397 static inline void cec_msg_report_power_status(struct cec_msg *msg,
1401 msg->msg[1] = CEC_MSG_REPORT_POWER_STATUS;
1402 msg->msg[2] = pwr_state;
1405 static inline void cec_ops_report_power_status(const struct cec_msg *msg,
1408 *pwr_state = msg->msg[2];
1411 static inline void cec_msg_give_device_power_status(struct cec_msg *msg,
1415 msg->msg[1] = CEC_MSG_GIVE_DEVICE_POWER_STATUS;
1416 msg->reply = reply ? CEC_MSG_REPORT_POWER_STATUS : 0;
1419 /* General Protocol Messages */
1420 static inline void cec_msg_feature_abort(struct cec_msg *msg,
1421 __u8 abort_msg, __u8 reason)
1424 msg->msg[1] = CEC_MSG_FEATURE_ABORT;
1425 msg->msg[2] = abort_msg;
1426 msg->msg[3] = reason;
1429 static inline void cec_ops_feature_abort(const struct cec_msg *msg,
1430 __u8 *abort_msg, __u8 *reason)
1432 *abort_msg = msg->msg[2];
1433 *reason = msg->msg[3];
1436 /* This changes the current message into a feature abort message */
1437 static inline void cec_msg_reply_feature_abort(struct cec_msg *msg, __u8 reason)
1439 cec_msg_set_reply_to(msg, msg);
1441 msg->msg[2] = msg->msg[1];
1442 msg->msg[3] = reason;
1443 msg->msg[1] = CEC_MSG_FEATURE_ABORT;
1446 static inline void cec_msg_abort(struct cec_msg *msg)
1449 msg->msg[1] = CEC_MSG_ABORT;
1453 /* System Audio Control Feature */
1454 static inline void cec_msg_report_audio_status(struct cec_msg *msg,
1455 __u8 aud_mute_status,
1456 __u8 aud_vol_status)
1459 msg->msg[1] = CEC_MSG_REPORT_AUDIO_STATUS;
1460 msg->msg[2] = (aud_mute_status << 7) | (aud_vol_status & 0x7f);
1463 static inline void cec_ops_report_audio_status(const struct cec_msg *msg,
1464 __u8 *aud_mute_status,
1465 __u8 *aud_vol_status)
1467 *aud_mute_status = msg->msg[2] >> 7;
1468 *aud_vol_status = msg->msg[2] & 0x7f;
1471 static inline void cec_msg_give_audio_status(struct cec_msg *msg,
1475 msg->msg[1] = CEC_MSG_GIVE_AUDIO_STATUS;
1476 msg->reply = reply ? CEC_MSG_REPORT_AUDIO_STATUS : 0;
1479 static inline void cec_msg_set_system_audio_mode(struct cec_msg *msg,
1480 __u8 sys_aud_status)
1483 msg->msg[1] = CEC_MSG_SET_SYSTEM_AUDIO_MODE;
1484 msg->msg[2] = sys_aud_status;
1487 static inline void cec_ops_set_system_audio_mode(const struct cec_msg *msg,
1488 __u8 *sys_aud_status)
1490 *sys_aud_status = msg->msg[2];
1493 static inline void cec_msg_system_audio_mode_request(struct cec_msg *msg,
1497 msg->len = phys_addr == 0xffff ? 2 : 4;
1498 msg->msg[1] = CEC_MSG_SYSTEM_AUDIO_MODE_REQUEST;
1499 msg->msg[2] = phys_addr >> 8;
1500 msg->msg[3] = phys_addr & 0xff;
1501 msg->reply = reply ? CEC_MSG_SET_SYSTEM_AUDIO_MODE : 0;
1505 static inline void cec_ops_system_audio_mode_request(const struct cec_msg *msg,
1509 *phys_addr = 0xffff;
1511 *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1514 static inline void cec_msg_system_audio_mode_status(struct cec_msg *msg,
1515 __u8 sys_aud_status)
1518 msg->msg[1] = CEC_MSG_SYSTEM_AUDIO_MODE_STATUS;
1519 msg->msg[2] = sys_aud_status;
1522 static inline void cec_ops_system_audio_mode_status(const struct cec_msg *msg,
1523 __u8 *sys_aud_status)
1525 *sys_aud_status = msg->msg[2];
1528 static inline void cec_msg_give_system_audio_mode_status(struct cec_msg *msg,
1532 msg->msg[1] = CEC_MSG_GIVE_SYSTEM_AUDIO_MODE_STATUS;
1533 msg->reply = reply ? CEC_MSG_SYSTEM_AUDIO_MODE_STATUS : 0;
1536 static inline void cec_msg_report_short_audio_descriptor(struct cec_msg *msg,
1537 __u8 num_descriptors,
1538 const __u32 *descriptors)
1542 if (num_descriptors > 4)
1543 num_descriptors = 4;
1544 msg->len = 2 + num_descriptors * 3;
1545 msg->msg[1] = CEC_MSG_REPORT_SHORT_AUDIO_DESCRIPTOR;
1546 for (i = 0; i < num_descriptors; i++) {
1547 msg->msg[2 + i * 3] = (descriptors[i] >> 16) & 0xff;
1548 msg->msg[3 + i * 3] = (descriptors[i] >> 8) & 0xff;
1549 msg->msg[4 + i * 3] = descriptors[i] & 0xff;
1553 static inline void cec_ops_report_short_audio_descriptor(const struct cec_msg *msg,
1554 __u8 *num_descriptors,
1559 *num_descriptors = (msg->len - 2) / 3;
1560 if (*num_descriptors > 4)
1561 *num_descriptors = 4;
1562 for (i = 0; i < *num_descriptors; i++)
1563 descriptors[i] = (msg->msg[2 + i * 3] << 16) |
1564 (msg->msg[3 + i * 3] << 8) |
1565 msg->msg[4 + i * 3];
1568 static inline void cec_msg_request_short_audio_descriptor(struct cec_msg *msg,
1570 __u8 num_descriptors,
1571 const __u8 *audio_format_id,
1572 const __u8 *audio_format_code)
1576 if (num_descriptors > 4)
1577 num_descriptors = 4;
1578 msg->len = 2 + num_descriptors;
1579 msg->msg[1] = CEC_MSG_REQUEST_SHORT_AUDIO_DESCRIPTOR;
1580 msg->reply = reply ? CEC_MSG_REPORT_SHORT_AUDIO_DESCRIPTOR : 0;
1581 for (i = 0; i < num_descriptors; i++)
1582 msg->msg[2 + i] = (audio_format_id[i] << 6) |
1583 (audio_format_code[i] & 0x3f);
1586 static inline void cec_ops_request_short_audio_descriptor(const struct cec_msg *msg,
1587 __u8 *num_descriptors,
1588 __u8 *audio_format_id,
1589 __u8 *audio_format_code)
1593 *num_descriptors = msg->len - 2;
1594 if (*num_descriptors > 4)
1595 *num_descriptors = 4;
1596 for (i = 0; i < *num_descriptors; i++) {
1597 audio_format_id[i] = msg->msg[2 + i] >> 6;
1598 audio_format_code[i] = msg->msg[2 + i] & 0x3f;
1603 /* Audio Rate Control Feature */
1604 static inline void cec_msg_set_audio_rate(struct cec_msg *msg,
1608 msg->msg[1] = CEC_MSG_SET_AUDIO_RATE;
1609 msg->msg[2] = audio_rate;
1612 static inline void cec_ops_set_audio_rate(const struct cec_msg *msg,
1615 *audio_rate = msg->msg[2];
1619 /* Audio Return Channel Control Feature */
1620 static inline void cec_msg_report_arc_initiated(struct cec_msg *msg)
1623 msg->msg[1] = CEC_MSG_REPORT_ARC_INITIATED;
1626 static inline void cec_msg_initiate_arc(struct cec_msg *msg,
1630 msg->msg[1] = CEC_MSG_INITIATE_ARC;
1631 msg->reply = reply ? CEC_MSG_REPORT_ARC_INITIATED : 0;
1634 static inline void cec_msg_request_arc_initiation(struct cec_msg *msg,
1638 msg->msg[1] = CEC_MSG_REQUEST_ARC_INITIATION;
1639 msg->reply = reply ? CEC_MSG_INITIATE_ARC : 0;
1642 static inline void cec_msg_report_arc_terminated(struct cec_msg *msg)
1645 msg->msg[1] = CEC_MSG_REPORT_ARC_TERMINATED;
1648 static inline void cec_msg_terminate_arc(struct cec_msg *msg,
1652 msg->msg[1] = CEC_MSG_TERMINATE_ARC;
1653 msg->reply = reply ? CEC_MSG_REPORT_ARC_TERMINATED : 0;
1656 static inline void cec_msg_request_arc_termination(struct cec_msg *msg,
1660 msg->msg[1] = CEC_MSG_REQUEST_ARC_TERMINATION;
1661 msg->reply = reply ? CEC_MSG_TERMINATE_ARC : 0;
1665 /* Dynamic Audio Lipsync Feature */
1666 /* Only for CEC 2.0 and up */
1667 static inline void cec_msg_report_current_latency(struct cec_msg *msg,
1670 __u8 low_latency_mode,
1671 __u8 audio_out_compensated,
1672 __u8 audio_out_delay)
1675 msg->msg[0] |= 0xf; /* broadcast */
1676 msg->msg[1] = CEC_MSG_REPORT_CURRENT_LATENCY;
1677 msg->msg[2] = phys_addr >> 8;
1678 msg->msg[3] = phys_addr & 0xff;
1679 msg->msg[4] = video_latency;
1680 msg->msg[5] = (low_latency_mode << 2) | audio_out_compensated;
1681 msg->msg[6] = audio_out_delay;
1684 static inline void cec_ops_report_current_latency(const struct cec_msg *msg,
1686 __u8 *video_latency,
1687 __u8 *low_latency_mode,
1688 __u8 *audio_out_compensated,
1689 __u8 *audio_out_delay)
1691 *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1692 *video_latency = msg->msg[4];
1693 *low_latency_mode = (msg->msg[5] >> 2) & 1;
1694 *audio_out_compensated = msg->msg[5] & 3;
1695 *audio_out_delay = msg->msg[6];
1698 static inline void cec_msg_request_current_latency(struct cec_msg *msg,
1703 msg->msg[0] |= 0xf; /* broadcast */
1704 msg->msg[1] = CEC_MSG_REQUEST_CURRENT_LATENCY;
1705 msg->msg[2] = phys_addr >> 8;
1706 msg->msg[3] = phys_addr & 0xff;
1707 msg->reply = reply ? CEC_MSG_REPORT_CURRENT_LATENCY : 0;
1710 static inline void cec_ops_request_current_latency(const struct cec_msg *msg,
1713 *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1717 /* Capability Discovery and Control Feature */
1718 static inline void cec_msg_cdc_hec_inquire_state(struct cec_msg *msg,
1723 msg->msg[0] |= 0xf; /* broadcast */
1724 msg->msg[1] = CEC_MSG_CDC_MESSAGE;
1725 /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
1726 msg->msg[4] = CEC_MSG_CDC_HEC_INQUIRE_STATE;
1727 msg->msg[5] = phys_addr1 >> 8;
1728 msg->msg[6] = phys_addr1 & 0xff;
1729 msg->msg[7] = phys_addr2 >> 8;
1730 msg->msg[8] = phys_addr2 & 0xff;
1733 static inline void cec_ops_cdc_hec_inquire_state(const struct cec_msg *msg,
1738 *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1739 *phys_addr1 = (msg->msg[5] << 8) | msg->msg[6];
1740 *phys_addr2 = (msg->msg[7] << 8) | msg->msg[8];
1743 static inline void cec_msg_cdc_hec_report_state(struct cec_msg *msg,
1744 __u16 target_phys_addr,
1745 __u8 hec_func_state,
1746 __u8 host_func_state,
1747 __u8 enc_func_state,
1752 msg->len = has_field ? 10 : 8;
1753 msg->msg[0] |= 0xf; /* broadcast */
1754 msg->msg[1] = CEC_MSG_CDC_MESSAGE;
1755 /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
1756 msg->msg[4] = CEC_MSG_CDC_HEC_REPORT_STATE;
1757 msg->msg[5] = target_phys_addr >> 8;
1758 msg->msg[6] = target_phys_addr & 0xff;
1759 msg->msg[7] = (hec_func_state << 6) |
1760 (host_func_state << 4) |
1761 (enc_func_state << 2) |
1764 msg->msg[8] = hec_field >> 8;
1765 msg->msg[9] = hec_field & 0xff;
1769 static inline void cec_ops_cdc_hec_report_state(const struct cec_msg *msg,
1771 __u16 *target_phys_addr,
1772 __u8 *hec_func_state,
1773 __u8 *host_func_state,
1774 __u8 *enc_func_state,
1779 *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1780 *target_phys_addr = (msg->msg[5] << 8) | msg->msg[6];
1781 *hec_func_state = msg->msg[7] >> 6;
1782 *host_func_state = (msg->msg[7] >> 4) & 3;
1783 *enc_func_state = (msg->msg[7] >> 4) & 3;
1784 *cdc_errcode = msg->msg[7] & 3;
1785 *has_field = msg->len >= 10;
1786 *hec_field = *has_field ? ((msg->msg[8] << 8) | msg->msg[9]) : 0;
1789 static inline void cec_msg_cdc_hec_set_state(struct cec_msg *msg,
1798 msg->msg[0] |= 0xf; /* broadcast */
1799 msg->msg[1] = CEC_MSG_CDC_MESSAGE;
1800 /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
1801 msg->msg[4] = CEC_MSG_CDC_HEC_INQUIRE_STATE;
1802 msg->msg[5] = phys_addr1 >> 8;
1803 msg->msg[6] = phys_addr1 & 0xff;
1804 msg->msg[7] = phys_addr2 >> 8;
1805 msg->msg[8] = phys_addr2 & 0xff;
1806 msg->msg[9] = hec_set_state;
1807 if (phys_addr3 != CEC_PHYS_ADDR_INVALID) {
1808 msg->msg[msg->len++] = phys_addr3 >> 8;
1809 msg->msg[msg->len++] = phys_addr3 & 0xff;
1810 if (phys_addr4 != CEC_PHYS_ADDR_INVALID) {
1811 msg->msg[msg->len++] = phys_addr4 >> 8;
1812 msg->msg[msg->len++] = phys_addr4 & 0xff;
1813 if (phys_addr5 != CEC_PHYS_ADDR_INVALID) {
1814 msg->msg[msg->len++] = phys_addr5 >> 8;
1815 msg->msg[msg->len++] = phys_addr5 & 0xff;
1821 static inline void cec_ops_cdc_hec_set_state(const struct cec_msg *msg,
1825 __u8 *hec_set_state,
1830 *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1831 *phys_addr1 = (msg->msg[5] << 8) | msg->msg[6];
1832 *phys_addr2 = (msg->msg[7] << 8) | msg->msg[8];
1833 *hec_set_state = msg->msg[9];
1834 *phys_addr3 = *phys_addr4 = *phys_addr5 = CEC_PHYS_ADDR_INVALID;
1836 *phys_addr3 = (msg->msg[10] << 8) | msg->msg[11];
1838 *phys_addr4 = (msg->msg[12] << 8) | msg->msg[13];
1840 *phys_addr5 = (msg->msg[14] << 8) | msg->msg[15];
1843 static inline void cec_msg_cdc_hec_set_state_adjacent(struct cec_msg *msg,
1848 msg->msg[0] |= 0xf; /* broadcast */
1849 msg->msg[1] = CEC_MSG_CDC_MESSAGE;
1850 /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
1851 msg->msg[4] = CEC_MSG_CDC_HEC_SET_STATE_ADJACENT;
1852 msg->msg[5] = phys_addr1 >> 8;
1853 msg->msg[6] = phys_addr1 & 0xff;
1854 msg->msg[7] = hec_set_state;
1857 static inline void cec_ops_cdc_hec_set_state_adjacent(const struct cec_msg *msg,
1860 __u8 *hec_set_state)
1862 *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1863 *phys_addr1 = (msg->msg[5] << 8) | msg->msg[6];
1864 *hec_set_state = msg->msg[7];
1867 static inline void cec_msg_cdc_hec_request_deactivation(struct cec_msg *msg,
1873 msg->msg[0] |= 0xf; /* broadcast */
1874 msg->msg[1] = CEC_MSG_CDC_MESSAGE;
1875 /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
1876 msg->msg[4] = CEC_MSG_CDC_HEC_REQUEST_DEACTIVATION;
1877 msg->msg[5] = phys_addr1 >> 8;
1878 msg->msg[6] = phys_addr1 & 0xff;
1879 msg->msg[7] = phys_addr2 >> 8;
1880 msg->msg[8] = phys_addr2 & 0xff;
1881 msg->msg[9] = phys_addr3 >> 8;
1882 msg->msg[10] = phys_addr3 & 0xff;
1885 static inline void cec_ops_cdc_hec_request_deactivation(const struct cec_msg *msg,
1891 *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1892 *phys_addr1 = (msg->msg[5] << 8) | msg->msg[6];
1893 *phys_addr2 = (msg->msg[7] << 8) | msg->msg[8];
1894 *phys_addr3 = (msg->msg[9] << 8) | msg->msg[10];
1897 static inline void cec_msg_cdc_hec_notify_alive(struct cec_msg *msg)
1900 msg->msg[0] |= 0xf; /* broadcast */
1901 msg->msg[1] = CEC_MSG_CDC_MESSAGE;
1902 /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
1903 msg->msg[4] = CEC_MSG_CDC_HEC_NOTIFY_ALIVE;
1906 static inline void cec_ops_cdc_hec_notify_alive(const struct cec_msg *msg,
1909 *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1912 static inline void cec_msg_cdc_hec_discover(struct cec_msg *msg)
1915 msg->msg[0] |= 0xf; /* broadcast */
1916 msg->msg[1] = CEC_MSG_CDC_MESSAGE;
1917 /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
1918 msg->msg[4] = CEC_MSG_CDC_HEC_DISCOVER;
1921 static inline void cec_ops_cdc_hec_discover(const struct cec_msg *msg,
1924 *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1927 static inline void cec_msg_cdc_hpd_set_state(struct cec_msg *msg,
1932 msg->msg[0] |= 0xf; /* broadcast */
1933 msg->msg[1] = CEC_MSG_CDC_MESSAGE;
1934 /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
1935 msg->msg[4] = CEC_MSG_CDC_HPD_SET_STATE;
1936 msg->msg[5] = (input_port << 4) | hpd_state;
1939 static inline void cec_ops_cdc_hpd_set_state(const struct cec_msg *msg,
1944 *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1945 *input_port = msg->msg[5] >> 4;
1946 *hpd_state = msg->msg[5] & 0xf;
1949 static inline void cec_msg_cdc_hpd_report_state(struct cec_msg *msg,
1954 msg->msg[0] |= 0xf; /* broadcast */
1955 msg->msg[1] = CEC_MSG_CDC_MESSAGE;
1956 /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
1957 msg->msg[4] = CEC_MSG_CDC_HPD_REPORT_STATE;
1958 msg->msg[5] = (hpd_state << 4) | hpd_error;
1961 static inline void cec_ops_cdc_hpd_report_state(const struct cec_msg *msg,
1966 *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1967 *hpd_state = msg->msg[5] >> 4;
1968 *hpd_error = msg->msg[5] & 0xf;