~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/uapi/linux/cec-funcs.h

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /include/uapi/linux/cec-funcs.h (Version linux-6.12-rc7) and /include/uapi/linux/cec-funcs.h (Version linux-5.16.20)


  1 /* SPDX-License-Identifier: ((GPL-2.0 WITH Lin      1 /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */
  2 /*                                                  2 /*
  3  * cec - HDMI Consumer Electronics Control mes      3  * cec - HDMI Consumer Electronics Control message functions
  4  *                                                  4  *
  5  * Copyright 2016 Cisco Systems, Inc. and/or i      5  * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  6  */                                                 6  */
  7                                                     7 
  8 #ifndef _CEC_UAPI_FUNCS_H                           8 #ifndef _CEC_UAPI_FUNCS_H
  9 #define _CEC_UAPI_FUNCS_H                           9 #define _CEC_UAPI_FUNCS_H
 10                                                    10 
 11 #include <linux/cec.h>                             11 #include <linux/cec.h>
 12                                                    12 
 13 /* One Touch Play Feature */                       13 /* One Touch Play Feature */
 14 static inline void cec_msg_active_source(struc     14 static inline void cec_msg_active_source(struct cec_msg *msg, __u16 phys_addr)
 15 {                                                  15 {
 16         msg->len = 4;                              16         msg->len = 4;
 17         msg->msg[0] |= 0xf; /* broadcast */        17         msg->msg[0] |= 0xf; /* broadcast */
 18         msg->msg[1] = CEC_MSG_ACTIVE_SOURCE;       18         msg->msg[1] = CEC_MSG_ACTIVE_SOURCE;
 19         msg->msg[2] = phys_addr >> 8;              19         msg->msg[2] = phys_addr >> 8;
 20         msg->msg[3] = phys_addr & 0xff;            20         msg->msg[3] = phys_addr & 0xff;
 21 }                                                  21 }
 22                                                    22 
 23 static inline void cec_ops_active_source(const     23 static inline void cec_ops_active_source(const struct cec_msg *msg,
 24                                          __u16     24                                          __u16 *phys_addr)
 25 {                                                  25 {
 26         *phys_addr = (msg->msg[2] << 8) | msg-     26         *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
 27 }                                                  27 }
 28                                                    28 
 29 static inline void cec_msg_image_view_on(struc     29 static inline void cec_msg_image_view_on(struct cec_msg *msg)
 30 {                                                  30 {
 31         msg->len = 2;                              31         msg->len = 2;
 32         msg->msg[1] = CEC_MSG_IMAGE_VIEW_ON;       32         msg->msg[1] = CEC_MSG_IMAGE_VIEW_ON;
 33 }                                                  33 }
 34                                                    34 
 35 static inline void cec_msg_text_view_on(struct     35 static inline void cec_msg_text_view_on(struct cec_msg *msg)
 36 {                                                  36 {
 37         msg->len = 2;                              37         msg->len = 2;
 38         msg->msg[1] = CEC_MSG_TEXT_VIEW_ON;        38         msg->msg[1] = CEC_MSG_TEXT_VIEW_ON;
 39 }                                                  39 }
 40                                                    40 
 41                                                    41 
 42 /* Routing Control Feature */                      42 /* Routing Control Feature */
 43 static inline void cec_msg_inactive_source(str     43 static inline void cec_msg_inactive_source(struct cec_msg *msg,
 44                                            __u     44                                            __u16 phys_addr)
 45 {                                                  45 {
 46         msg->len = 4;                              46         msg->len = 4;
 47         msg->msg[1] = CEC_MSG_INACTIVE_SOURCE;     47         msg->msg[1] = CEC_MSG_INACTIVE_SOURCE;
 48         msg->msg[2] = phys_addr >> 8;              48         msg->msg[2] = phys_addr >> 8;
 49         msg->msg[3] = phys_addr & 0xff;            49         msg->msg[3] = phys_addr & 0xff;
 50 }                                                  50 }
 51                                                    51 
 52 static inline void cec_ops_inactive_source(con     52 static inline void cec_ops_inactive_source(const struct cec_msg *msg,
 53                                            __u     53                                            __u16 *phys_addr)
 54 {                                                  54 {
 55         *phys_addr = (msg->msg[2] << 8) | msg-     55         *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
 56 }                                                  56 }
 57                                                    57 
 58 static inline void cec_msg_request_active_sour     58 static inline void cec_msg_request_active_source(struct cec_msg *msg,
 59                                                    59                                                  int reply)
 60 {                                                  60 {
 61         msg->len = 2;                              61         msg->len = 2;
 62         msg->msg[0] |= 0xf; /* broadcast */        62         msg->msg[0] |= 0xf; /* broadcast */
 63         msg->msg[1] = CEC_MSG_REQUEST_ACTIVE_S     63         msg->msg[1] = CEC_MSG_REQUEST_ACTIVE_SOURCE;
 64         msg->reply = reply ? CEC_MSG_ACTIVE_SO     64         msg->reply = reply ? CEC_MSG_ACTIVE_SOURCE : 0;
 65 }                                                  65 }
 66                                                    66 
 67 static inline void cec_msg_routing_information     67 static inline void cec_msg_routing_information(struct cec_msg *msg,
 68                                                    68                                                __u16 phys_addr)
 69 {                                                  69 {
 70         msg->len = 4;                              70         msg->len = 4;
 71         msg->msg[0] |= 0xf; /* broadcast */        71         msg->msg[0] |= 0xf; /* broadcast */
 72         msg->msg[1] = CEC_MSG_ROUTING_INFORMAT     72         msg->msg[1] = CEC_MSG_ROUTING_INFORMATION;
 73         msg->msg[2] = phys_addr >> 8;              73         msg->msg[2] = phys_addr >> 8;
 74         msg->msg[3] = phys_addr & 0xff;            74         msg->msg[3] = phys_addr & 0xff;
 75 }                                                  75 }
 76                                                    76 
 77 static inline void cec_ops_routing_information     77 static inline void cec_ops_routing_information(const struct cec_msg *msg,
 78                                                    78                                                __u16 *phys_addr)
 79 {                                                  79 {
 80         *phys_addr = (msg->msg[2] << 8) | msg-     80         *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
 81 }                                                  81 }
 82                                                    82 
 83 static inline void cec_msg_routing_change(stru     83 static inline void cec_msg_routing_change(struct cec_msg *msg,
 84                                           int      84                                           int reply,
 85                                           __u1     85                                           __u16 orig_phys_addr,
 86                                           __u1     86                                           __u16 new_phys_addr)
 87 {                                                  87 {
 88         msg->len = 6;                              88         msg->len = 6;
 89         msg->msg[0] |= 0xf; /* broadcast */        89         msg->msg[0] |= 0xf; /* broadcast */
 90         msg->msg[1] = CEC_MSG_ROUTING_CHANGE;      90         msg->msg[1] = CEC_MSG_ROUTING_CHANGE;
 91         msg->msg[2] = orig_phys_addr >> 8;         91         msg->msg[2] = orig_phys_addr >> 8;
 92         msg->msg[3] = orig_phys_addr & 0xff;       92         msg->msg[3] = orig_phys_addr & 0xff;
 93         msg->msg[4] = new_phys_addr >> 8;          93         msg->msg[4] = new_phys_addr >> 8;
 94         msg->msg[5] = new_phys_addr & 0xff;        94         msg->msg[5] = new_phys_addr & 0xff;
 95         msg->reply = reply ? CEC_MSG_ROUTING_I     95         msg->reply = reply ? CEC_MSG_ROUTING_INFORMATION : 0;
 96 }                                                  96 }
 97                                                    97 
 98 static inline void cec_ops_routing_change(cons     98 static inline void cec_ops_routing_change(const struct cec_msg *msg,
 99                                           __u1     99                                           __u16 *orig_phys_addr,
100                                           __u1    100                                           __u16 *new_phys_addr)
101 {                                                 101 {
102         *orig_phys_addr = (msg->msg[2] << 8) |    102         *orig_phys_addr = (msg->msg[2] << 8) | msg->msg[3];
103         *new_phys_addr = (msg->msg[4] << 8) |     103         *new_phys_addr = (msg->msg[4] << 8) | msg->msg[5];
104 }                                                 104 }
105                                                   105 
106 static inline void cec_msg_set_stream_path(str    106 static inline void cec_msg_set_stream_path(struct cec_msg *msg, __u16 phys_addr)
107 {                                                 107 {
108         msg->len = 4;                             108         msg->len = 4;
109         msg->msg[0] |= 0xf; /* broadcast */       109         msg->msg[0] |= 0xf; /* broadcast */
110         msg->msg[1] = CEC_MSG_SET_STREAM_PATH;    110         msg->msg[1] = CEC_MSG_SET_STREAM_PATH;
111         msg->msg[2] = phys_addr >> 8;             111         msg->msg[2] = phys_addr >> 8;
112         msg->msg[3] = phys_addr & 0xff;           112         msg->msg[3] = phys_addr & 0xff;
113 }                                                 113 }
114                                                   114 
115 static inline void cec_ops_set_stream_path(con    115 static inline void cec_ops_set_stream_path(const struct cec_msg *msg,
116                                            __u    116                                            __u16 *phys_addr)
117 {                                                 117 {
118         *phys_addr = (msg->msg[2] << 8) | msg-    118         *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
119 }                                                 119 }
120                                                   120 
121                                                   121 
122 /* Standby Feature */                             122 /* Standby Feature */
123 static inline void cec_msg_standby(struct cec_    123 static inline void cec_msg_standby(struct cec_msg *msg)
124 {                                                 124 {
125         msg->len = 2;                             125         msg->len = 2;
126         msg->msg[1] = CEC_MSG_STANDBY;            126         msg->msg[1] = CEC_MSG_STANDBY;
127 }                                                 127 }
128                                                   128 
129                                                   129 
130 /* One Touch Record Feature */                    130 /* One Touch Record Feature */
131 static inline void cec_msg_record_off(struct c    131 static inline void cec_msg_record_off(struct cec_msg *msg, int reply)
132 {                                                 132 {
133         msg->len = 2;                             133         msg->len = 2;
134         msg->msg[1] = CEC_MSG_RECORD_OFF;         134         msg->msg[1] = CEC_MSG_RECORD_OFF;
135         msg->reply = reply ? CEC_MSG_RECORD_ST    135         msg->reply = reply ? CEC_MSG_RECORD_STATUS : 0;
136 }                                                 136 }
137                                                   137 
138 struct cec_op_arib_data {                         138 struct cec_op_arib_data {
139         __u16 transport_id;                       139         __u16 transport_id;
140         __u16 service_id;                         140         __u16 service_id;
141         __u16 orig_network_id;                    141         __u16 orig_network_id;
142 };                                                142 };
143                                                   143 
144 struct cec_op_atsc_data {                         144 struct cec_op_atsc_data {
145         __u16 transport_id;                       145         __u16 transport_id;
146         __u16 program_number;                     146         __u16 program_number;
147 };                                                147 };
148                                                   148 
149 struct cec_op_dvb_data {                          149 struct cec_op_dvb_data {
150         __u16 transport_id;                       150         __u16 transport_id;
151         __u16 service_id;                         151         __u16 service_id;
152         __u16 orig_network_id;                    152         __u16 orig_network_id;
153 };                                                153 };
154                                                   154 
155 struct cec_op_channel_data {                      155 struct cec_op_channel_data {
156         __u8 channel_number_fmt;                  156         __u8 channel_number_fmt;
157         __u16 major;                              157         __u16 major;
158         __u16 minor;                              158         __u16 minor;
159 };                                                159 };
160                                                   160 
161 struct cec_op_digital_service_id {                161 struct cec_op_digital_service_id {
162         __u8 service_id_method;                   162         __u8 service_id_method;
163         __u8 dig_bcast_system;                    163         __u8 dig_bcast_system;
164         union {                                   164         union {
165                 struct cec_op_arib_data arib;     165                 struct cec_op_arib_data arib;
166                 struct cec_op_atsc_data atsc;     166                 struct cec_op_atsc_data atsc;
167                 struct cec_op_dvb_data dvb;       167                 struct cec_op_dvb_data dvb;
168                 struct cec_op_channel_data cha    168                 struct cec_op_channel_data channel;
169         };                                        169         };
170 };                                                170 };
171                                                   171 
172 struct cec_op_record_src {                        172 struct cec_op_record_src {
173         __u8 type;                                173         __u8 type;
174         union {                                   174         union {
175                 struct cec_op_digital_service_    175                 struct cec_op_digital_service_id digital;
176                 struct {                          176                 struct {
177                         __u8 ana_bcast_type;      177                         __u8 ana_bcast_type;
178                         __u16 ana_freq;           178                         __u16 ana_freq;
179                         __u8 bcast_system;        179                         __u8 bcast_system;
180                 } analog;                         180                 } analog;
181                 struct {                          181                 struct {
182                         __u8 plug;                182                         __u8 plug;
183                 } ext_plug;                       183                 } ext_plug;
184                 struct {                          184                 struct {
185                         __u16 phys_addr;          185                         __u16 phys_addr;
186                 } ext_phys_addr;                  186                 } ext_phys_addr;
187         };                                        187         };
188 };                                                188 };
189                                                   189 
190 static inline void cec_set_digital_service_id(    190 static inline void cec_set_digital_service_id(__u8 *msg,
191               const struct cec_op_digital_serv    191               const struct cec_op_digital_service_id *digital)
192 {                                                 192 {
193         *msg++ = (digital->service_id_method <    193         *msg++ = (digital->service_id_method << 7) | digital->dig_bcast_system;
194         if (digital->service_id_method == CEC_    194         if (digital->service_id_method == CEC_OP_SERVICE_ID_METHOD_BY_CHANNEL) {
195                 *msg++ = (digital->channel.cha    195                 *msg++ = (digital->channel.channel_number_fmt << 2) |
196                          (digital->channel.maj    196                          (digital->channel.major >> 8);
197                 *msg++ = digital->channel.majo    197                 *msg++ = digital->channel.major & 0xff;
198                 *msg++ = digital->channel.mino    198                 *msg++ = digital->channel.minor >> 8;
199                 *msg++ = digital->channel.mino    199                 *msg++ = digital->channel.minor & 0xff;
200                 *msg++ = 0;                       200                 *msg++ = 0;
201                 *msg++ = 0;                       201                 *msg++ = 0;
202                 return;                           202                 return;
203         }                                         203         }
204         switch (digital->dig_bcast_system) {      204         switch (digital->dig_bcast_system) {
205         case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_A    205         case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_GEN:
206         case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_A    206         case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_CABLE:
207         case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_A    207         case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_SAT:
208         case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_A    208         case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_T:
209                 *msg++ = digital->atsc.transpo    209                 *msg++ = digital->atsc.transport_id >> 8;
210                 *msg++ = digital->atsc.transpo    210                 *msg++ = digital->atsc.transport_id & 0xff;
211                 *msg++ = digital->atsc.program    211                 *msg++ = digital->atsc.program_number >> 8;
212                 *msg++ = digital->atsc.program    212                 *msg++ = digital->atsc.program_number & 0xff;
213                 *msg++ = 0;                       213                 *msg++ = 0;
214                 *msg++ = 0;                       214                 *msg++ = 0;
215                 break;                            215                 break;
216         default:                                  216         default:
217                 *msg++ = digital->dvb.transpor    217                 *msg++ = digital->dvb.transport_id >> 8;
218                 *msg++ = digital->dvb.transpor    218                 *msg++ = digital->dvb.transport_id & 0xff;
219                 *msg++ = digital->dvb.service_    219                 *msg++ = digital->dvb.service_id >> 8;
220                 *msg++ = digital->dvb.service_    220                 *msg++ = digital->dvb.service_id & 0xff;
221                 *msg++ = digital->dvb.orig_net    221                 *msg++ = digital->dvb.orig_network_id >> 8;
222                 *msg++ = digital->dvb.orig_net    222                 *msg++ = digital->dvb.orig_network_id & 0xff;
223                 break;                            223                 break;
224         }                                         224         }
225 }                                                 225 }
226                                                   226 
227 static inline void cec_get_digital_service_id(    227 static inline void cec_get_digital_service_id(const __u8 *msg,
228               struct cec_op_digital_service_id    228               struct cec_op_digital_service_id *digital)
229 {                                                 229 {
230         digital->service_id_method = msg[0] >>    230         digital->service_id_method = msg[0] >> 7;
231         digital->dig_bcast_system = msg[0] & 0    231         digital->dig_bcast_system = msg[0] & 0x7f;
232         if (digital->service_id_method == CEC_    232         if (digital->service_id_method == CEC_OP_SERVICE_ID_METHOD_BY_CHANNEL) {
233                 digital->channel.channel_numbe    233                 digital->channel.channel_number_fmt = msg[1] >> 2;
234                 digital->channel.major = ((msg    234                 digital->channel.major = ((msg[1] & 3) << 6) | msg[2];
235                 digital->channel.minor = (msg[    235                 digital->channel.minor = (msg[3] << 8) | msg[4];
236                 return;                           236                 return;
237         }                                         237         }
238         digital->dvb.transport_id = (msg[1] <<    238         digital->dvb.transport_id = (msg[1] << 8) | msg[2];
239         digital->dvb.service_id = (msg[3] << 8    239         digital->dvb.service_id = (msg[3] << 8) | msg[4];
240         digital->dvb.orig_network_id = (msg[5]    240         digital->dvb.orig_network_id = (msg[5] << 8) | msg[6];
241 }                                                 241 }
242                                                   242 
243 static inline void cec_msg_record_on_own(struc    243 static inline void cec_msg_record_on_own(struct cec_msg *msg)
244 {                                                 244 {
245         msg->len = 3;                             245         msg->len = 3;
246         msg->msg[1] = CEC_MSG_RECORD_ON;          246         msg->msg[1] = CEC_MSG_RECORD_ON;
247         msg->msg[2] = CEC_OP_RECORD_SRC_OWN;      247         msg->msg[2] = CEC_OP_RECORD_SRC_OWN;
248 }                                                 248 }
249                                                   249 
250 static inline void cec_msg_record_on_digital(s    250 static inline void cec_msg_record_on_digital(struct cec_msg *msg,
251                              const struct cec_    251                              const struct cec_op_digital_service_id *digital)
252 {                                                 252 {
253         msg->len = 10;                            253         msg->len = 10;
254         msg->msg[1] = CEC_MSG_RECORD_ON;          254         msg->msg[1] = CEC_MSG_RECORD_ON;
255         msg->msg[2] = CEC_OP_RECORD_SRC_DIGITA    255         msg->msg[2] = CEC_OP_RECORD_SRC_DIGITAL;
256         cec_set_digital_service_id(msg->msg +     256         cec_set_digital_service_id(msg->msg + 3, digital);
257 }                                                 257 }
258                                                   258 
259 static inline void cec_msg_record_on_analog(st    259 static inline void cec_msg_record_on_analog(struct cec_msg *msg,
260                                             __    260                                             __u8 ana_bcast_type,
261                                             __    261                                             __u16 ana_freq,
262                                             __    262                                             __u8 bcast_system)
263 {                                                 263 {
264         msg->len = 7;                             264         msg->len = 7;
265         msg->msg[1] = CEC_MSG_RECORD_ON;          265         msg->msg[1] = CEC_MSG_RECORD_ON;
266         msg->msg[2] = CEC_OP_RECORD_SRC_ANALOG    266         msg->msg[2] = CEC_OP_RECORD_SRC_ANALOG;
267         msg->msg[3] = ana_bcast_type;             267         msg->msg[3] = ana_bcast_type;
268         msg->msg[4] = ana_freq >> 8;              268         msg->msg[4] = ana_freq >> 8;
269         msg->msg[5] = ana_freq & 0xff;            269         msg->msg[5] = ana_freq & 0xff;
270         msg->msg[6] = bcast_system;               270         msg->msg[6] = bcast_system;
271 }                                                 271 }
272                                                   272 
273 static inline void cec_msg_record_on_plug(stru    273 static inline void cec_msg_record_on_plug(struct cec_msg *msg,
274                                           __u8    274                                           __u8 plug)
275 {                                                 275 {
276         msg->len = 4;                             276         msg->len = 4;
277         msg->msg[1] = CEC_MSG_RECORD_ON;          277         msg->msg[1] = CEC_MSG_RECORD_ON;
278         msg->msg[2] = CEC_OP_RECORD_SRC_EXT_PL    278         msg->msg[2] = CEC_OP_RECORD_SRC_EXT_PLUG;
279         msg->msg[3] = plug;                       279         msg->msg[3] = plug;
280 }                                                 280 }
281                                                   281 
282 static inline void cec_msg_record_on_phys_addr    282 static inline void cec_msg_record_on_phys_addr(struct cec_msg *msg,
283                                                   283                                                __u16 phys_addr)
284 {                                                 284 {
285         msg->len = 5;                             285         msg->len = 5;
286         msg->msg[1] = CEC_MSG_RECORD_ON;          286         msg->msg[1] = CEC_MSG_RECORD_ON;
287         msg->msg[2] = CEC_OP_RECORD_SRC_EXT_PH    287         msg->msg[2] = CEC_OP_RECORD_SRC_EXT_PHYS_ADDR;
288         msg->msg[3] = phys_addr >> 8;             288         msg->msg[3] = phys_addr >> 8;
289         msg->msg[4] = phys_addr & 0xff;           289         msg->msg[4] = phys_addr & 0xff;
290 }                                                 290 }
291                                                   291 
292 static inline void cec_msg_record_on(struct ce    292 static inline void cec_msg_record_on(struct cec_msg *msg,
293                                      int reply    293                                      int reply,
294                                      const str    294                                      const struct cec_op_record_src *rec_src)
295 {                                                 295 {
296         switch (rec_src->type) {                  296         switch (rec_src->type) {
297         case CEC_OP_RECORD_SRC_OWN:               297         case CEC_OP_RECORD_SRC_OWN:
298                 cec_msg_record_on_own(msg);       298                 cec_msg_record_on_own(msg);
299                 break;                            299                 break;
300         case CEC_OP_RECORD_SRC_DIGITAL:           300         case CEC_OP_RECORD_SRC_DIGITAL:
301                 cec_msg_record_on_digital(msg,    301                 cec_msg_record_on_digital(msg, &rec_src->digital);
302                 break;                            302                 break;
303         case CEC_OP_RECORD_SRC_ANALOG:            303         case CEC_OP_RECORD_SRC_ANALOG:
304                 cec_msg_record_on_analog(msg,     304                 cec_msg_record_on_analog(msg,
305                                          rec_s    305                                          rec_src->analog.ana_bcast_type,
306                                          rec_s    306                                          rec_src->analog.ana_freq,
307                                          rec_s    307                                          rec_src->analog.bcast_system);
308                 break;                            308                 break;
309         case CEC_OP_RECORD_SRC_EXT_PLUG:          309         case CEC_OP_RECORD_SRC_EXT_PLUG:
310                 cec_msg_record_on_plug(msg, re    310                 cec_msg_record_on_plug(msg, rec_src->ext_plug.plug);
311                 break;                            311                 break;
312         case CEC_OP_RECORD_SRC_EXT_PHYS_ADDR:     312         case CEC_OP_RECORD_SRC_EXT_PHYS_ADDR:
313                 cec_msg_record_on_phys_addr(ms    313                 cec_msg_record_on_phys_addr(msg,
314                                             re    314                                             rec_src->ext_phys_addr.phys_addr);
315                 break;                            315                 break;
316         }                                         316         }
317         msg->reply = reply ? CEC_MSG_RECORD_ST    317         msg->reply = reply ? CEC_MSG_RECORD_STATUS : 0;
318 }                                                 318 }
319                                                   319 
320 static inline void cec_ops_record_on(const str    320 static inline void cec_ops_record_on(const struct cec_msg *msg,
321                                      struct ce    321                                      struct cec_op_record_src *rec_src)
322 {                                                 322 {
323         rec_src->type = msg->msg[2];              323         rec_src->type = msg->msg[2];
324         switch (rec_src->type) {                  324         switch (rec_src->type) {
325         case CEC_OP_RECORD_SRC_OWN:               325         case CEC_OP_RECORD_SRC_OWN:
326                 break;                            326                 break;
327         case CEC_OP_RECORD_SRC_DIGITAL:           327         case CEC_OP_RECORD_SRC_DIGITAL:
328                 cec_get_digital_service_id(msg    328                 cec_get_digital_service_id(msg->msg + 3, &rec_src->digital);
329                 break;                            329                 break;
330         case CEC_OP_RECORD_SRC_ANALOG:            330         case CEC_OP_RECORD_SRC_ANALOG:
331                 rec_src->analog.ana_bcast_type    331                 rec_src->analog.ana_bcast_type = msg->msg[3];
332                 rec_src->analog.ana_freq =        332                 rec_src->analog.ana_freq =
333                         (msg->msg[4] << 8) | m    333                         (msg->msg[4] << 8) | msg->msg[5];
334                 rec_src->analog.bcast_system =    334                 rec_src->analog.bcast_system = msg->msg[6];
335                 break;                            335                 break;
336         case CEC_OP_RECORD_SRC_EXT_PLUG:          336         case CEC_OP_RECORD_SRC_EXT_PLUG:
337                 rec_src->ext_plug.plug = msg->    337                 rec_src->ext_plug.plug = msg->msg[3];
338                 break;                            338                 break;
339         case CEC_OP_RECORD_SRC_EXT_PHYS_ADDR:     339         case CEC_OP_RECORD_SRC_EXT_PHYS_ADDR:
340                 rec_src->ext_phys_addr.phys_ad    340                 rec_src->ext_phys_addr.phys_addr =
341                         (msg->msg[3] << 8) | m    341                         (msg->msg[3] << 8) | msg->msg[4];
342                 break;                            342                 break;
343         }                                         343         }
344 }                                                 344 }
345                                                   345 
346 static inline void cec_msg_record_status(struc    346 static inline void cec_msg_record_status(struct cec_msg *msg, __u8 rec_status)
347 {                                                 347 {
348         msg->len = 3;                             348         msg->len = 3;
349         msg->msg[1] = CEC_MSG_RECORD_STATUS;      349         msg->msg[1] = CEC_MSG_RECORD_STATUS;
350         msg->msg[2] = rec_status;                 350         msg->msg[2] = rec_status;
351 }                                                 351 }
352                                                   352 
353 static inline void cec_ops_record_status(const    353 static inline void cec_ops_record_status(const struct cec_msg *msg,
354                                          __u8     354                                          __u8 *rec_status)
355 {                                                 355 {
356         *rec_status = msg->msg[2];                356         *rec_status = msg->msg[2];
357 }                                                 357 }
358                                                   358 
359 static inline void cec_msg_record_tv_screen(st    359 static inline void cec_msg_record_tv_screen(struct cec_msg *msg,
360                                             in    360                                             int reply)
361 {                                                 361 {
362         msg->len = 2;                             362         msg->len = 2;
363         msg->msg[1] = CEC_MSG_RECORD_TV_SCREEN    363         msg->msg[1] = CEC_MSG_RECORD_TV_SCREEN;
364         msg->reply = reply ? CEC_MSG_RECORD_ON    364         msg->reply = reply ? CEC_MSG_RECORD_ON : 0;
365 }                                                 365 }
366                                                   366 
367                                                   367 
368 /* Timer Programming Feature */                   368 /* Timer Programming Feature */
369 static inline void cec_msg_timer_status(struct    369 static inline void cec_msg_timer_status(struct cec_msg *msg,
370                                         __u8 t    370                                         __u8 timer_overlap_warning,
371                                         __u8 m    371                                         __u8 media_info,
372                                         __u8 p    372                                         __u8 prog_info,
373                                         __u8 p    373                                         __u8 prog_error,
374                                         __u8 d    374                                         __u8 duration_hr,
375                                         __u8 d    375                                         __u8 duration_min)
376 {                                                 376 {
377         msg->len = 3;                             377         msg->len = 3;
378         msg->msg[1] = CEC_MSG_TIMER_STATUS;       378         msg->msg[1] = CEC_MSG_TIMER_STATUS;
379         msg->msg[2] = (timer_overlap_warning <    379         msg->msg[2] = (timer_overlap_warning << 7) |
380                 (media_info << 5) |               380                 (media_info << 5) |
381                 (prog_info ? 0x10 : 0) |          381                 (prog_info ? 0x10 : 0) |
382                 (prog_info ? prog_info : prog_    382                 (prog_info ? prog_info : prog_error);
383         if (prog_info == CEC_OP_PROG_INFO_NOT_    383         if (prog_info == CEC_OP_PROG_INFO_NOT_ENOUGH_SPACE ||
384             prog_info == CEC_OP_PROG_INFO_MIGH    384             prog_info == CEC_OP_PROG_INFO_MIGHT_NOT_BE_ENOUGH_SPACE ||
385             prog_error == CEC_OP_PROG_ERROR_DU    385             prog_error == CEC_OP_PROG_ERROR_DUPLICATE) {
386                 msg->len += 2;                    386                 msg->len += 2;
387                 msg->msg[3] = ((duration_hr /     387                 msg->msg[3] = ((duration_hr / 10) << 4) | (duration_hr % 10);
388                 msg->msg[4] = ((duration_min /    388                 msg->msg[4] = ((duration_min / 10) << 4) | (duration_min % 10);
389         }                                         389         }
390 }                                                 390 }
391                                                   391 
392 static inline void cec_ops_timer_status(const     392 static inline void cec_ops_timer_status(const struct cec_msg *msg,
393                                         __u8 *    393                                         __u8 *timer_overlap_warning,
394                                         __u8 *    394                                         __u8 *media_info,
395                                         __u8 *    395                                         __u8 *prog_info,
396                                         __u8 *    396                                         __u8 *prog_error,
397                                         __u8 *    397                                         __u8 *duration_hr,
398                                         __u8 *    398                                         __u8 *duration_min)
399 {                                                 399 {
400         *timer_overlap_warning = msg->msg[2] >    400         *timer_overlap_warning = msg->msg[2] >> 7;
401         *media_info = (msg->msg[2] >> 5) & 3;     401         *media_info = (msg->msg[2] >> 5) & 3;
402         if (msg->msg[2] & 0x10) {                 402         if (msg->msg[2] & 0x10) {
403                 *prog_info = msg->msg[2] & 0xf    403                 *prog_info = msg->msg[2] & 0xf;
404                 *prog_error = 0;                  404                 *prog_error = 0;
405         } else {                                  405         } else {
406                 *prog_info = 0;                   406                 *prog_info = 0;
407                 *prog_error = msg->msg[2] & 0x    407                 *prog_error = msg->msg[2] & 0xf;
408         }                                         408         }
409         if (*prog_info == CEC_OP_PROG_INFO_NOT    409         if (*prog_info == CEC_OP_PROG_INFO_NOT_ENOUGH_SPACE ||
410             *prog_info == CEC_OP_PROG_INFO_MIG    410             *prog_info == CEC_OP_PROG_INFO_MIGHT_NOT_BE_ENOUGH_SPACE ||
411             *prog_error == CEC_OP_PROG_ERROR_D    411             *prog_error == CEC_OP_PROG_ERROR_DUPLICATE) {
412                 *duration_hr = (msg->msg[3] >>    412                 *duration_hr = (msg->msg[3] >> 4) * 10 + (msg->msg[3] & 0xf);
413                 *duration_min = (msg->msg[4] >    413                 *duration_min = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
414         } else {                                  414         } else {
415                 *duration_hr = *duration_min =    415                 *duration_hr = *duration_min = 0;
416         }                                         416         }
417 }                                                 417 }
418                                                   418 
419 static inline void cec_msg_timer_cleared_statu    419 static inline void cec_msg_timer_cleared_status(struct cec_msg *msg,
420                                                   420                                                 __u8 timer_cleared_status)
421 {                                                 421 {
422         msg->len = 3;                             422         msg->len = 3;
423         msg->msg[1] = CEC_MSG_TIMER_CLEARED_ST    423         msg->msg[1] = CEC_MSG_TIMER_CLEARED_STATUS;
424         msg->msg[2] = timer_cleared_status;       424         msg->msg[2] = timer_cleared_status;
425 }                                                 425 }
426                                                   426 
427 static inline void cec_ops_timer_cleared_statu    427 static inline void cec_ops_timer_cleared_status(const struct cec_msg *msg,
428                                                   428                                                 __u8 *timer_cleared_status)
429 {                                                 429 {
430         *timer_cleared_status = msg->msg[2];      430         *timer_cleared_status = msg->msg[2];
431 }                                                 431 }
432                                                   432 
433 static inline void cec_msg_clear_analogue_time    433 static inline void cec_msg_clear_analogue_timer(struct cec_msg *msg,
434                                                   434                                                 int reply,
435                                                   435                                                 __u8 day,
436                                                   436                                                 __u8 month,
437                                                   437                                                 __u8 start_hr,
438                                                   438                                                 __u8 start_min,
439                                                   439                                                 __u8 duration_hr,
440                                                   440                                                 __u8 duration_min,
441                                                   441                                                 __u8 recording_seq,
442                                                   442                                                 __u8 ana_bcast_type,
443                                                   443                                                 __u16 ana_freq,
444                                                   444                                                 __u8 bcast_system)
445 {                                                 445 {
446         msg->len = 13;                            446         msg->len = 13;
447         msg->msg[1] = CEC_MSG_CLEAR_ANALOGUE_T    447         msg->msg[1] = CEC_MSG_CLEAR_ANALOGUE_TIMER;
448         msg->msg[2] = day;                        448         msg->msg[2] = day;
449         msg->msg[3] = month;                      449         msg->msg[3] = month;
450         /* Hours and minutes are in BCD format    450         /* Hours and minutes are in BCD format */
451         msg->msg[4] = ((start_hr / 10) << 4) |    451         msg->msg[4] = ((start_hr / 10) << 4) | (start_hr % 10);
452         msg->msg[5] = ((start_min / 10) << 4)     452         msg->msg[5] = ((start_min / 10) << 4) | (start_min % 10);
453         msg->msg[6] = ((duration_hr / 10) << 4    453         msg->msg[6] = ((duration_hr / 10) << 4) | (duration_hr % 10);
454         msg->msg[7] = ((duration_min / 10) <<     454         msg->msg[7] = ((duration_min / 10) << 4) | (duration_min % 10);
455         msg->msg[8] = recording_seq;              455         msg->msg[8] = recording_seq;
456         msg->msg[9] = ana_bcast_type;             456         msg->msg[9] = ana_bcast_type;
457         msg->msg[10] = ana_freq >> 8;             457         msg->msg[10] = ana_freq >> 8;
458         msg->msg[11] = ana_freq & 0xff;           458         msg->msg[11] = ana_freq & 0xff;
459         msg->msg[12] = bcast_system;              459         msg->msg[12] = bcast_system;
460         msg->reply = reply ? CEC_MSG_TIMER_CLE    460         msg->reply = reply ? CEC_MSG_TIMER_CLEARED_STATUS : 0;
461 }                                                 461 }
462                                                   462 
463 static inline void cec_ops_clear_analogue_time    463 static inline void cec_ops_clear_analogue_timer(const struct cec_msg *msg,
464                                                   464                                                 __u8 *day,
465                                                   465                                                 __u8 *month,
466                                                   466                                                 __u8 *start_hr,
467                                                   467                                                 __u8 *start_min,
468                                                   468                                                 __u8 *duration_hr,
469                                                   469                                                 __u8 *duration_min,
470                                                   470                                                 __u8 *recording_seq,
471                                                   471                                                 __u8 *ana_bcast_type,
472                                                   472                                                 __u16 *ana_freq,
473                                                   473                                                 __u8 *bcast_system)
474 {                                                 474 {
475         *day = msg->msg[2];                       475         *day = msg->msg[2];
476         *month = msg->msg[3];                     476         *month = msg->msg[3];
477         /* Hours and minutes are in BCD format    477         /* Hours and minutes are in BCD format */
478         *start_hr = (msg->msg[4] >> 4) * 10 +     478         *start_hr = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
479         *start_min = (msg->msg[5] >> 4) * 10 +    479         *start_min = (msg->msg[5] >> 4) * 10 + (msg->msg[5] & 0xf);
480         *duration_hr = (msg->msg[6] >> 4) * 10    480         *duration_hr = (msg->msg[6] >> 4) * 10 + (msg->msg[6] & 0xf);
481         *duration_min = (msg->msg[7] >> 4) * 1    481         *duration_min = (msg->msg[7] >> 4) * 10 + (msg->msg[7] & 0xf);
482         *recording_seq = msg->msg[8];             482         *recording_seq = msg->msg[8];
483         *ana_bcast_type = msg->msg[9];            483         *ana_bcast_type = msg->msg[9];
484         *ana_freq = (msg->msg[10] << 8) | msg-    484         *ana_freq = (msg->msg[10] << 8) | msg->msg[11];
485         *bcast_system = msg->msg[12];             485         *bcast_system = msg->msg[12];
486 }                                                 486 }
487                                                   487 
488 static inline void cec_msg_clear_digital_timer    488 static inline void cec_msg_clear_digital_timer(struct cec_msg *msg,
489                                 int reply,        489                                 int reply,
490                                 __u8 day,         490                                 __u8 day,
491                                 __u8 month,       491                                 __u8 month,
492                                 __u8 start_hr,    492                                 __u8 start_hr,
493                                 __u8 start_min    493                                 __u8 start_min,
494                                 __u8 duration_    494                                 __u8 duration_hr,
495                                 __u8 duration_    495                                 __u8 duration_min,
496                                 __u8 recording    496                                 __u8 recording_seq,
497                                 const struct c    497                                 const struct cec_op_digital_service_id *digital)
498 {                                                 498 {
499         msg->len = 16;                            499         msg->len = 16;
500         msg->reply = reply ? CEC_MSG_TIMER_CLE    500         msg->reply = reply ? CEC_MSG_TIMER_CLEARED_STATUS : 0;
501         msg->msg[1] = CEC_MSG_CLEAR_DIGITAL_TI    501         msg->msg[1] = CEC_MSG_CLEAR_DIGITAL_TIMER;
502         msg->msg[2] = day;                        502         msg->msg[2] = day;
503         msg->msg[3] = month;                      503         msg->msg[3] = month;
504         /* Hours and minutes are in BCD format    504         /* Hours and minutes are in BCD format */
505         msg->msg[4] = ((start_hr / 10) << 4) |    505         msg->msg[4] = ((start_hr / 10) << 4) | (start_hr % 10);
506         msg->msg[5] = ((start_min / 10) << 4)     506         msg->msg[5] = ((start_min / 10) << 4) | (start_min % 10);
507         msg->msg[6] = ((duration_hr / 10) << 4    507         msg->msg[6] = ((duration_hr / 10) << 4) | (duration_hr % 10);
508         msg->msg[7] = ((duration_min / 10) <<     508         msg->msg[7] = ((duration_min / 10) << 4) | (duration_min % 10);
509         msg->msg[8] = recording_seq;              509         msg->msg[8] = recording_seq;
510         cec_set_digital_service_id(msg->msg +     510         cec_set_digital_service_id(msg->msg + 9, digital);
511 }                                                 511 }
512                                                   512 
513 static inline void cec_ops_clear_digital_timer    513 static inline void cec_ops_clear_digital_timer(const struct cec_msg *msg,
514                                 __u8 *day,        514                                 __u8 *day,
515                                 __u8 *month,      515                                 __u8 *month,
516                                 __u8 *start_hr    516                                 __u8 *start_hr,
517                                 __u8 *start_mi    517                                 __u8 *start_min,
518                                 __u8 *duration    518                                 __u8 *duration_hr,
519                                 __u8 *duration    519                                 __u8 *duration_min,
520                                 __u8 *recordin    520                                 __u8 *recording_seq,
521                                 struct cec_op_    521                                 struct cec_op_digital_service_id *digital)
522 {                                                 522 {
523         *day = msg->msg[2];                       523         *day = msg->msg[2];
524         *month = msg->msg[3];                     524         *month = msg->msg[3];
525         /* Hours and minutes are in BCD format    525         /* Hours and minutes are in BCD format */
526         *start_hr = (msg->msg[4] >> 4) * 10 +     526         *start_hr = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
527         *start_min = (msg->msg[5] >> 4) * 10 +    527         *start_min = (msg->msg[5] >> 4) * 10 + (msg->msg[5] & 0xf);
528         *duration_hr = (msg->msg[6] >> 4) * 10    528         *duration_hr = (msg->msg[6] >> 4) * 10 + (msg->msg[6] & 0xf);
529         *duration_min = (msg->msg[7] >> 4) * 1    529         *duration_min = (msg->msg[7] >> 4) * 10 + (msg->msg[7] & 0xf);
530         *recording_seq = msg->msg[8];             530         *recording_seq = msg->msg[8];
531         cec_get_digital_service_id(msg->msg +     531         cec_get_digital_service_id(msg->msg + 9, digital);
532 }                                                 532 }
533                                                   533 
534 static inline void cec_msg_clear_ext_timer(str    534 static inline void cec_msg_clear_ext_timer(struct cec_msg *msg,
535                                            int    535                                            int reply,
536                                            __u    536                                            __u8 day,
537                                            __u    537                                            __u8 month,
538                                            __u    538                                            __u8 start_hr,
539                                            __u    539                                            __u8 start_min,
540                                            __u    540                                            __u8 duration_hr,
541                                            __u    541                                            __u8 duration_min,
542                                            __u    542                                            __u8 recording_seq,
543                                            __u    543                                            __u8 ext_src_spec,
544                                            __u    544                                            __u8 plug,
545                                            __u    545                                            __u16 phys_addr)
546 {                                                 546 {
547         msg->len = 13;                            547         msg->len = 13;
548         msg->msg[1] = CEC_MSG_CLEAR_EXT_TIMER;    548         msg->msg[1] = CEC_MSG_CLEAR_EXT_TIMER;
549         msg->msg[2] = day;                        549         msg->msg[2] = day;
550         msg->msg[3] = month;                      550         msg->msg[3] = month;
551         /* Hours and minutes are in BCD format    551         /* Hours and minutes are in BCD format */
552         msg->msg[4] = ((start_hr / 10) << 4) |    552         msg->msg[4] = ((start_hr / 10) << 4) | (start_hr % 10);
553         msg->msg[5] = ((start_min / 10) << 4)     553         msg->msg[5] = ((start_min / 10) << 4) | (start_min % 10);
554         msg->msg[6] = ((duration_hr / 10) << 4    554         msg->msg[6] = ((duration_hr / 10) << 4) | (duration_hr % 10);
555         msg->msg[7] = ((duration_min / 10) <<     555         msg->msg[7] = ((duration_min / 10) << 4) | (duration_min % 10);
556         msg->msg[8] = recording_seq;              556         msg->msg[8] = recording_seq;
557         msg->msg[9] = ext_src_spec;               557         msg->msg[9] = ext_src_spec;
558         msg->msg[10] = plug;                      558         msg->msg[10] = plug;
559         msg->msg[11] = phys_addr >> 8;            559         msg->msg[11] = phys_addr >> 8;
560         msg->msg[12] = phys_addr & 0xff;          560         msg->msg[12] = phys_addr & 0xff;
561         msg->reply = reply ? CEC_MSG_TIMER_CLE    561         msg->reply = reply ? CEC_MSG_TIMER_CLEARED_STATUS : 0;
562 }                                                 562 }
563                                                   563 
564 static inline void cec_ops_clear_ext_timer(con    564 static inline void cec_ops_clear_ext_timer(const struct cec_msg *msg,
565                                            __u    565                                            __u8 *day,
566                                            __u    566                                            __u8 *month,
567                                            __u    567                                            __u8 *start_hr,
568                                            __u    568                                            __u8 *start_min,
569                                            __u    569                                            __u8 *duration_hr,
570                                            __u    570                                            __u8 *duration_min,
571                                            __u    571                                            __u8 *recording_seq,
572                                            __u    572                                            __u8 *ext_src_spec,
573                                            __u    573                                            __u8 *plug,
574                                            __u    574                                            __u16 *phys_addr)
575 {                                                 575 {
576         *day = msg->msg[2];                       576         *day = msg->msg[2];
577         *month = msg->msg[3];                     577         *month = msg->msg[3];
578         /* Hours and minutes are in BCD format    578         /* Hours and minutes are in BCD format */
579         *start_hr = (msg->msg[4] >> 4) * 10 +     579         *start_hr = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
580         *start_min = (msg->msg[5] >> 4) * 10 +    580         *start_min = (msg->msg[5] >> 4) * 10 + (msg->msg[5] & 0xf);
581         *duration_hr = (msg->msg[6] >> 4) * 10    581         *duration_hr = (msg->msg[6] >> 4) * 10 + (msg->msg[6] & 0xf);
582         *duration_min = (msg->msg[7] >> 4) * 1    582         *duration_min = (msg->msg[7] >> 4) * 10 + (msg->msg[7] & 0xf);
583         *recording_seq = msg->msg[8];             583         *recording_seq = msg->msg[8];
584         *ext_src_spec = msg->msg[9];              584         *ext_src_spec = msg->msg[9];
585         *plug = msg->msg[10];                     585         *plug = msg->msg[10];
586         *phys_addr = (msg->msg[11] << 8) | msg    586         *phys_addr = (msg->msg[11] << 8) | msg->msg[12];
587 }                                                 587 }
588                                                   588 
589 static inline void cec_msg_set_analogue_timer(    589 static inline void cec_msg_set_analogue_timer(struct cec_msg *msg,
590                                                   590                                               int reply,
591                                                   591                                               __u8 day,
592                                                   592                                               __u8 month,
593                                                   593                                               __u8 start_hr,
594                                                   594                                               __u8 start_min,
595                                                   595                                               __u8 duration_hr,
596                                                   596                                               __u8 duration_min,
597                                                   597                                               __u8 recording_seq,
598                                                   598                                               __u8 ana_bcast_type,
599                                                   599                                               __u16 ana_freq,
600                                                   600                                               __u8 bcast_system)
601 {                                                 601 {
602         msg->len = 13;                            602         msg->len = 13;
603         msg->msg[1] = CEC_MSG_SET_ANALOGUE_TIM    603         msg->msg[1] = CEC_MSG_SET_ANALOGUE_TIMER;
604         msg->msg[2] = day;                        604         msg->msg[2] = day;
605         msg->msg[3] = month;                      605         msg->msg[3] = month;
606         /* Hours and minutes are in BCD format    606         /* Hours and minutes are in BCD format */
607         msg->msg[4] = ((start_hr / 10) << 4) |    607         msg->msg[4] = ((start_hr / 10) << 4) | (start_hr % 10);
608         msg->msg[5] = ((start_min / 10) << 4)     608         msg->msg[5] = ((start_min / 10) << 4) | (start_min % 10);
609         msg->msg[6] = ((duration_hr / 10) << 4    609         msg->msg[6] = ((duration_hr / 10) << 4) | (duration_hr % 10);
610         msg->msg[7] = ((duration_min / 10) <<     610         msg->msg[7] = ((duration_min / 10) << 4) | (duration_min % 10);
611         msg->msg[8] = recording_seq;              611         msg->msg[8] = recording_seq;
612         msg->msg[9] = ana_bcast_type;             612         msg->msg[9] = ana_bcast_type;
613         msg->msg[10] = ana_freq >> 8;             613         msg->msg[10] = ana_freq >> 8;
614         msg->msg[11] = ana_freq & 0xff;           614         msg->msg[11] = ana_freq & 0xff;
615         msg->msg[12] = bcast_system;              615         msg->msg[12] = bcast_system;
616         msg->reply = reply ? CEC_MSG_TIMER_STA    616         msg->reply = reply ? CEC_MSG_TIMER_STATUS : 0;
617 }                                                 617 }
618                                                   618 
619 static inline void cec_ops_set_analogue_timer(    619 static inline void cec_ops_set_analogue_timer(const struct cec_msg *msg,
620                                                   620                                               __u8 *day,
621                                                   621                                               __u8 *month,
622                                                   622                                               __u8 *start_hr,
623                                                   623                                               __u8 *start_min,
624                                                   624                                               __u8 *duration_hr,
625                                                   625                                               __u8 *duration_min,
626                                                   626                                               __u8 *recording_seq,
627                                                   627                                               __u8 *ana_bcast_type,
628                                                   628                                               __u16 *ana_freq,
629                                                   629                                               __u8 *bcast_system)
630 {                                                 630 {
631         *day = msg->msg[2];                       631         *day = msg->msg[2];
632         *month = msg->msg[3];                     632         *month = msg->msg[3];
633         /* Hours and minutes are in BCD format    633         /* Hours and minutes are in BCD format */
634         *start_hr = (msg->msg[4] >> 4) * 10 +     634         *start_hr = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
635         *start_min = (msg->msg[5] >> 4) * 10 +    635         *start_min = (msg->msg[5] >> 4) * 10 + (msg->msg[5] & 0xf);
636         *duration_hr = (msg->msg[6] >> 4) * 10    636         *duration_hr = (msg->msg[6] >> 4) * 10 + (msg->msg[6] & 0xf);
637         *duration_min = (msg->msg[7] >> 4) * 1    637         *duration_min = (msg->msg[7] >> 4) * 10 + (msg->msg[7] & 0xf);
638         *recording_seq = msg->msg[8];             638         *recording_seq = msg->msg[8];
639         *ana_bcast_type = msg->msg[9];            639         *ana_bcast_type = msg->msg[9];
640         *ana_freq = (msg->msg[10] << 8) | msg-    640         *ana_freq = (msg->msg[10] << 8) | msg->msg[11];
641         *bcast_system = msg->msg[12];             641         *bcast_system = msg->msg[12];
642 }                                                 642 }
643                                                   643 
644 static inline void cec_msg_set_digital_timer(s    644 static inline void cec_msg_set_digital_timer(struct cec_msg *msg,
645                         int reply,                645                         int reply,
646                         __u8 day,                 646                         __u8 day,
647                         __u8 month,               647                         __u8 month,
648                         __u8 start_hr,            648                         __u8 start_hr,
649                         __u8 start_min,           649                         __u8 start_min,
650                         __u8 duration_hr,         650                         __u8 duration_hr,
651                         __u8 duration_min,        651                         __u8 duration_min,
652                         __u8 recording_seq,       652                         __u8 recording_seq,
653                         const struct cec_op_di    653                         const struct cec_op_digital_service_id *digital)
654 {                                                 654 {
655         msg->len = 16;                            655         msg->len = 16;
656         msg->reply = reply ? CEC_MSG_TIMER_STA    656         msg->reply = reply ? CEC_MSG_TIMER_STATUS : 0;
657         msg->msg[1] = CEC_MSG_SET_DIGITAL_TIME    657         msg->msg[1] = CEC_MSG_SET_DIGITAL_TIMER;
658         msg->msg[2] = day;                        658         msg->msg[2] = day;
659         msg->msg[3] = month;                      659         msg->msg[3] = month;
660         /* Hours and minutes are in BCD format    660         /* Hours and minutes are in BCD format */
661         msg->msg[4] = ((start_hr / 10) << 4) |    661         msg->msg[4] = ((start_hr / 10) << 4) | (start_hr % 10);
662         msg->msg[5] = ((start_min / 10) << 4)     662         msg->msg[5] = ((start_min / 10) << 4) | (start_min % 10);
663         msg->msg[6] = ((duration_hr / 10) << 4    663         msg->msg[6] = ((duration_hr / 10) << 4) | (duration_hr % 10);
664         msg->msg[7] = ((duration_min / 10) <<     664         msg->msg[7] = ((duration_min / 10) << 4) | (duration_min % 10);
665         msg->msg[8] = recording_seq;              665         msg->msg[8] = recording_seq;
666         cec_set_digital_service_id(msg->msg +     666         cec_set_digital_service_id(msg->msg + 9, digital);
667 }                                                 667 }
668                                                   668 
669 static inline void cec_ops_set_digital_timer(c    669 static inline void cec_ops_set_digital_timer(const struct cec_msg *msg,
670                         __u8 *day,                670                         __u8 *day,
671                         __u8 *month,              671                         __u8 *month,
672                         __u8 *start_hr,           672                         __u8 *start_hr,
673                         __u8 *start_min,          673                         __u8 *start_min,
674                         __u8 *duration_hr,        674                         __u8 *duration_hr,
675                         __u8 *duration_min,       675                         __u8 *duration_min,
676                         __u8 *recording_seq,      676                         __u8 *recording_seq,
677                         struct cec_op_digital_    677                         struct cec_op_digital_service_id *digital)
678 {                                                 678 {
679         *day = msg->msg[2];                       679         *day = msg->msg[2];
680         *month = msg->msg[3];                     680         *month = msg->msg[3];
681         /* Hours and minutes are in BCD format    681         /* Hours and minutes are in BCD format */
682         *start_hr = (msg->msg[4] >> 4) * 10 +     682         *start_hr = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
683         *start_min = (msg->msg[5] >> 4) * 10 +    683         *start_min = (msg->msg[5] >> 4) * 10 + (msg->msg[5] & 0xf);
684         *duration_hr = (msg->msg[6] >> 4) * 10    684         *duration_hr = (msg->msg[6] >> 4) * 10 + (msg->msg[6] & 0xf);
685         *duration_min = (msg->msg[7] >> 4) * 1    685         *duration_min = (msg->msg[7] >> 4) * 10 + (msg->msg[7] & 0xf);
686         *recording_seq = msg->msg[8];             686         *recording_seq = msg->msg[8];
687         cec_get_digital_service_id(msg->msg +     687         cec_get_digital_service_id(msg->msg + 9, digital);
688 }                                                 688 }
689                                                   689 
690 static inline void cec_msg_set_ext_timer(struc    690 static inline void cec_msg_set_ext_timer(struct cec_msg *msg,
691                                          int r    691                                          int reply,
692                                          __u8     692                                          __u8 day,
693                                          __u8     693                                          __u8 month,
694                                          __u8     694                                          __u8 start_hr,
695                                          __u8     695                                          __u8 start_min,
696                                          __u8     696                                          __u8 duration_hr,
697                                          __u8     697                                          __u8 duration_min,
698                                          __u8     698                                          __u8 recording_seq,
699                                          __u8     699                                          __u8 ext_src_spec,
700                                          __u8     700                                          __u8 plug,
701                                          __u16    701                                          __u16 phys_addr)
702 {                                                 702 {
703         msg->len = 13;                            703         msg->len = 13;
704         msg->msg[1] = CEC_MSG_SET_EXT_TIMER;      704         msg->msg[1] = CEC_MSG_SET_EXT_TIMER;
705         msg->msg[2] = day;                        705         msg->msg[2] = day;
706         msg->msg[3] = month;                      706         msg->msg[3] = month;
707         /* Hours and minutes are in BCD format    707         /* Hours and minutes are in BCD format */
708         msg->msg[4] = ((start_hr / 10) << 4) |    708         msg->msg[4] = ((start_hr / 10) << 4) | (start_hr % 10);
709         msg->msg[5] = ((start_min / 10) << 4)     709         msg->msg[5] = ((start_min / 10) << 4) | (start_min % 10);
710         msg->msg[6] = ((duration_hr / 10) << 4    710         msg->msg[6] = ((duration_hr / 10) << 4) | (duration_hr % 10);
711         msg->msg[7] = ((duration_min / 10) <<     711         msg->msg[7] = ((duration_min / 10) << 4) | (duration_min % 10);
712         msg->msg[8] = recording_seq;              712         msg->msg[8] = recording_seq;
713         msg->msg[9] = ext_src_spec;               713         msg->msg[9] = ext_src_spec;
714         msg->msg[10] = plug;                      714         msg->msg[10] = plug;
715         msg->msg[11] = phys_addr >> 8;            715         msg->msg[11] = phys_addr >> 8;
716         msg->msg[12] = phys_addr & 0xff;          716         msg->msg[12] = phys_addr & 0xff;
717         msg->reply = reply ? CEC_MSG_TIMER_STA    717         msg->reply = reply ? CEC_MSG_TIMER_STATUS : 0;
718 }                                                 718 }
719                                                   719 
720 static inline void cec_ops_set_ext_timer(const    720 static inline void cec_ops_set_ext_timer(const struct cec_msg *msg,
721                                          __u8     721                                          __u8 *day,
722                                          __u8     722                                          __u8 *month,
723                                          __u8     723                                          __u8 *start_hr,
724                                          __u8     724                                          __u8 *start_min,
725                                          __u8     725                                          __u8 *duration_hr,
726                                          __u8     726                                          __u8 *duration_min,
727                                          __u8     727                                          __u8 *recording_seq,
728                                          __u8     728                                          __u8 *ext_src_spec,
729                                          __u8     729                                          __u8 *plug,
730                                          __u16    730                                          __u16 *phys_addr)
731 {                                                 731 {
732         *day = msg->msg[2];                       732         *day = msg->msg[2];
733         *month = msg->msg[3];                     733         *month = msg->msg[3];
734         /* Hours and minutes are in BCD format    734         /* Hours and minutes are in BCD format */
735         *start_hr = (msg->msg[4] >> 4) * 10 +     735         *start_hr = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
736         *start_min = (msg->msg[5] >> 4) * 10 +    736         *start_min = (msg->msg[5] >> 4) * 10 + (msg->msg[5] & 0xf);
737         *duration_hr = (msg->msg[6] >> 4) * 10    737         *duration_hr = (msg->msg[6] >> 4) * 10 + (msg->msg[6] & 0xf);
738         *duration_min = (msg->msg[7] >> 4) * 1    738         *duration_min = (msg->msg[7] >> 4) * 10 + (msg->msg[7] & 0xf);
739         *recording_seq = msg->msg[8];             739         *recording_seq = msg->msg[8];
740         *ext_src_spec = msg->msg[9];              740         *ext_src_spec = msg->msg[9];
741         *plug = msg->msg[10];                     741         *plug = msg->msg[10];
742         *phys_addr = (msg->msg[11] << 8) | msg    742         *phys_addr = (msg->msg[11] << 8) | msg->msg[12];
743 }                                                 743 }
744                                                   744 
745 static inline void cec_msg_set_timer_program_t    745 static inline void cec_msg_set_timer_program_title(struct cec_msg *msg,
746                                                   746                                                    const char *prog_title)
747 {                                                 747 {
748         unsigned int len = strlen(prog_title);    748         unsigned int len = strlen(prog_title);
749                                                   749 
750         if (len > 14)                             750         if (len > 14)
751                 len = 14;                         751                 len = 14;
752         msg->len = 2 + len;                       752         msg->len = 2 + len;
753         msg->msg[1] = CEC_MSG_SET_TIMER_PROGRA    753         msg->msg[1] = CEC_MSG_SET_TIMER_PROGRAM_TITLE;
754         memcpy(msg->msg + 2, prog_title, len);    754         memcpy(msg->msg + 2, prog_title, len);
755 }                                                 755 }
756                                                   756 
757 static inline void cec_ops_set_timer_program_t    757 static inline void cec_ops_set_timer_program_title(const struct cec_msg *msg,
758                                                   758                                                    char *prog_title)
759 {                                                 759 {
760         unsigned int len = msg->len > 2 ? msg-    760         unsigned int len = msg->len > 2 ? msg->len - 2 : 0;
761                                                   761 
762         if (len > 14)                             762         if (len > 14)
763                 len = 14;                         763                 len = 14;
764         memcpy(prog_title, msg->msg + 2, len);    764         memcpy(prog_title, msg->msg + 2, len);
765         prog_title[len] = '\0';                   765         prog_title[len] = '\0';
766 }                                                 766 }
767                                                   767 
768 /* System Information Feature */                  768 /* System Information Feature */
769 static inline void cec_msg_cec_version(struct     769 static inline void cec_msg_cec_version(struct cec_msg *msg, __u8 cec_version)
770 {                                                 770 {
771         msg->len = 3;                             771         msg->len = 3;
772         msg->msg[1] = CEC_MSG_CEC_VERSION;        772         msg->msg[1] = CEC_MSG_CEC_VERSION;
773         msg->msg[2] = cec_version;                773         msg->msg[2] = cec_version;
774 }                                                 774 }
775                                                   775 
776 static inline void cec_ops_cec_version(const s    776 static inline void cec_ops_cec_version(const struct cec_msg *msg,
777                                        __u8 *c    777                                        __u8 *cec_version)
778 {                                                 778 {
779         *cec_version = msg->msg[2];               779         *cec_version = msg->msg[2];
780 }                                                 780 }
781                                                   781 
782 static inline void cec_msg_get_cec_version(str    782 static inline void cec_msg_get_cec_version(struct cec_msg *msg,
783                                            int    783                                            int reply)
784 {                                                 784 {
785         msg->len = 2;                             785         msg->len = 2;
786         msg->msg[1] = CEC_MSG_GET_CEC_VERSION;    786         msg->msg[1] = CEC_MSG_GET_CEC_VERSION;
787         msg->reply = reply ? CEC_MSG_CEC_VERSI    787         msg->reply = reply ? CEC_MSG_CEC_VERSION : 0;
788 }                                                 788 }
789                                                   789 
790 static inline void cec_msg_report_physical_add    790 static inline void cec_msg_report_physical_addr(struct cec_msg *msg,
791                                         __u16     791                                         __u16 phys_addr, __u8 prim_devtype)
792 {                                                 792 {
793         msg->len = 5;                             793         msg->len = 5;
794         msg->msg[0] |= 0xf; /* broadcast */       794         msg->msg[0] |= 0xf; /* broadcast */
795         msg->msg[1] = CEC_MSG_REPORT_PHYSICAL_    795         msg->msg[1] = CEC_MSG_REPORT_PHYSICAL_ADDR;
796         msg->msg[2] = phys_addr >> 8;             796         msg->msg[2] = phys_addr >> 8;
797         msg->msg[3] = phys_addr & 0xff;           797         msg->msg[3] = phys_addr & 0xff;
798         msg->msg[4] = prim_devtype;               798         msg->msg[4] = prim_devtype;
799 }                                                 799 }
800                                                   800 
801 static inline void cec_ops_report_physical_add    801 static inline void cec_ops_report_physical_addr(const struct cec_msg *msg,
802                                         __u16     802                                         __u16 *phys_addr, __u8 *prim_devtype)
803 {                                                 803 {
804         *phys_addr = (msg->msg[2] << 8) | msg-    804         *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
805         *prim_devtype = msg->msg[4];              805         *prim_devtype = msg->msg[4];
806 }                                                 806 }
807                                                   807 
808 static inline void cec_msg_give_physical_addr(    808 static inline void cec_msg_give_physical_addr(struct cec_msg *msg,
809                                                   809                                               int reply)
810 {                                                 810 {
811         msg->len = 2;                             811         msg->len = 2;
812         msg->msg[1] = CEC_MSG_GIVE_PHYSICAL_AD    812         msg->msg[1] = CEC_MSG_GIVE_PHYSICAL_ADDR;
813         msg->reply = reply ? CEC_MSG_REPORT_PH    813         msg->reply = reply ? CEC_MSG_REPORT_PHYSICAL_ADDR : 0;
814 }                                                 814 }
815                                                   815 
816 static inline void cec_msg_set_menu_language(s    816 static inline void cec_msg_set_menu_language(struct cec_msg *msg,
817                                              c    817                                              const char *language)
818 {                                                 818 {
819         msg->len = 5;                             819         msg->len = 5;
820         msg->msg[0] |= 0xf; /* broadcast */       820         msg->msg[0] |= 0xf; /* broadcast */
821         msg->msg[1] = CEC_MSG_SET_MENU_LANGUAG    821         msg->msg[1] = CEC_MSG_SET_MENU_LANGUAGE;
822         memcpy(msg->msg + 2, language, 3);        822         memcpy(msg->msg + 2, language, 3);
823 }                                                 823 }
824                                                   824 
825 static inline void cec_ops_set_menu_language(c    825 static inline void cec_ops_set_menu_language(const struct cec_msg *msg,
826                                              c    826                                              char *language)
827 {                                                 827 {
828         memcpy(language, msg->msg + 2, 3);        828         memcpy(language, msg->msg + 2, 3);
829         language[3] = '\0';                       829         language[3] = '\0';
830 }                                                 830 }
831                                                   831 
832 static inline void cec_msg_get_menu_language(s    832 static inline void cec_msg_get_menu_language(struct cec_msg *msg,
833                                              i    833                                              int reply)
834 {                                                 834 {
835         msg->len = 2;                             835         msg->len = 2;
836         msg->msg[1] = CEC_MSG_GET_MENU_LANGUAG    836         msg->msg[1] = CEC_MSG_GET_MENU_LANGUAGE;
837         msg->reply = reply ? CEC_MSG_SET_MENU_    837         msg->reply = reply ? CEC_MSG_SET_MENU_LANGUAGE : 0;
838 }                                                 838 }
839                                                   839 
840 /*                                                840 /*
841  * Assumes a single RC Profile byte and a sing    841  * Assumes a single RC Profile byte and a single Device Features byte,
842  * i.e. no extended features are supported by     842  * i.e. no extended features are supported by this helper function.
843  *                                                843  *
844  * As of CEC 2.0 no extended features are defi    844  * As of CEC 2.0 no extended features are defined, should those be added
845  * in the future, then this function needs to     845  * in the future, then this function needs to be adapted or a new function
846  * should be added.                               846  * should be added.
847  */                                               847  */
848 static inline void cec_msg_report_features(str    848 static inline void cec_msg_report_features(struct cec_msg *msg,
849                                 __u8 cec_versi    849                                 __u8 cec_version, __u8 all_device_types,
850                                 __u8 rc_profil    850                                 __u8 rc_profile, __u8 dev_features)
851 {                                                 851 {
852         msg->len = 6;                             852         msg->len = 6;
853         msg->msg[0] |= 0xf; /* broadcast */       853         msg->msg[0] |= 0xf; /* broadcast */
854         msg->msg[1] = CEC_MSG_REPORT_FEATURES;    854         msg->msg[1] = CEC_MSG_REPORT_FEATURES;
855         msg->msg[2] = cec_version;                855         msg->msg[2] = cec_version;
856         msg->msg[3] = all_device_types;           856         msg->msg[3] = all_device_types;
857         msg->msg[4] = rc_profile;                 857         msg->msg[4] = rc_profile;
858         msg->msg[5] = dev_features;               858         msg->msg[5] = dev_features;
859 }                                                 859 }
860                                                   860 
861 static inline void cec_ops_report_features(con    861 static inline void cec_ops_report_features(const struct cec_msg *msg,
862                         __u8 *cec_version, __u    862                         __u8 *cec_version, __u8 *all_device_types,
863                         const __u8 **rc_profil    863                         const __u8 **rc_profile, const __u8 **dev_features)
864 {                                                 864 {
865         const __u8 *p = &msg->msg[4];             865         const __u8 *p = &msg->msg[4];
866                                                   866 
867         *cec_version = msg->msg[2];               867         *cec_version = msg->msg[2];
868         *all_device_types = msg->msg[3];          868         *all_device_types = msg->msg[3];
869         *rc_profile = p;                          869         *rc_profile = p;
870         *dev_features = NULL;                     870         *dev_features = NULL;
871         while (p < &msg->msg[14] && (*p & CEC_    871         while (p < &msg->msg[14] && (*p & CEC_OP_FEAT_EXT))
872                 p++;                              872                 p++;
873         if (!(*p & CEC_OP_FEAT_EXT)) {            873         if (!(*p & CEC_OP_FEAT_EXT)) {
874                 *dev_features = p + 1;            874                 *dev_features = p + 1;
875                 while (p < &msg->msg[15] && (*    875                 while (p < &msg->msg[15] && (*p & CEC_OP_FEAT_EXT))
876                         p++;                      876                         p++;
877         }                                         877         }
878         if (*p & CEC_OP_FEAT_EXT)                 878         if (*p & CEC_OP_FEAT_EXT)
879                 *rc_profile = *dev_features =     879                 *rc_profile = *dev_features = NULL;
880 }                                                 880 }
881                                                   881 
882 static inline void cec_msg_give_features(struc    882 static inline void cec_msg_give_features(struct cec_msg *msg,
883                                          int r    883                                          int reply)
884 {                                                 884 {
885         msg->len = 2;                             885         msg->len = 2;
886         msg->msg[1] = CEC_MSG_GIVE_FEATURES;      886         msg->msg[1] = CEC_MSG_GIVE_FEATURES;
887         msg->reply = reply ? CEC_MSG_REPORT_FE    887         msg->reply = reply ? CEC_MSG_REPORT_FEATURES : 0;
888 }                                                 888 }
889                                                   889 
890 /* Deck Control Feature */                        890 /* Deck Control Feature */
891 static inline void cec_msg_deck_control(struct    891 static inline void cec_msg_deck_control(struct cec_msg *msg,
892                                         __u8 d    892                                         __u8 deck_control_mode)
893 {                                                 893 {
894         msg->len = 3;                             894         msg->len = 3;
895         msg->msg[1] = CEC_MSG_DECK_CONTROL;       895         msg->msg[1] = CEC_MSG_DECK_CONTROL;
896         msg->msg[2] = deck_control_mode;          896         msg->msg[2] = deck_control_mode;
897 }                                                 897 }
898                                                   898 
899 static inline void cec_ops_deck_control(const     899 static inline void cec_ops_deck_control(const struct cec_msg *msg,
900                                         __u8 *    900                                         __u8 *deck_control_mode)
901 {                                                 901 {
902         *deck_control_mode = msg->msg[2];         902         *deck_control_mode = msg->msg[2];
903 }                                                 903 }
904                                                   904 
905 static inline void cec_msg_deck_status(struct     905 static inline void cec_msg_deck_status(struct cec_msg *msg,
906                                        __u8 de    906                                        __u8 deck_info)
907 {                                                 907 {
908         msg->len = 3;                             908         msg->len = 3;
909         msg->msg[1] = CEC_MSG_DECK_STATUS;        909         msg->msg[1] = CEC_MSG_DECK_STATUS;
910         msg->msg[2] = deck_info;                  910         msg->msg[2] = deck_info;
911 }                                                 911 }
912                                                   912 
913 static inline void cec_ops_deck_status(const s    913 static inline void cec_ops_deck_status(const struct cec_msg *msg,
914                                        __u8 *d    914                                        __u8 *deck_info)
915 {                                                 915 {
916         *deck_info = msg->msg[2];                 916         *deck_info = msg->msg[2];
917 }                                                 917 }
918                                                   918 
919 static inline void cec_msg_give_deck_status(st    919 static inline void cec_msg_give_deck_status(struct cec_msg *msg,
920                                             in    920                                             int reply,
921                                             __    921                                             __u8 status_req)
922 {                                                 922 {
923         msg->len = 3;                             923         msg->len = 3;
924         msg->msg[1] = CEC_MSG_GIVE_DECK_STATUS    924         msg->msg[1] = CEC_MSG_GIVE_DECK_STATUS;
925         msg->msg[2] = status_req;                 925         msg->msg[2] = status_req;
926         msg->reply = (reply && status_req != C    926         msg->reply = (reply && status_req != CEC_OP_STATUS_REQ_OFF) ?
927                                 CEC_MSG_DECK_S    927                                 CEC_MSG_DECK_STATUS : 0;
928 }                                                 928 }
929                                                   929 
930 static inline void cec_ops_give_deck_status(co    930 static inline void cec_ops_give_deck_status(const struct cec_msg *msg,
931                                             __    931                                             __u8 *status_req)
932 {                                                 932 {
933         *status_req = msg->msg[2];                933         *status_req = msg->msg[2];
934 }                                                 934 }
935                                                   935 
936 static inline void cec_msg_play(struct cec_msg    936 static inline void cec_msg_play(struct cec_msg *msg,
937                                 __u8 play_mode    937                                 __u8 play_mode)
938 {                                                 938 {
939         msg->len = 3;                             939         msg->len = 3;
940         msg->msg[1] = CEC_MSG_PLAY;               940         msg->msg[1] = CEC_MSG_PLAY;
941         msg->msg[2] = play_mode;                  941         msg->msg[2] = play_mode;
942 }                                                 942 }
943                                                   943 
944 static inline void cec_ops_play(const struct c    944 static inline void cec_ops_play(const struct cec_msg *msg,
945                                 __u8 *play_mod    945                                 __u8 *play_mode)
946 {                                                 946 {
947         *play_mode = msg->msg[2];                 947         *play_mode = msg->msg[2];
948 }                                                 948 }
949                                                   949 
950                                                   950 
951 /* Tuner Control Feature */                       951 /* Tuner Control Feature */
952 struct cec_op_tuner_device_info {                 952 struct cec_op_tuner_device_info {
953         __u8 rec_flag;                            953         __u8 rec_flag;
954         __u8 tuner_display_info;                  954         __u8 tuner_display_info;
955         __u8 is_analog;                           955         __u8 is_analog;
956         union {                                   956         union {
957                 struct cec_op_digital_service_    957                 struct cec_op_digital_service_id digital;
958                 struct {                          958                 struct {
959                         __u8 ana_bcast_type;      959                         __u8 ana_bcast_type;
960                         __u16 ana_freq;           960                         __u16 ana_freq;
961                         __u8 bcast_system;        961                         __u8 bcast_system;
962                 } analog;                         962                 } analog;
963         };                                        963         };
964 };                                                964 };
965                                                   965 
966 static inline void cec_msg_tuner_device_status    966 static inline void cec_msg_tuner_device_status_analog(struct cec_msg *msg,
967                                                   967                                                       __u8 rec_flag,
968                                                   968                                                       __u8 tuner_display_info,
969                                                   969                                                       __u8 ana_bcast_type,
970                                                   970                                                       __u16 ana_freq,
971                                                   971                                                       __u8 bcast_system)
972 {                                                 972 {
973         msg->len = 7;                             973         msg->len = 7;
974         msg->msg[1] = CEC_MSG_TUNER_DEVICE_STA    974         msg->msg[1] = CEC_MSG_TUNER_DEVICE_STATUS;
975         msg->msg[2] = (rec_flag << 7) | tuner_    975         msg->msg[2] = (rec_flag << 7) | tuner_display_info;
976         msg->msg[3] = ana_bcast_type;             976         msg->msg[3] = ana_bcast_type;
977         msg->msg[4] = ana_freq >> 8;              977         msg->msg[4] = ana_freq >> 8;
978         msg->msg[5] = ana_freq & 0xff;            978         msg->msg[5] = ana_freq & 0xff;
979         msg->msg[6] = bcast_system;               979         msg->msg[6] = bcast_system;
980 }                                                 980 }
981                                                   981 
982 static inline void cec_msg_tuner_device_status    982 static inline void cec_msg_tuner_device_status_digital(struct cec_msg *msg,
983                    __u8 rec_flag, __u8 tuner_d    983                    __u8 rec_flag, __u8 tuner_display_info,
984                    const struct cec_op_digital    984                    const struct cec_op_digital_service_id *digital)
985 {                                                 985 {
986         msg->len = 10;                            986         msg->len = 10;
987         msg->msg[1] = CEC_MSG_TUNER_DEVICE_STA    987         msg->msg[1] = CEC_MSG_TUNER_DEVICE_STATUS;
988         msg->msg[2] = (rec_flag << 7) | tuner_    988         msg->msg[2] = (rec_flag << 7) | tuner_display_info;
989         cec_set_digital_service_id(msg->msg +     989         cec_set_digital_service_id(msg->msg + 3, digital);
990 }                                                 990 }
991                                                   991 
992 static inline void cec_msg_tuner_device_status    992 static inline void cec_msg_tuner_device_status(struct cec_msg *msg,
993                         const struct cec_op_tu    993                         const struct cec_op_tuner_device_info *tuner_dev_info)
994 {                                                 994 {
995         if (tuner_dev_info->is_analog)            995         if (tuner_dev_info->is_analog)
996                 cec_msg_tuner_device_status_an    996                 cec_msg_tuner_device_status_analog(msg,
997                         tuner_dev_info->rec_fl    997                         tuner_dev_info->rec_flag,
998                         tuner_dev_info->tuner_    998                         tuner_dev_info->tuner_display_info,
999                         tuner_dev_info->analog    999                         tuner_dev_info->analog.ana_bcast_type,
1000                         tuner_dev_info->analo    1000                         tuner_dev_info->analog.ana_freq,
1001                         tuner_dev_info->analo    1001                         tuner_dev_info->analog.bcast_system);
1002         else                                     1002         else
1003                 cec_msg_tuner_device_status_d    1003                 cec_msg_tuner_device_status_digital(msg,
1004                         tuner_dev_info->rec_f    1004                         tuner_dev_info->rec_flag,
1005                         tuner_dev_info->tuner    1005                         tuner_dev_info->tuner_display_info,
1006                         &tuner_dev_info->digi    1006                         &tuner_dev_info->digital);
1007 }                                                1007 }
1008                                                  1008 
1009 static inline void cec_ops_tuner_device_statu    1009 static inline void cec_ops_tuner_device_status(const struct cec_msg *msg,
1010                                 struct cec_op    1010                                 struct cec_op_tuner_device_info *tuner_dev_info)
1011 {                                                1011 {
1012         tuner_dev_info->is_analog = msg->len     1012         tuner_dev_info->is_analog = msg->len < 10;
1013         tuner_dev_info->rec_flag = msg->msg[2    1013         tuner_dev_info->rec_flag = msg->msg[2] >> 7;
1014         tuner_dev_info->tuner_display_info =     1014         tuner_dev_info->tuner_display_info = msg->msg[2] & 0x7f;
1015         if (tuner_dev_info->is_analog) {         1015         if (tuner_dev_info->is_analog) {
1016                 tuner_dev_info->analog.ana_bc    1016                 tuner_dev_info->analog.ana_bcast_type = msg->msg[3];
1017                 tuner_dev_info->analog.ana_fr    1017                 tuner_dev_info->analog.ana_freq = (msg->msg[4] << 8) | msg->msg[5];
1018                 tuner_dev_info->analog.bcast_    1018                 tuner_dev_info->analog.bcast_system = msg->msg[6];
1019                 return;                          1019                 return;
1020         }                                        1020         }
1021         cec_get_digital_service_id(msg->msg +    1021         cec_get_digital_service_id(msg->msg + 3, &tuner_dev_info->digital);
1022 }                                                1022 }
1023                                                  1023 
1024 static inline void cec_msg_give_tuner_device_    1024 static inline void cec_msg_give_tuner_device_status(struct cec_msg *msg,
1025                                                  1025                                                     int reply,
1026                                                  1026                                                     __u8 status_req)
1027 {                                                1027 {
1028         msg->len = 3;                            1028         msg->len = 3;
1029         msg->msg[1] = CEC_MSG_GIVE_TUNER_DEVI    1029         msg->msg[1] = CEC_MSG_GIVE_TUNER_DEVICE_STATUS;
1030         msg->msg[2] = status_req;                1030         msg->msg[2] = status_req;
1031         msg->reply = (reply && status_req !=     1031         msg->reply = (reply && status_req != CEC_OP_STATUS_REQ_OFF) ?
1032                                 CEC_MSG_TUNER    1032                                 CEC_MSG_TUNER_DEVICE_STATUS : 0;
1033 }                                                1033 }
1034                                                  1034 
1035 static inline void cec_ops_give_tuner_device_    1035 static inline void cec_ops_give_tuner_device_status(const struct cec_msg *msg,
1036                                                  1036                                                     __u8 *status_req)
1037 {                                                1037 {
1038         *status_req = msg->msg[2];               1038         *status_req = msg->msg[2];
1039 }                                                1039 }
1040                                                  1040 
1041 static inline void cec_msg_select_analogue_se    1041 static inline void cec_msg_select_analogue_service(struct cec_msg *msg,
1042                                                  1042                                                    __u8 ana_bcast_type,
1043                                                  1043                                                    __u16 ana_freq,
1044                                                  1044                                                    __u8 bcast_system)
1045 {                                                1045 {
1046         msg->len = 6;                            1046         msg->len = 6;
1047         msg->msg[1] = CEC_MSG_SELECT_ANALOGUE    1047         msg->msg[1] = CEC_MSG_SELECT_ANALOGUE_SERVICE;
1048         msg->msg[2] = ana_bcast_type;            1048         msg->msg[2] = ana_bcast_type;
1049         msg->msg[3] = ana_freq >> 8;             1049         msg->msg[3] = ana_freq >> 8;
1050         msg->msg[4] = ana_freq & 0xff;           1050         msg->msg[4] = ana_freq & 0xff;
1051         msg->msg[5] = bcast_system;              1051         msg->msg[5] = bcast_system;
1052 }                                                1052 }
1053                                                  1053 
1054 static inline void cec_ops_select_analogue_se    1054 static inline void cec_ops_select_analogue_service(const struct cec_msg *msg,
1055                                                  1055                                                    __u8 *ana_bcast_type,
1056                                                  1056                                                    __u16 *ana_freq,
1057                                                  1057                                                    __u8 *bcast_system)
1058 {                                                1058 {
1059         *ana_bcast_type = msg->msg[2];           1059         *ana_bcast_type = msg->msg[2];
1060         *ana_freq = (msg->msg[3] << 8) | msg-    1060         *ana_freq = (msg->msg[3] << 8) | msg->msg[4];
1061         *bcast_system = msg->msg[5];             1061         *bcast_system = msg->msg[5];
1062 }                                                1062 }
1063                                                  1063 
1064 static inline void cec_msg_select_digital_ser    1064 static inline void cec_msg_select_digital_service(struct cec_msg *msg,
1065                                 const struct     1065                                 const struct cec_op_digital_service_id *digital)
1066 {                                                1066 {
1067         msg->len = 9;                            1067         msg->len = 9;
1068         msg->msg[1] = CEC_MSG_SELECT_DIGITAL_    1068         msg->msg[1] = CEC_MSG_SELECT_DIGITAL_SERVICE;
1069         cec_set_digital_service_id(msg->msg +    1069         cec_set_digital_service_id(msg->msg + 2, digital);
1070 }                                                1070 }
1071                                                  1071 
1072 static inline void cec_ops_select_digital_ser    1072 static inline void cec_ops_select_digital_service(const struct cec_msg *msg,
1073                                 struct cec_op    1073                                 struct cec_op_digital_service_id *digital)
1074 {                                                1074 {
1075         cec_get_digital_service_id(msg->msg +    1075         cec_get_digital_service_id(msg->msg + 2, digital);
1076 }                                                1076 }
1077                                                  1077 
1078 static inline void cec_msg_tuner_step_decreme    1078 static inline void cec_msg_tuner_step_decrement(struct cec_msg *msg)
1079 {                                                1079 {
1080         msg->len = 2;                            1080         msg->len = 2;
1081         msg->msg[1] = CEC_MSG_TUNER_STEP_DECR    1081         msg->msg[1] = CEC_MSG_TUNER_STEP_DECREMENT;
1082 }                                                1082 }
1083                                                  1083 
1084 static inline void cec_msg_tuner_step_increme    1084 static inline void cec_msg_tuner_step_increment(struct cec_msg *msg)
1085 {                                                1085 {
1086         msg->len = 2;                            1086         msg->len = 2;
1087         msg->msg[1] = CEC_MSG_TUNER_STEP_INCR    1087         msg->msg[1] = CEC_MSG_TUNER_STEP_INCREMENT;
1088 }                                                1088 }
1089                                                  1089 
1090                                                  1090 
1091 /* Vendor Specific Commands Feature */           1091 /* Vendor Specific Commands Feature */
1092 static inline void cec_msg_device_vendor_id(s    1092 static inline void cec_msg_device_vendor_id(struct cec_msg *msg, __u32 vendor_id)
1093 {                                                1093 {
1094         msg->len = 5;                            1094         msg->len = 5;
1095         msg->msg[0] |= 0xf; /* broadcast */      1095         msg->msg[0] |= 0xf; /* broadcast */
1096         msg->msg[1] = CEC_MSG_DEVICE_VENDOR_I    1096         msg->msg[1] = CEC_MSG_DEVICE_VENDOR_ID;
1097         msg->msg[2] = vendor_id >> 16;           1097         msg->msg[2] = vendor_id >> 16;
1098         msg->msg[3] = (vendor_id >> 8) & 0xff    1098         msg->msg[3] = (vendor_id >> 8) & 0xff;
1099         msg->msg[4] = vendor_id & 0xff;          1099         msg->msg[4] = vendor_id & 0xff;
1100 }                                                1100 }
1101                                                  1101 
1102 static inline void cec_ops_device_vendor_id(c    1102 static inline void cec_ops_device_vendor_id(const struct cec_msg *msg,
1103                                             _    1103                                             __u32 *vendor_id)
1104 {                                                1104 {
1105         *vendor_id = (msg->msg[2] << 16) | (m    1105         *vendor_id = (msg->msg[2] << 16) | (msg->msg[3] << 8) | msg->msg[4];
1106 }                                                1106 }
1107                                                  1107 
1108 static inline void cec_msg_give_device_vendor    1108 static inline void cec_msg_give_device_vendor_id(struct cec_msg *msg,
1109                                                  1109                                                  int reply)
1110 {                                                1110 {
1111         msg->len = 2;                            1111         msg->len = 2;
1112         msg->msg[1] = CEC_MSG_GIVE_DEVICE_VEN    1112         msg->msg[1] = CEC_MSG_GIVE_DEVICE_VENDOR_ID;
1113         msg->reply = reply ? CEC_MSG_DEVICE_V    1113         msg->reply = reply ? CEC_MSG_DEVICE_VENDOR_ID : 0;
1114 }                                                1114 }
1115                                                  1115 
1116 static inline void cec_msg_vendor_command(str    1116 static inline void cec_msg_vendor_command(struct cec_msg *msg,
1117                                           __u    1117                                           __u8 size, const __u8 *vendor_cmd)
1118 {                                                1118 {
1119         if (size > 14)                           1119         if (size > 14)
1120                 size = 14;                       1120                 size = 14;
1121         msg->len = 2 + size;                     1121         msg->len = 2 + size;
1122         msg->msg[1] = CEC_MSG_VENDOR_COMMAND;    1122         msg->msg[1] = CEC_MSG_VENDOR_COMMAND;
1123         memcpy(msg->msg + 2, vendor_cmd, size    1123         memcpy(msg->msg + 2, vendor_cmd, size);
1124 }                                                1124 }
1125                                                  1125 
1126 static inline void cec_ops_vendor_command(con    1126 static inline void cec_ops_vendor_command(const struct cec_msg *msg,
1127                                           __u    1127                                           __u8 *size,
1128                                           con    1128                                           const __u8 **vendor_cmd)
1129 {                                                1129 {
1130         *size = msg->len - 2;                    1130         *size = msg->len - 2;
1131                                                  1131 
1132         if (*size > 14)                          1132         if (*size > 14)
1133                 *size = 14;                      1133                 *size = 14;
1134         *vendor_cmd = msg->msg + 2;              1134         *vendor_cmd = msg->msg + 2;
1135 }                                                1135 }
1136                                                  1136 
1137 static inline void cec_msg_vendor_command_wit    1137 static inline void cec_msg_vendor_command_with_id(struct cec_msg *msg,
1138                                                  1138                                                   __u32 vendor_id, __u8 size,
1139                                                  1139                                                   const __u8 *vendor_cmd)
1140 {                                                1140 {
1141         if (size > 11)                           1141         if (size > 11)
1142                 size = 11;                       1142                 size = 11;
1143         msg->len = 5 + size;                     1143         msg->len = 5 + size;
1144         msg->msg[1] = CEC_MSG_VENDOR_COMMAND_    1144         msg->msg[1] = CEC_MSG_VENDOR_COMMAND_WITH_ID;
1145         msg->msg[2] = vendor_id >> 16;           1145         msg->msg[2] = vendor_id >> 16;
1146         msg->msg[3] = (vendor_id >> 8) & 0xff    1146         msg->msg[3] = (vendor_id >> 8) & 0xff;
1147         msg->msg[4] = vendor_id & 0xff;          1147         msg->msg[4] = vendor_id & 0xff;
1148         memcpy(msg->msg + 5, vendor_cmd, size    1148         memcpy(msg->msg + 5, vendor_cmd, size);
1149 }                                                1149 }
1150                                                  1150 
1151 static inline void cec_ops_vendor_command_wit    1151 static inline void cec_ops_vendor_command_with_id(const struct cec_msg *msg,
1152                                                  1152                                                   __u32 *vendor_id,  __u8 *size,
1153                                                  1153                                                   const __u8 **vendor_cmd)
1154 {                                                1154 {
1155         *size = msg->len - 5;                    1155         *size = msg->len - 5;
1156                                                  1156 
1157         if (*size > 11)                          1157         if (*size > 11)
1158                 *size = 11;                      1158                 *size = 11;
1159         *vendor_id = (msg->msg[2] << 16) | (m    1159         *vendor_id = (msg->msg[2] << 16) | (msg->msg[3] << 8) | msg->msg[4];
1160         *vendor_cmd = msg->msg + 5;              1160         *vendor_cmd = msg->msg + 5;
1161 }                                                1161 }
1162                                                  1162 
1163 static inline void cec_msg_vendor_remote_butt    1163 static inline void cec_msg_vendor_remote_button_down(struct cec_msg *msg,
1164                                                  1164                                                      __u8 size,
1165                                                  1165                                                      const __u8 *rc_code)
1166 {                                                1166 {
1167         if (size > 14)                           1167         if (size > 14)
1168                 size = 14;                       1168                 size = 14;
1169         msg->len = 2 + size;                     1169         msg->len = 2 + size;
1170         msg->msg[1] = CEC_MSG_VENDOR_REMOTE_B    1170         msg->msg[1] = CEC_MSG_VENDOR_REMOTE_BUTTON_DOWN;
1171         memcpy(msg->msg + 2, rc_code, size);     1171         memcpy(msg->msg + 2, rc_code, size);
1172 }                                                1172 }
1173                                                  1173 
1174 static inline void cec_ops_vendor_remote_butt    1174 static inline void cec_ops_vendor_remote_button_down(const struct cec_msg *msg,
1175                                                  1175                                                      __u8 *size,
1176                                                  1176                                                      const __u8 **rc_code)
1177 {                                                1177 {
1178         *size = msg->len - 2;                    1178         *size = msg->len - 2;
1179                                                  1179 
1180         if (*size > 14)                          1180         if (*size > 14)
1181                 *size = 14;                      1181                 *size = 14;
1182         *rc_code = msg->msg + 2;                 1182         *rc_code = msg->msg + 2;
1183 }                                                1183 }
1184                                                  1184 
1185 static inline void cec_msg_vendor_remote_butt    1185 static inline void cec_msg_vendor_remote_button_up(struct cec_msg *msg)
1186 {                                                1186 {
1187         msg->len = 2;                            1187         msg->len = 2;
1188         msg->msg[1] = CEC_MSG_VENDOR_REMOTE_B    1188         msg->msg[1] = CEC_MSG_VENDOR_REMOTE_BUTTON_UP;
1189 }                                                1189 }
1190                                                  1190 
1191                                                  1191 
1192 /* OSD Display Feature */                        1192 /* OSD Display Feature */
1193 static inline void cec_msg_set_osd_string(str    1193 static inline void cec_msg_set_osd_string(struct cec_msg *msg,
1194                                           __u    1194                                           __u8 disp_ctl,
1195                                           con    1195                                           const char *osd)
1196 {                                                1196 {
1197         unsigned int len = strlen(osd);          1197         unsigned int len = strlen(osd);
1198                                                  1198 
1199         if (len > 13)                            1199         if (len > 13)
1200                 len = 13;                        1200                 len = 13;
1201         msg->len = 3 + len;                      1201         msg->len = 3 + len;
1202         msg->msg[1] = CEC_MSG_SET_OSD_STRING;    1202         msg->msg[1] = CEC_MSG_SET_OSD_STRING;
1203         msg->msg[2] = disp_ctl;                  1203         msg->msg[2] = disp_ctl;
1204         memcpy(msg->msg + 3, osd, len);          1204         memcpy(msg->msg + 3, osd, len);
1205 }                                                1205 }
1206                                                  1206 
1207 static inline void cec_ops_set_osd_string(con    1207 static inline void cec_ops_set_osd_string(const struct cec_msg *msg,
1208                                           __u    1208                                           __u8 *disp_ctl,
1209                                           cha    1209                                           char *osd)
1210 {                                                1210 {
1211         unsigned int len = msg->len > 3 ? msg    1211         unsigned int len = msg->len > 3 ? msg->len - 3 : 0;
1212                                                  1212 
1213         *disp_ctl = msg->msg[2];                 1213         *disp_ctl = msg->msg[2];
1214         if (len > 13)                            1214         if (len > 13)
1215                 len = 13;                        1215                 len = 13;
1216         memcpy(osd, msg->msg + 3, len);          1216         memcpy(osd, msg->msg + 3, len);
1217         osd[len] = '\0';                         1217         osd[len] = '\0';
1218 }                                                1218 }
1219                                                  1219 
1220                                                  1220 
1221 /* Device OSD Transfer Feature */                1221 /* Device OSD Transfer Feature */
1222 static inline void cec_msg_set_osd_name(struc    1222 static inline void cec_msg_set_osd_name(struct cec_msg *msg, const char *name)
1223 {                                                1223 {
1224         unsigned int len = strlen(name);         1224         unsigned int len = strlen(name);
1225                                                  1225 
1226         if (len > 14)                            1226         if (len > 14)
1227                 len = 14;                        1227                 len = 14;
1228         msg->len = 2 + len;                      1228         msg->len = 2 + len;
1229         msg->msg[1] = CEC_MSG_SET_OSD_NAME;      1229         msg->msg[1] = CEC_MSG_SET_OSD_NAME;
1230         memcpy(msg->msg + 2, name, len);         1230         memcpy(msg->msg + 2, name, len);
1231 }                                                1231 }
1232                                                  1232 
1233 static inline void cec_ops_set_osd_name(const    1233 static inline void cec_ops_set_osd_name(const struct cec_msg *msg,
1234                                         char     1234                                         char *name)
1235 {                                                1235 {
1236         unsigned int len = msg->len > 2 ? msg    1236         unsigned int len = msg->len > 2 ? msg->len - 2 : 0;
1237                                                  1237 
1238         if (len > 14)                            1238         if (len > 14)
1239                 len = 14;                        1239                 len = 14;
1240         memcpy(name, msg->msg + 2, len);         1240         memcpy(name, msg->msg + 2, len);
1241         name[len] = '\0';                        1241         name[len] = '\0';
1242 }                                                1242 }
1243                                                  1243 
1244 static inline void cec_msg_give_osd_name(stru    1244 static inline void cec_msg_give_osd_name(struct cec_msg *msg,
1245                                          int     1245                                          int reply)
1246 {                                                1246 {
1247         msg->len = 2;                            1247         msg->len = 2;
1248         msg->msg[1] = CEC_MSG_GIVE_OSD_NAME;     1248         msg->msg[1] = CEC_MSG_GIVE_OSD_NAME;
1249         msg->reply = reply ? CEC_MSG_SET_OSD_    1249         msg->reply = reply ? CEC_MSG_SET_OSD_NAME : 0;
1250 }                                                1250 }
1251                                                  1251 
1252                                                  1252 
1253 /* Device Menu Control Feature */                1253 /* Device Menu Control Feature */
1254 static inline void cec_msg_menu_status(struct    1254 static inline void cec_msg_menu_status(struct cec_msg *msg,
1255                                        __u8 m    1255                                        __u8 menu_state)
1256 {                                                1256 {
1257         msg->len = 3;                            1257         msg->len = 3;
1258         msg->msg[1] = CEC_MSG_MENU_STATUS;       1258         msg->msg[1] = CEC_MSG_MENU_STATUS;
1259         msg->msg[2] = menu_state;                1259         msg->msg[2] = menu_state;
1260 }                                                1260 }
1261                                                  1261 
1262 static inline void cec_ops_menu_status(const     1262 static inline void cec_ops_menu_status(const struct cec_msg *msg,
1263                                        __u8 *    1263                                        __u8 *menu_state)
1264 {                                                1264 {
1265         *menu_state = msg->msg[2];               1265         *menu_state = msg->msg[2];
1266 }                                                1266 }
1267                                                  1267 
1268 static inline void cec_msg_menu_request(struc    1268 static inline void cec_msg_menu_request(struct cec_msg *msg,
1269                                         int r    1269                                         int reply,
1270                                         __u8     1270                                         __u8 menu_req)
1271 {                                                1271 {
1272         msg->len = 3;                            1272         msg->len = 3;
1273         msg->msg[1] = CEC_MSG_MENU_REQUEST;      1273         msg->msg[1] = CEC_MSG_MENU_REQUEST;
1274         msg->msg[2] = menu_req;                  1274         msg->msg[2] = menu_req;
1275         msg->reply = reply ? CEC_MSG_MENU_STA    1275         msg->reply = reply ? CEC_MSG_MENU_STATUS : 0;
1276 }                                                1276 }
1277                                                  1277 
1278 static inline void cec_ops_menu_request(const    1278 static inline void cec_ops_menu_request(const struct cec_msg *msg,
1279                                         __u8     1279                                         __u8 *menu_req)
1280 {                                                1280 {
1281         *menu_req = msg->msg[2];                 1281         *menu_req = msg->msg[2];
1282 }                                                1282 }
1283                                                  1283 
1284 struct cec_op_ui_command {                       1284 struct cec_op_ui_command {
1285         __u8 ui_cmd;                             1285         __u8 ui_cmd;
1286         __u8 has_opt_arg;                        1286         __u8 has_opt_arg;
1287         union {                                  1287         union {
1288                 struct cec_op_channel_data ch    1288                 struct cec_op_channel_data channel_identifier;
1289                 __u8 ui_broadcast_type;          1289                 __u8 ui_broadcast_type;
1290                 __u8 ui_sound_presentation_co    1290                 __u8 ui_sound_presentation_control;
1291                 __u8 play_mode;                  1291                 __u8 play_mode;
1292                 __u8 ui_function_media;          1292                 __u8 ui_function_media;
1293                 __u8 ui_function_select_av_in    1293                 __u8 ui_function_select_av_input;
1294                 __u8 ui_function_select_audio    1294                 __u8 ui_function_select_audio_input;
1295         };                                       1295         };
1296 };                                               1296 };
1297                                                  1297 
1298 static inline void cec_msg_user_control_press    1298 static inline void cec_msg_user_control_pressed(struct cec_msg *msg,
1299                                         const    1299                                         const struct cec_op_ui_command *ui_cmd)
1300 {                                                1300 {
1301         msg->len = 3;                            1301         msg->len = 3;
1302         msg->msg[1] = CEC_MSG_USER_CONTROL_PR    1302         msg->msg[1] = CEC_MSG_USER_CONTROL_PRESSED;
1303         msg->msg[2] = ui_cmd->ui_cmd;            1303         msg->msg[2] = ui_cmd->ui_cmd;
1304         if (!ui_cmd->has_opt_arg)                1304         if (!ui_cmd->has_opt_arg)
1305                 return;                          1305                 return;
1306         switch (ui_cmd->ui_cmd) {                1306         switch (ui_cmd->ui_cmd) {
1307         case CEC_OP_UI_CMD_SELECT_BROADCAST_T    1307         case CEC_OP_UI_CMD_SELECT_BROADCAST_TYPE:
1308         case CEC_OP_UI_CMD_SELECT_SOUND_PRESE    1308         case CEC_OP_UI_CMD_SELECT_SOUND_PRESENTATION:
1309         case CEC_OP_UI_CMD_PLAY_FUNCTION:        1309         case CEC_OP_UI_CMD_PLAY_FUNCTION:
1310         case CEC_OP_UI_CMD_SELECT_MEDIA_FUNCT    1310         case CEC_OP_UI_CMD_SELECT_MEDIA_FUNCTION:
1311         case CEC_OP_UI_CMD_SELECT_AV_INPUT_FU    1311         case CEC_OP_UI_CMD_SELECT_AV_INPUT_FUNCTION:
1312         case CEC_OP_UI_CMD_SELECT_AUDIO_INPUT    1312         case CEC_OP_UI_CMD_SELECT_AUDIO_INPUT_FUNCTION:
1313                 /* The optional operand is on    1313                 /* The optional operand is one byte for all these ui commands */
1314                 msg->len++;                      1314                 msg->len++;
1315                 msg->msg[3] = ui_cmd->play_mo    1315                 msg->msg[3] = ui_cmd->play_mode;
1316                 break;                           1316                 break;
1317         case CEC_OP_UI_CMD_TUNE_FUNCTION:        1317         case CEC_OP_UI_CMD_TUNE_FUNCTION:
1318                 msg->len += 4;                   1318                 msg->len += 4;
1319                 msg->msg[3] = (ui_cmd->channe    1319                 msg->msg[3] = (ui_cmd->channel_identifier.channel_number_fmt << 2) |
1320                               (ui_cmd->channe    1320                               (ui_cmd->channel_identifier.major >> 8);
1321                 msg->msg[4] = ui_cmd->channel    1321                 msg->msg[4] = ui_cmd->channel_identifier.major & 0xff;
1322                 msg->msg[5] = ui_cmd->channel    1322                 msg->msg[5] = ui_cmd->channel_identifier.minor >> 8;
1323                 msg->msg[6] = ui_cmd->channel    1323                 msg->msg[6] = ui_cmd->channel_identifier.minor & 0xff;
1324                 break;                           1324                 break;
1325         }                                        1325         }
1326 }                                                1326 }
1327                                                  1327 
1328 static inline void cec_ops_user_control_press    1328 static inline void cec_ops_user_control_pressed(const struct cec_msg *msg,
1329                                                  1329                                                 struct cec_op_ui_command *ui_cmd)
1330 {                                                1330 {
1331         ui_cmd->ui_cmd = msg->msg[2];            1331         ui_cmd->ui_cmd = msg->msg[2];
1332         ui_cmd->has_opt_arg = 0;                 1332         ui_cmd->has_opt_arg = 0;
1333         if (msg->len == 3)                       1333         if (msg->len == 3)
1334                 return;                          1334                 return;
1335         switch (ui_cmd->ui_cmd) {                1335         switch (ui_cmd->ui_cmd) {
1336         case CEC_OP_UI_CMD_SELECT_BROADCAST_T    1336         case CEC_OP_UI_CMD_SELECT_BROADCAST_TYPE:
1337         case CEC_OP_UI_CMD_SELECT_SOUND_PRESE    1337         case CEC_OP_UI_CMD_SELECT_SOUND_PRESENTATION:
1338         case CEC_OP_UI_CMD_PLAY_FUNCTION:        1338         case CEC_OP_UI_CMD_PLAY_FUNCTION:
1339         case CEC_OP_UI_CMD_SELECT_MEDIA_FUNCT    1339         case CEC_OP_UI_CMD_SELECT_MEDIA_FUNCTION:
1340         case CEC_OP_UI_CMD_SELECT_AV_INPUT_FU    1340         case CEC_OP_UI_CMD_SELECT_AV_INPUT_FUNCTION:
1341         case CEC_OP_UI_CMD_SELECT_AUDIO_INPUT    1341         case CEC_OP_UI_CMD_SELECT_AUDIO_INPUT_FUNCTION:
1342                 /* The optional operand is on    1342                 /* The optional operand is one byte for all these ui commands */
1343                 ui_cmd->play_mode = msg->msg[    1343                 ui_cmd->play_mode = msg->msg[3];
1344                 ui_cmd->has_opt_arg = 1;         1344                 ui_cmd->has_opt_arg = 1;
1345                 break;                           1345                 break;
1346         case CEC_OP_UI_CMD_TUNE_FUNCTION:        1346         case CEC_OP_UI_CMD_TUNE_FUNCTION:
1347                 if (msg->len < 7)                1347                 if (msg->len < 7)
1348                         break;                   1348                         break;
1349                 ui_cmd->has_opt_arg = 1;         1349                 ui_cmd->has_opt_arg = 1;
1350                 ui_cmd->channel_identifier.ch    1350                 ui_cmd->channel_identifier.channel_number_fmt = msg->msg[3] >> 2;
1351                 ui_cmd->channel_identifier.ma    1351                 ui_cmd->channel_identifier.major = ((msg->msg[3] & 3) << 6) | msg->msg[4];
1352                 ui_cmd->channel_identifier.mi    1352                 ui_cmd->channel_identifier.minor = (msg->msg[5] << 8) | msg->msg[6];
1353                 break;                           1353                 break;
1354         }                                        1354         }
1355 }                                                1355 }
1356                                                  1356 
1357 static inline void cec_msg_user_control_relea    1357 static inline void cec_msg_user_control_released(struct cec_msg *msg)
1358 {                                                1358 {
1359         msg->len = 2;                            1359         msg->len = 2;
1360         msg->msg[1] = CEC_MSG_USER_CONTROL_RE    1360         msg->msg[1] = CEC_MSG_USER_CONTROL_RELEASED;
1361 }                                                1361 }
1362                                                  1362 
1363 /* Remote Control Passthrough Feature */         1363 /* Remote Control Passthrough Feature */
1364                                                  1364 
1365 /* Power Status Feature */                       1365 /* Power Status Feature */
1366 static inline void cec_msg_report_power_statu    1366 static inline void cec_msg_report_power_status(struct cec_msg *msg,
1367                                                  1367                                                __u8 pwr_state)
1368 {                                                1368 {
1369         msg->len = 3;                            1369         msg->len = 3;
1370         msg->msg[1] = CEC_MSG_REPORT_POWER_ST    1370         msg->msg[1] = CEC_MSG_REPORT_POWER_STATUS;
1371         msg->msg[2] = pwr_state;                 1371         msg->msg[2] = pwr_state;
1372 }                                                1372 }
1373                                                  1373 
1374 static inline void cec_ops_report_power_statu    1374 static inline void cec_ops_report_power_status(const struct cec_msg *msg,
1375                                                  1375                                                __u8 *pwr_state)
1376 {                                                1376 {
1377         *pwr_state = msg->msg[2];                1377         *pwr_state = msg->msg[2];
1378 }                                                1378 }
1379                                                  1379 
1380 static inline void cec_msg_give_device_power_    1380 static inline void cec_msg_give_device_power_status(struct cec_msg *msg,
1381                                                  1381                                                     int reply)
1382 {                                                1382 {
1383         msg->len = 2;                            1383         msg->len = 2;
1384         msg->msg[1] = CEC_MSG_GIVE_DEVICE_POW    1384         msg->msg[1] = CEC_MSG_GIVE_DEVICE_POWER_STATUS;
1385         msg->reply = reply ? CEC_MSG_REPORT_P    1385         msg->reply = reply ? CEC_MSG_REPORT_POWER_STATUS : 0;
1386 }                                                1386 }
1387                                                  1387 
1388 /* General Protocol Messages */                  1388 /* General Protocol Messages */
1389 static inline void cec_msg_feature_abort(stru    1389 static inline void cec_msg_feature_abort(struct cec_msg *msg,
1390                                          __u8    1390                                          __u8 abort_msg, __u8 reason)
1391 {                                                1391 {
1392         msg->len = 4;                            1392         msg->len = 4;
1393         msg->msg[1] = CEC_MSG_FEATURE_ABORT;     1393         msg->msg[1] = CEC_MSG_FEATURE_ABORT;
1394         msg->msg[2] = abort_msg;                 1394         msg->msg[2] = abort_msg;
1395         msg->msg[3] = reason;                    1395         msg->msg[3] = reason;
1396 }                                                1396 }
1397                                                  1397 
1398 static inline void cec_ops_feature_abort(cons    1398 static inline void cec_ops_feature_abort(const struct cec_msg *msg,
1399                                          __u8    1399                                          __u8 *abort_msg, __u8 *reason)
1400 {                                                1400 {
1401         *abort_msg = msg->msg[2];                1401         *abort_msg = msg->msg[2];
1402         *reason = msg->msg[3];                   1402         *reason = msg->msg[3];
1403 }                                                1403 }
1404                                                  1404 
1405 /* This changes the current message into a fe    1405 /* This changes the current message into a feature abort message */
1406 static inline void cec_msg_reply_feature_abor    1406 static inline void cec_msg_reply_feature_abort(struct cec_msg *msg, __u8 reason)
1407 {                                                1407 {
1408         cec_msg_set_reply_to(msg, msg);          1408         cec_msg_set_reply_to(msg, msg);
1409         msg->len = 4;                            1409         msg->len = 4;
1410         msg->msg[2] = msg->msg[1];               1410         msg->msg[2] = msg->msg[1];
1411         msg->msg[3] = reason;                    1411         msg->msg[3] = reason;
1412         msg->msg[1] = CEC_MSG_FEATURE_ABORT;     1412         msg->msg[1] = CEC_MSG_FEATURE_ABORT;
1413 }                                                1413 }
1414                                                  1414 
1415 static inline void cec_msg_abort(struct cec_m    1415 static inline void cec_msg_abort(struct cec_msg *msg)
1416 {                                                1416 {
1417         msg->len = 2;                            1417         msg->len = 2;
1418         msg->msg[1] = CEC_MSG_ABORT;             1418         msg->msg[1] = CEC_MSG_ABORT;
1419 }                                                1419 }
1420                                                  1420 
1421                                                  1421 
1422 /* System Audio Control Feature */               1422 /* System Audio Control Feature */
1423 static inline void cec_msg_report_audio_statu    1423 static inline void cec_msg_report_audio_status(struct cec_msg *msg,
1424                                                  1424                                                __u8 aud_mute_status,
1425                                                  1425                                                __u8 aud_vol_status)
1426 {                                                1426 {
1427         msg->len = 3;                            1427         msg->len = 3;
1428         msg->msg[1] = CEC_MSG_REPORT_AUDIO_ST    1428         msg->msg[1] = CEC_MSG_REPORT_AUDIO_STATUS;
1429         msg->msg[2] = (aud_mute_status << 7)     1429         msg->msg[2] = (aud_mute_status << 7) | (aud_vol_status & 0x7f);
1430 }                                                1430 }
1431                                                  1431 
1432 static inline void cec_ops_report_audio_statu    1432 static inline void cec_ops_report_audio_status(const struct cec_msg *msg,
1433                                                  1433                                                __u8 *aud_mute_status,
1434                                                  1434                                                __u8 *aud_vol_status)
1435 {                                                1435 {
1436         *aud_mute_status = msg->msg[2] >> 7;     1436         *aud_mute_status = msg->msg[2] >> 7;
1437         *aud_vol_status = msg->msg[2] & 0x7f;    1437         *aud_vol_status = msg->msg[2] & 0x7f;
1438 }                                                1438 }
1439                                                  1439 
1440 static inline void cec_msg_give_audio_status(    1440 static inline void cec_msg_give_audio_status(struct cec_msg *msg,
1441                                                  1441                                              int reply)
1442 {                                                1442 {
1443         msg->len = 2;                            1443         msg->len = 2;
1444         msg->msg[1] = CEC_MSG_GIVE_AUDIO_STAT    1444         msg->msg[1] = CEC_MSG_GIVE_AUDIO_STATUS;
1445         msg->reply = reply ? CEC_MSG_REPORT_A    1445         msg->reply = reply ? CEC_MSG_REPORT_AUDIO_STATUS : 0;
1446 }                                                1446 }
1447                                                  1447 
1448 static inline void cec_msg_set_system_audio_m    1448 static inline void cec_msg_set_system_audio_mode(struct cec_msg *msg,
1449                                                  1449                                                  __u8 sys_aud_status)
1450 {                                                1450 {
1451         msg->len = 3;                            1451         msg->len = 3;
1452         msg->msg[1] = CEC_MSG_SET_SYSTEM_AUDI    1452         msg->msg[1] = CEC_MSG_SET_SYSTEM_AUDIO_MODE;
1453         msg->msg[2] = sys_aud_status;            1453         msg->msg[2] = sys_aud_status;
1454 }                                                1454 }
1455                                                  1455 
1456 static inline void cec_ops_set_system_audio_m    1456 static inline void cec_ops_set_system_audio_mode(const struct cec_msg *msg,
1457                                                  1457                                                  __u8 *sys_aud_status)
1458 {                                                1458 {
1459         *sys_aud_status = msg->msg[2];           1459         *sys_aud_status = msg->msg[2];
1460 }                                                1460 }
1461                                                  1461 
1462 static inline void cec_msg_system_audio_mode_    1462 static inline void cec_msg_system_audio_mode_request(struct cec_msg *msg,
1463                                                  1463                                                      int reply,
1464                                                  1464                                                      __u16 phys_addr)
1465 {                                                1465 {
1466         msg->len = phys_addr == 0xffff ? 2 :     1466         msg->len = phys_addr == 0xffff ? 2 : 4;
1467         msg->msg[1] = CEC_MSG_SYSTEM_AUDIO_MO    1467         msg->msg[1] = CEC_MSG_SYSTEM_AUDIO_MODE_REQUEST;
1468         msg->msg[2] = phys_addr >> 8;            1468         msg->msg[2] = phys_addr >> 8;
1469         msg->msg[3] = phys_addr & 0xff;          1469         msg->msg[3] = phys_addr & 0xff;
1470         msg->reply = reply ? CEC_MSG_SET_SYST    1470         msg->reply = reply ? CEC_MSG_SET_SYSTEM_AUDIO_MODE : 0;
1471                                                  1471 
1472 }                                                1472 }
1473                                                  1473 
1474 static inline void cec_ops_system_audio_mode_    1474 static inline void cec_ops_system_audio_mode_request(const struct cec_msg *msg,
1475                                                  1475                                                      __u16 *phys_addr)
1476 {                                                1476 {
1477         if (msg->len < 4)                        1477         if (msg->len < 4)
1478                 *phys_addr = 0xffff;             1478                 *phys_addr = 0xffff;
1479         else                                     1479         else
1480                 *phys_addr = (msg->msg[2] <<     1480                 *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1481 }                                                1481 }
1482                                                  1482 
1483 static inline void cec_msg_system_audio_mode_    1483 static inline void cec_msg_system_audio_mode_status(struct cec_msg *msg,
1484                                                  1484                                                     __u8 sys_aud_status)
1485 {                                                1485 {
1486         msg->len = 3;                            1486         msg->len = 3;
1487         msg->msg[1] = CEC_MSG_SYSTEM_AUDIO_MO    1487         msg->msg[1] = CEC_MSG_SYSTEM_AUDIO_MODE_STATUS;
1488         msg->msg[2] = sys_aud_status;            1488         msg->msg[2] = sys_aud_status;
1489 }                                                1489 }
1490                                                  1490 
1491 static inline void cec_ops_system_audio_mode_    1491 static inline void cec_ops_system_audio_mode_status(const struct cec_msg *msg,
1492                                                  1492                                                     __u8 *sys_aud_status)
1493 {                                                1493 {
1494         *sys_aud_status = msg->msg[2];           1494         *sys_aud_status = msg->msg[2];
1495 }                                                1495 }
1496                                                  1496 
1497 static inline void cec_msg_give_system_audio_    1497 static inline void cec_msg_give_system_audio_mode_status(struct cec_msg *msg,
1498                                                  1498                                                          int reply)
1499 {                                                1499 {
1500         msg->len = 2;                            1500         msg->len = 2;
1501         msg->msg[1] = CEC_MSG_GIVE_SYSTEM_AUD    1501         msg->msg[1] = CEC_MSG_GIVE_SYSTEM_AUDIO_MODE_STATUS;
1502         msg->reply = reply ? CEC_MSG_SYSTEM_A    1502         msg->reply = reply ? CEC_MSG_SYSTEM_AUDIO_MODE_STATUS : 0;
1503 }                                                1503 }
1504                                                  1504 
1505 static inline void cec_msg_report_short_audio    1505 static inline void cec_msg_report_short_audio_descriptor(struct cec_msg *msg,
1506                                         __u8     1506                                         __u8 num_descriptors,
1507                                         const    1507                                         const __u32 *descriptors)
1508 {                                                1508 {
1509         unsigned int i;                          1509         unsigned int i;
1510                                                  1510 
1511         if (num_descriptors > 4)                 1511         if (num_descriptors > 4)
1512                 num_descriptors = 4;             1512                 num_descriptors = 4;
1513         msg->len = 2 + num_descriptors * 3;      1513         msg->len = 2 + num_descriptors * 3;
1514         msg->msg[1] = CEC_MSG_REPORT_SHORT_AU    1514         msg->msg[1] = CEC_MSG_REPORT_SHORT_AUDIO_DESCRIPTOR;
1515         for (i = 0; i < num_descriptors; i++)    1515         for (i = 0; i < num_descriptors; i++) {
1516                 msg->msg[2 + i * 3] = (descri    1516                 msg->msg[2 + i * 3] = (descriptors[i] >> 16) & 0xff;
1517                 msg->msg[3 + i * 3] = (descri    1517                 msg->msg[3 + i * 3] = (descriptors[i] >> 8) & 0xff;
1518                 msg->msg[4 + i * 3] = descrip    1518                 msg->msg[4 + i * 3] = descriptors[i] & 0xff;
1519         }                                        1519         }
1520 }                                                1520 }
1521                                                  1521 
1522 static inline void cec_ops_report_short_audio    1522 static inline void cec_ops_report_short_audio_descriptor(const struct cec_msg *msg,
1523                                                  1523                                                          __u8 *num_descriptors,
1524                                                  1524                                                          __u32 *descriptors)
1525 {                                                1525 {
1526         unsigned int i;                          1526         unsigned int i;
1527                                                  1527 
1528         *num_descriptors = (msg->len - 2) / 3    1528         *num_descriptors = (msg->len - 2) / 3;
1529         if (*num_descriptors > 4)                1529         if (*num_descriptors > 4)
1530                 *num_descriptors = 4;            1530                 *num_descriptors = 4;
1531         for (i = 0; i < *num_descriptors; i++    1531         for (i = 0; i < *num_descriptors; i++)
1532                 descriptors[i] = (msg->msg[2     1532                 descriptors[i] = (msg->msg[2 + i * 3] << 16) |
1533                         (msg->msg[3 + i * 3]     1533                         (msg->msg[3 + i * 3] << 8) |
1534                         msg->msg[4 + i * 3];     1534                         msg->msg[4 + i * 3];
1535 }                                                1535 }
1536                                                  1536 
1537 static inline void cec_msg_request_short_audi    1537 static inline void cec_msg_request_short_audio_descriptor(struct cec_msg *msg,
1538                                         int r    1538                                         int reply,
1539                                         __u8     1539                                         __u8 num_descriptors,
1540                                         const    1540                                         const __u8 *audio_format_id,
1541                                         const    1541                                         const __u8 *audio_format_code)
1542 {                                                1542 {
1543         unsigned int i;                          1543         unsigned int i;
1544                                                  1544 
1545         if (num_descriptors > 4)                 1545         if (num_descriptors > 4)
1546                 num_descriptors = 4;             1546                 num_descriptors = 4;
1547         msg->len = 2 + num_descriptors;          1547         msg->len = 2 + num_descriptors;
1548         msg->msg[1] = CEC_MSG_REQUEST_SHORT_A    1548         msg->msg[1] = CEC_MSG_REQUEST_SHORT_AUDIO_DESCRIPTOR;
1549         msg->reply = reply ? CEC_MSG_REPORT_S    1549         msg->reply = reply ? CEC_MSG_REPORT_SHORT_AUDIO_DESCRIPTOR : 0;
1550         for (i = 0; i < num_descriptors; i++)    1550         for (i = 0; i < num_descriptors; i++)
1551                 msg->msg[2 + i] = (audio_form    1551                 msg->msg[2 + i] = (audio_format_id[i] << 6) |
1552                                   (audio_form    1552                                   (audio_format_code[i] & 0x3f);
1553 }                                                1553 }
1554                                                  1554 
1555 static inline void cec_ops_request_short_audi    1555 static inline void cec_ops_request_short_audio_descriptor(const struct cec_msg *msg,
1556                                         __u8     1556                                         __u8 *num_descriptors,
1557                                         __u8     1557                                         __u8 *audio_format_id,
1558                                         __u8     1558                                         __u8 *audio_format_code)
1559 {                                                1559 {
1560         unsigned int i;                          1560         unsigned int i;
1561                                                  1561 
1562         *num_descriptors = msg->len - 2;         1562         *num_descriptors = msg->len - 2;
1563         if (*num_descriptors > 4)                1563         if (*num_descriptors > 4)
1564                 *num_descriptors = 4;            1564                 *num_descriptors = 4;
1565         for (i = 0; i < *num_descriptors; i++    1565         for (i = 0; i < *num_descriptors; i++) {
1566                 audio_format_id[i] = msg->msg    1566                 audio_format_id[i] = msg->msg[2 + i] >> 6;
1567                 audio_format_code[i] = msg->m    1567                 audio_format_code[i] = msg->msg[2 + i] & 0x3f;
1568         }                                        1568         }
1569 }                                                1569 }
1570                                                  1570 
1571 static inline void cec_msg_set_audio_volume_l << 
1572                                               << 
1573 {                                             << 
1574         msg->len = 3;                         << 
1575         msg->msg[1] = CEC_MSG_SET_AUDIO_VOLUM << 
1576         msg->msg[2] = audio_volume_level;     << 
1577 }                                             << 
1578                                               << 
1579 static inline void cec_ops_set_audio_volume_l << 
1580                                               << 
1581 {                                             << 
1582         *audio_volume_level = msg->msg[2];    << 
1583 }                                             << 
1584                                               << 
1585                                                  1571 
1586 /* Audio Rate Control Feature */                 1572 /* Audio Rate Control Feature */
1587 static inline void cec_msg_set_audio_rate(str    1573 static inline void cec_msg_set_audio_rate(struct cec_msg *msg,
1588                                           __u    1574                                           __u8 audio_rate)
1589 {                                                1575 {
1590         msg->len = 3;                            1576         msg->len = 3;
1591         msg->msg[1] = CEC_MSG_SET_AUDIO_RATE;    1577         msg->msg[1] = CEC_MSG_SET_AUDIO_RATE;
1592         msg->msg[2] = audio_rate;                1578         msg->msg[2] = audio_rate;
1593 }                                                1579 }
1594                                                  1580 
1595 static inline void cec_ops_set_audio_rate(con    1581 static inline void cec_ops_set_audio_rate(const struct cec_msg *msg,
1596                                           __u    1582                                           __u8 *audio_rate)
1597 {                                                1583 {
1598         *audio_rate = msg->msg[2];               1584         *audio_rate = msg->msg[2];
1599 }                                                1585 }
1600                                                  1586 
1601                                                  1587 
1602 /* Audio Return Channel Control Feature */       1588 /* Audio Return Channel Control Feature */
1603 static inline void cec_msg_report_arc_initiat    1589 static inline void cec_msg_report_arc_initiated(struct cec_msg *msg)
1604 {                                                1590 {
1605         msg->len = 2;                            1591         msg->len = 2;
1606         msg->msg[1] = CEC_MSG_REPORT_ARC_INIT    1592         msg->msg[1] = CEC_MSG_REPORT_ARC_INITIATED;
1607 }                                                1593 }
1608                                                  1594 
1609 static inline void cec_msg_initiate_arc(struc    1595 static inline void cec_msg_initiate_arc(struct cec_msg *msg,
1610                                         int r    1596                                         int reply)
1611 {                                                1597 {
1612         msg->len = 2;                            1598         msg->len = 2;
1613         msg->msg[1] = CEC_MSG_INITIATE_ARC;      1599         msg->msg[1] = CEC_MSG_INITIATE_ARC;
1614         msg->reply = reply ? CEC_MSG_REPORT_A    1600         msg->reply = reply ? CEC_MSG_REPORT_ARC_INITIATED : 0;
1615 }                                                1601 }
1616                                                  1602 
1617 static inline void cec_msg_request_arc_initia    1603 static inline void cec_msg_request_arc_initiation(struct cec_msg *msg,
1618                                                  1604                                                   int reply)
1619 {                                                1605 {
1620         msg->len = 2;                            1606         msg->len = 2;
1621         msg->msg[1] = CEC_MSG_REQUEST_ARC_INI    1607         msg->msg[1] = CEC_MSG_REQUEST_ARC_INITIATION;
1622         msg->reply = reply ? CEC_MSG_INITIATE    1608         msg->reply = reply ? CEC_MSG_INITIATE_ARC : 0;
1623 }                                                1609 }
1624                                                  1610 
1625 static inline void cec_msg_report_arc_termina    1611 static inline void cec_msg_report_arc_terminated(struct cec_msg *msg)
1626 {                                                1612 {
1627         msg->len = 2;                            1613         msg->len = 2;
1628         msg->msg[1] = CEC_MSG_REPORT_ARC_TERM    1614         msg->msg[1] = CEC_MSG_REPORT_ARC_TERMINATED;
1629 }                                                1615 }
1630                                                  1616 
1631 static inline void cec_msg_terminate_arc(stru    1617 static inline void cec_msg_terminate_arc(struct cec_msg *msg,
1632                                          int     1618                                          int reply)
1633 {                                                1619 {
1634         msg->len = 2;                            1620         msg->len = 2;
1635         msg->msg[1] = CEC_MSG_TERMINATE_ARC;     1621         msg->msg[1] = CEC_MSG_TERMINATE_ARC;
1636         msg->reply = reply ? CEC_MSG_REPORT_A    1622         msg->reply = reply ? CEC_MSG_REPORT_ARC_TERMINATED : 0;
1637 }                                                1623 }
1638                                                  1624 
1639 static inline void cec_msg_request_arc_termin    1625 static inline void cec_msg_request_arc_termination(struct cec_msg *msg,
1640                                                  1626                                                    int reply)
1641 {                                                1627 {
1642         msg->len = 2;                            1628         msg->len = 2;
1643         msg->msg[1] = CEC_MSG_REQUEST_ARC_TER    1629         msg->msg[1] = CEC_MSG_REQUEST_ARC_TERMINATION;
1644         msg->reply = reply ? CEC_MSG_TERMINAT    1630         msg->reply = reply ? CEC_MSG_TERMINATE_ARC : 0;
1645 }                                                1631 }
1646                                                  1632 
1647                                                  1633 
1648 /* Dynamic Audio Lipsync Feature */              1634 /* Dynamic Audio Lipsync Feature */
1649 /* Only for CEC 2.0 and up */                    1635 /* Only for CEC 2.0 and up */
1650 static inline void cec_msg_report_current_lat    1636 static inline void cec_msg_report_current_latency(struct cec_msg *msg,
1651                                                  1637                                                   __u16 phys_addr,
1652                                                  1638                                                   __u8 video_latency,
1653                                                  1639                                                   __u8 low_latency_mode,
1654                                                  1640                                                   __u8 audio_out_compensated,
1655                                                  1641                                                   __u8 audio_out_delay)
1656 {                                                1642 {
1657         msg->len = 6;                            1643         msg->len = 6;
1658         msg->msg[0] |= 0xf; /* broadcast */      1644         msg->msg[0] |= 0xf; /* broadcast */
1659         msg->msg[1] = CEC_MSG_REPORT_CURRENT_    1645         msg->msg[1] = CEC_MSG_REPORT_CURRENT_LATENCY;
1660         msg->msg[2] = phys_addr >> 8;            1646         msg->msg[2] = phys_addr >> 8;
1661         msg->msg[3] = phys_addr & 0xff;          1647         msg->msg[3] = phys_addr & 0xff;
1662         msg->msg[4] = video_latency;             1648         msg->msg[4] = video_latency;
1663         msg->msg[5] = (low_latency_mode << 2)    1649         msg->msg[5] = (low_latency_mode << 2) | audio_out_compensated;
1664         if (audio_out_compensated == 3)          1650         if (audio_out_compensated == 3)
1665                 msg->msg[msg->len++] = audio_    1651                 msg->msg[msg->len++] = audio_out_delay;
1666 }                                                1652 }
1667                                                  1653 
1668 static inline void cec_ops_report_current_lat    1654 static inline void cec_ops_report_current_latency(const struct cec_msg *msg,
1669                                                  1655                                                   __u16 *phys_addr,
1670                                                  1656                                                   __u8 *video_latency,
1671                                                  1657                                                   __u8 *low_latency_mode,
1672                                                  1658                                                   __u8 *audio_out_compensated,
1673                                                  1659                                                   __u8 *audio_out_delay)
1674 {                                                1660 {
1675         *phys_addr = (msg->msg[2] << 8) | msg    1661         *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1676         *video_latency = msg->msg[4];            1662         *video_latency = msg->msg[4];
1677         *low_latency_mode = (msg->msg[5] >> 2    1663         *low_latency_mode = (msg->msg[5] >> 2) & 1;
1678         *audio_out_compensated = msg->msg[5]     1664         *audio_out_compensated = msg->msg[5] & 3;
1679         if (*audio_out_compensated == 3 && ms    1665         if (*audio_out_compensated == 3 && msg->len >= 7)
1680                 *audio_out_delay = msg->msg[6    1666                 *audio_out_delay = msg->msg[6];
1681         else                                     1667         else
1682                 *audio_out_delay = 1;            1668                 *audio_out_delay = 1;
1683 }                                                1669 }
1684                                                  1670 
1685 static inline void cec_msg_request_current_la    1671 static inline void cec_msg_request_current_latency(struct cec_msg *msg,
1686                                                  1672                                                    int reply,
1687                                                  1673                                                    __u16 phys_addr)
1688 {                                                1674 {
1689         msg->len = 4;                            1675         msg->len = 4;
1690         msg->msg[0] |= 0xf; /* broadcast */      1676         msg->msg[0] |= 0xf; /* broadcast */
1691         msg->msg[1] = CEC_MSG_REQUEST_CURRENT    1677         msg->msg[1] = CEC_MSG_REQUEST_CURRENT_LATENCY;
1692         msg->msg[2] = phys_addr >> 8;            1678         msg->msg[2] = phys_addr >> 8;
1693         msg->msg[3] = phys_addr & 0xff;          1679         msg->msg[3] = phys_addr & 0xff;
1694         msg->reply = reply ? CEC_MSG_REPORT_C    1680         msg->reply = reply ? CEC_MSG_REPORT_CURRENT_LATENCY : 0;
1695 }                                                1681 }
1696                                                  1682 
1697 static inline void cec_ops_request_current_la    1683 static inline void cec_ops_request_current_latency(const struct cec_msg *msg,
1698                                                  1684                                                    __u16 *phys_addr)
1699 {                                                1685 {
1700         *phys_addr = (msg->msg[2] << 8) | msg    1686         *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1701 }                                                1687 }
1702                                                  1688 
1703                                                  1689 
1704 /* Capability Discovery and Control Feature *    1690 /* Capability Discovery and Control Feature */
1705 static inline void cec_msg_cdc_hec_inquire_st    1691 static inline void cec_msg_cdc_hec_inquire_state(struct cec_msg *msg,
1706                                                  1692                                                  __u16 phys_addr1,
1707                                                  1693                                                  __u16 phys_addr2)
1708 {                                                1694 {
1709         msg->len = 9;                            1695         msg->len = 9;
1710         msg->msg[0] |= 0xf; /* broadcast */      1696         msg->msg[0] |= 0xf; /* broadcast */
1711         msg->msg[1] = CEC_MSG_CDC_MESSAGE;       1697         msg->msg[1] = CEC_MSG_CDC_MESSAGE;
1712         /* msg[2] and msg[3] (phys_addr) are     1698         /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
1713         msg->msg[4] = CEC_MSG_CDC_HEC_INQUIRE    1699         msg->msg[4] = CEC_MSG_CDC_HEC_INQUIRE_STATE;
1714         msg->msg[5] = phys_addr1 >> 8;           1700         msg->msg[5] = phys_addr1 >> 8;
1715         msg->msg[6] = phys_addr1 & 0xff;         1701         msg->msg[6] = phys_addr1 & 0xff;
1716         msg->msg[7] = phys_addr2 >> 8;           1702         msg->msg[7] = phys_addr2 >> 8;
1717         msg->msg[8] = phys_addr2 & 0xff;         1703         msg->msg[8] = phys_addr2 & 0xff;
1718 }                                                1704 }
1719                                                  1705 
1720 static inline void cec_ops_cdc_hec_inquire_st    1706 static inline void cec_ops_cdc_hec_inquire_state(const struct cec_msg *msg,
1721                                                  1707                                                  __u16 *phys_addr,
1722                                                  1708                                                  __u16 *phys_addr1,
1723                                                  1709                                                  __u16 *phys_addr2)
1724 {                                                1710 {
1725         *phys_addr = (msg->msg[2] << 8) | msg    1711         *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1726         *phys_addr1 = (msg->msg[5] << 8) | ms    1712         *phys_addr1 = (msg->msg[5] << 8) | msg->msg[6];
1727         *phys_addr2 = (msg->msg[7] << 8) | ms    1713         *phys_addr2 = (msg->msg[7] << 8) | msg->msg[8];
1728 }                                                1714 }
1729                                                  1715 
1730 static inline void cec_msg_cdc_hec_report_sta    1716 static inline void cec_msg_cdc_hec_report_state(struct cec_msg *msg,
1731                                                  1717                                                 __u16 target_phys_addr,
1732                                                  1718                                                 __u8 hec_func_state,
1733                                                  1719                                                 __u8 host_func_state,
1734                                                  1720                                                 __u8 enc_func_state,
1735                                                  1721                                                 __u8 cdc_errcode,
1736                                                  1722                                                 __u8 has_field,
1737                                                  1723                                                 __u16 hec_field)
1738 {                                                1724 {
1739         msg->len = has_field ? 10 : 8;           1725         msg->len = has_field ? 10 : 8;
1740         msg->msg[0] |= 0xf; /* broadcast */      1726         msg->msg[0] |= 0xf; /* broadcast */
1741         msg->msg[1] = CEC_MSG_CDC_MESSAGE;       1727         msg->msg[1] = CEC_MSG_CDC_MESSAGE;
1742         /* msg[2] and msg[3] (phys_addr) are     1728         /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
1743         msg->msg[4] = CEC_MSG_CDC_HEC_REPORT_    1729         msg->msg[4] = CEC_MSG_CDC_HEC_REPORT_STATE;
1744         msg->msg[5] = target_phys_addr >> 8;     1730         msg->msg[5] = target_phys_addr >> 8;
1745         msg->msg[6] = target_phys_addr & 0xff    1731         msg->msg[6] = target_phys_addr & 0xff;
1746         msg->msg[7] = (hec_func_state << 6) |    1732         msg->msg[7] = (hec_func_state << 6) |
1747                       (host_func_state << 4)     1733                       (host_func_state << 4) |
1748                       (enc_func_state << 2) |    1734                       (enc_func_state << 2) |
1749                       cdc_errcode;               1735                       cdc_errcode;
1750         if (has_field) {                         1736         if (has_field) {
1751                 msg->msg[8] = hec_field >> 8;    1737                 msg->msg[8] = hec_field >> 8;
1752                 msg->msg[9] = hec_field & 0xf    1738                 msg->msg[9] = hec_field & 0xff;
1753         }                                        1739         }
1754 }                                                1740 }
1755                                                  1741 
1756 static inline void cec_ops_cdc_hec_report_sta    1742 static inline void cec_ops_cdc_hec_report_state(const struct cec_msg *msg,
1757                                                  1743                                                 __u16 *phys_addr,
1758                                                  1744                                                 __u16 *target_phys_addr,
1759                                                  1745                                                 __u8 *hec_func_state,
1760                                                  1746                                                 __u8 *host_func_state,
1761                                                  1747                                                 __u8 *enc_func_state,
1762                                                  1748                                                 __u8 *cdc_errcode,
1763                                                  1749                                                 __u8 *has_field,
1764                                                  1750                                                 __u16 *hec_field)
1765 {                                                1751 {
1766         *phys_addr = (msg->msg[2] << 8) | msg    1752         *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1767         *target_phys_addr = (msg->msg[5] << 8    1753         *target_phys_addr = (msg->msg[5] << 8) | msg->msg[6];
1768         *hec_func_state = msg->msg[7] >> 6;      1754         *hec_func_state = msg->msg[7] >> 6;
1769         *host_func_state = (msg->msg[7] >> 4)    1755         *host_func_state = (msg->msg[7] >> 4) & 3;
1770         *enc_func_state = (msg->msg[7] >> 4)     1756         *enc_func_state = (msg->msg[7] >> 4) & 3;
1771         *cdc_errcode = msg->msg[7] & 3;          1757         *cdc_errcode = msg->msg[7] & 3;
1772         *has_field = msg->len >= 10;             1758         *has_field = msg->len >= 10;
1773         *hec_field = *has_field ? ((msg->msg[    1759         *hec_field = *has_field ? ((msg->msg[8] << 8) | msg->msg[9]) : 0;
1774 }                                                1760 }
1775                                                  1761 
1776 static inline void cec_msg_cdc_hec_set_state(    1762 static inline void cec_msg_cdc_hec_set_state(struct cec_msg *msg,
1777                                                  1763                                              __u16 phys_addr1,
1778                                                  1764                                              __u16 phys_addr2,
1779                                                  1765                                              __u8 hec_set_state,
1780                                                  1766                                              __u16 phys_addr3,
1781                                                  1767                                              __u16 phys_addr4,
1782                                                  1768                                              __u16 phys_addr5)
1783 {                                                1769 {
1784         msg->len = 10;                           1770         msg->len = 10;
1785         msg->msg[0] |= 0xf; /* broadcast */      1771         msg->msg[0] |= 0xf; /* broadcast */
1786         msg->msg[1] = CEC_MSG_CDC_MESSAGE;       1772         msg->msg[1] = CEC_MSG_CDC_MESSAGE;
1787         /* msg[2] and msg[3] (phys_addr) are     1773         /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
1788         msg->msg[4] = CEC_MSG_CDC_HEC_INQUIRE    1774         msg->msg[4] = CEC_MSG_CDC_HEC_INQUIRE_STATE;
1789         msg->msg[5] = phys_addr1 >> 8;           1775         msg->msg[5] = phys_addr1 >> 8;
1790         msg->msg[6] = phys_addr1 & 0xff;         1776         msg->msg[6] = phys_addr1 & 0xff;
1791         msg->msg[7] = phys_addr2 >> 8;           1777         msg->msg[7] = phys_addr2 >> 8;
1792         msg->msg[8] = phys_addr2 & 0xff;         1778         msg->msg[8] = phys_addr2 & 0xff;
1793         msg->msg[9] = hec_set_state;             1779         msg->msg[9] = hec_set_state;
1794         if (phys_addr3 != CEC_PHYS_ADDR_INVAL    1780         if (phys_addr3 != CEC_PHYS_ADDR_INVALID) {
1795                 msg->msg[msg->len++] = phys_a    1781                 msg->msg[msg->len++] = phys_addr3 >> 8;
1796                 msg->msg[msg->len++] = phys_a    1782                 msg->msg[msg->len++] = phys_addr3 & 0xff;
1797                 if (phys_addr4 != CEC_PHYS_AD    1783                 if (phys_addr4 != CEC_PHYS_ADDR_INVALID) {
1798                         msg->msg[msg->len++]     1784                         msg->msg[msg->len++] = phys_addr4 >> 8;
1799                         msg->msg[msg->len++]     1785                         msg->msg[msg->len++] = phys_addr4 & 0xff;
1800                         if (phys_addr5 != CEC    1786                         if (phys_addr5 != CEC_PHYS_ADDR_INVALID) {
1801                                 msg->msg[msg-    1787                                 msg->msg[msg->len++] = phys_addr5 >> 8;
1802                                 msg->msg[msg-    1788                                 msg->msg[msg->len++] = phys_addr5 & 0xff;
1803                         }                        1789                         }
1804                 }                                1790                 }
1805         }                                        1791         }
1806 }                                                1792 }
1807                                                  1793 
1808 static inline void cec_ops_cdc_hec_set_state(    1794 static inline void cec_ops_cdc_hec_set_state(const struct cec_msg *msg,
1809                                                  1795                                              __u16 *phys_addr,
1810                                                  1796                                              __u16 *phys_addr1,
1811                                                  1797                                              __u16 *phys_addr2,
1812                                                  1798                                              __u8 *hec_set_state,
1813                                                  1799                                              __u16 *phys_addr3,
1814                                                  1800                                              __u16 *phys_addr4,
1815                                                  1801                                              __u16 *phys_addr5)
1816 {                                                1802 {
1817         *phys_addr = (msg->msg[2] << 8) | msg    1803         *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1818         *phys_addr1 = (msg->msg[5] << 8) | ms    1804         *phys_addr1 = (msg->msg[5] << 8) | msg->msg[6];
1819         *phys_addr2 = (msg->msg[7] << 8) | ms    1805         *phys_addr2 = (msg->msg[7] << 8) | msg->msg[8];
1820         *hec_set_state = msg->msg[9];            1806         *hec_set_state = msg->msg[9];
1821         *phys_addr3 = *phys_addr4 = *phys_add    1807         *phys_addr3 = *phys_addr4 = *phys_addr5 = CEC_PHYS_ADDR_INVALID;
1822         if (msg->len >= 12)                      1808         if (msg->len >= 12)
1823                 *phys_addr3 = (msg->msg[10] <    1809                 *phys_addr3 = (msg->msg[10] << 8) | msg->msg[11];
1824         if (msg->len >= 14)                      1810         if (msg->len >= 14)
1825                 *phys_addr4 = (msg->msg[12] <    1811                 *phys_addr4 = (msg->msg[12] << 8) | msg->msg[13];
1826         if (msg->len >= 16)                      1812         if (msg->len >= 16)
1827                 *phys_addr5 = (msg->msg[14] <    1813                 *phys_addr5 = (msg->msg[14] << 8) | msg->msg[15];
1828 }                                                1814 }
1829                                                  1815 
1830 static inline void cec_msg_cdc_hec_set_state_    1816 static inline void cec_msg_cdc_hec_set_state_adjacent(struct cec_msg *msg,
1831                                                  1817                                                       __u16 phys_addr1,
1832                                                  1818                                                       __u8 hec_set_state)
1833 {                                                1819 {
1834         msg->len = 8;                            1820         msg->len = 8;
1835         msg->msg[0] |= 0xf; /* broadcast */      1821         msg->msg[0] |= 0xf; /* broadcast */
1836         msg->msg[1] = CEC_MSG_CDC_MESSAGE;       1822         msg->msg[1] = CEC_MSG_CDC_MESSAGE;
1837         /* msg[2] and msg[3] (phys_addr) are     1823         /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
1838         msg->msg[4] = CEC_MSG_CDC_HEC_SET_STA    1824         msg->msg[4] = CEC_MSG_CDC_HEC_SET_STATE_ADJACENT;
1839         msg->msg[5] = phys_addr1 >> 8;           1825         msg->msg[5] = phys_addr1 >> 8;
1840         msg->msg[6] = phys_addr1 & 0xff;         1826         msg->msg[6] = phys_addr1 & 0xff;
1841         msg->msg[7] = hec_set_state;             1827         msg->msg[7] = hec_set_state;
1842 }                                                1828 }
1843                                                  1829 
1844 static inline void cec_ops_cdc_hec_set_state_    1830 static inline void cec_ops_cdc_hec_set_state_adjacent(const struct cec_msg *msg,
1845                                                  1831                                                       __u16 *phys_addr,
1846                                                  1832                                                       __u16 *phys_addr1,
1847                                                  1833                                                       __u8 *hec_set_state)
1848 {                                                1834 {
1849         *phys_addr = (msg->msg[2] << 8) | msg    1835         *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1850         *phys_addr1 = (msg->msg[5] << 8) | ms    1836         *phys_addr1 = (msg->msg[5] << 8) | msg->msg[6];
1851         *hec_set_state = msg->msg[7];            1837         *hec_set_state = msg->msg[7];
1852 }                                                1838 }
1853                                                  1839 
1854 static inline void cec_msg_cdc_hec_request_de    1840 static inline void cec_msg_cdc_hec_request_deactivation(struct cec_msg *msg,
1855                                                  1841                                                         __u16 phys_addr1,
1856                                                  1842                                                         __u16 phys_addr2,
1857                                                  1843                                                         __u16 phys_addr3)
1858 {                                                1844 {
1859         msg->len = 11;                           1845         msg->len = 11;
1860         msg->msg[0] |= 0xf; /* broadcast */      1846         msg->msg[0] |= 0xf; /* broadcast */
1861         msg->msg[1] = CEC_MSG_CDC_MESSAGE;       1847         msg->msg[1] = CEC_MSG_CDC_MESSAGE;
1862         /* msg[2] and msg[3] (phys_addr) are     1848         /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
1863         msg->msg[4] = CEC_MSG_CDC_HEC_REQUEST    1849         msg->msg[4] = CEC_MSG_CDC_HEC_REQUEST_DEACTIVATION;
1864         msg->msg[5] = phys_addr1 >> 8;           1850         msg->msg[5] = phys_addr1 >> 8;
1865         msg->msg[6] = phys_addr1 & 0xff;         1851         msg->msg[6] = phys_addr1 & 0xff;
1866         msg->msg[7] = phys_addr2 >> 8;           1852         msg->msg[7] = phys_addr2 >> 8;
1867         msg->msg[8] = phys_addr2 & 0xff;         1853         msg->msg[8] = phys_addr2 & 0xff;
1868         msg->msg[9] = phys_addr3 >> 8;           1854         msg->msg[9] = phys_addr3 >> 8;
1869         msg->msg[10] = phys_addr3 & 0xff;        1855         msg->msg[10] = phys_addr3 & 0xff;
1870 }                                                1856 }
1871                                                  1857 
1872 static inline void cec_ops_cdc_hec_request_de    1858 static inline void cec_ops_cdc_hec_request_deactivation(const struct cec_msg *msg,
1873                                                  1859                                                         __u16 *phys_addr,
1874                                                  1860                                                         __u16 *phys_addr1,
1875                                                  1861                                                         __u16 *phys_addr2,
1876                                                  1862                                                         __u16 *phys_addr3)
1877 {                                                1863 {
1878         *phys_addr = (msg->msg[2] << 8) | msg    1864         *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1879         *phys_addr1 = (msg->msg[5] << 8) | ms    1865         *phys_addr1 = (msg->msg[5] << 8) | msg->msg[6];
1880         *phys_addr2 = (msg->msg[7] << 8) | ms    1866         *phys_addr2 = (msg->msg[7] << 8) | msg->msg[8];
1881         *phys_addr3 = (msg->msg[9] << 8) | ms    1867         *phys_addr3 = (msg->msg[9] << 8) | msg->msg[10];
1882 }                                                1868 }
1883                                                  1869 
1884 static inline void cec_msg_cdc_hec_notify_ali    1870 static inline void cec_msg_cdc_hec_notify_alive(struct cec_msg *msg)
1885 {                                                1871 {
1886         msg->len = 5;                            1872         msg->len = 5;
1887         msg->msg[0] |= 0xf; /* broadcast */      1873         msg->msg[0] |= 0xf; /* broadcast */
1888         msg->msg[1] = CEC_MSG_CDC_MESSAGE;       1874         msg->msg[1] = CEC_MSG_CDC_MESSAGE;
1889         /* msg[2] and msg[3] (phys_addr) are     1875         /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
1890         msg->msg[4] = CEC_MSG_CDC_HEC_NOTIFY_    1876         msg->msg[4] = CEC_MSG_CDC_HEC_NOTIFY_ALIVE;
1891 }                                                1877 }
1892                                                  1878 
1893 static inline void cec_ops_cdc_hec_notify_ali    1879 static inline void cec_ops_cdc_hec_notify_alive(const struct cec_msg *msg,
1894                                                  1880                                                 __u16 *phys_addr)
1895 {                                                1881 {
1896         *phys_addr = (msg->msg[2] << 8) | msg    1882         *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1897 }                                                1883 }
1898                                                  1884 
1899 static inline void cec_msg_cdc_hec_discover(s    1885 static inline void cec_msg_cdc_hec_discover(struct cec_msg *msg)
1900 {                                                1886 {
1901         msg->len = 5;                            1887         msg->len = 5;
1902         msg->msg[0] |= 0xf; /* broadcast */      1888         msg->msg[0] |= 0xf; /* broadcast */
1903         msg->msg[1] = CEC_MSG_CDC_MESSAGE;       1889         msg->msg[1] = CEC_MSG_CDC_MESSAGE;
1904         /* msg[2] and msg[3] (phys_addr) are     1890         /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
1905         msg->msg[4] = CEC_MSG_CDC_HEC_DISCOVE    1891         msg->msg[4] = CEC_MSG_CDC_HEC_DISCOVER;
1906 }                                                1892 }
1907                                                  1893 
1908 static inline void cec_ops_cdc_hec_discover(c    1894 static inline void cec_ops_cdc_hec_discover(const struct cec_msg *msg,
1909                                             _    1895                                             __u16 *phys_addr)
1910 {                                                1896 {
1911         *phys_addr = (msg->msg[2] << 8) | msg    1897         *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1912 }                                                1898 }
1913                                                  1899 
1914 static inline void cec_msg_cdc_hpd_set_state(    1900 static inline void cec_msg_cdc_hpd_set_state(struct cec_msg *msg,
1915                                                  1901                                              __u8 input_port,
1916                                                  1902                                              __u8 hpd_state)
1917 {                                                1903 {
1918         msg->len = 6;                            1904         msg->len = 6;
1919         msg->msg[0] |= 0xf; /* broadcast */      1905         msg->msg[0] |= 0xf; /* broadcast */
1920         msg->msg[1] = CEC_MSG_CDC_MESSAGE;       1906         msg->msg[1] = CEC_MSG_CDC_MESSAGE;
1921         /* msg[2] and msg[3] (phys_addr) are     1907         /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
1922         msg->msg[4] = CEC_MSG_CDC_HPD_SET_STA    1908         msg->msg[4] = CEC_MSG_CDC_HPD_SET_STATE;
1923         msg->msg[5] = (input_port << 4) | hpd    1909         msg->msg[5] = (input_port << 4) | hpd_state;
1924 }                                                1910 }
1925                                                  1911 
1926 static inline void cec_ops_cdc_hpd_set_state(    1912 static inline void cec_ops_cdc_hpd_set_state(const struct cec_msg *msg,
1927                                             _    1913                                             __u16 *phys_addr,
1928                                             _    1914                                             __u8 *input_port,
1929                                             _    1915                                             __u8 *hpd_state)
1930 {                                                1916 {
1931         *phys_addr = (msg->msg[2] << 8) | msg    1917         *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1932         *input_port = msg->msg[5] >> 4;          1918         *input_port = msg->msg[5] >> 4;
1933         *hpd_state = msg->msg[5] & 0xf;          1919         *hpd_state = msg->msg[5] & 0xf;
1934 }                                                1920 }
1935                                                  1921 
1936 static inline void cec_msg_cdc_hpd_report_sta    1922 static inline void cec_msg_cdc_hpd_report_state(struct cec_msg *msg,
1937                                                  1923                                                 __u8 hpd_state,
1938                                                  1924                                                 __u8 hpd_error)
1939 {                                                1925 {
1940         msg->len = 6;                            1926         msg->len = 6;
1941         msg->msg[0] |= 0xf; /* broadcast */      1927         msg->msg[0] |= 0xf; /* broadcast */
1942         msg->msg[1] = CEC_MSG_CDC_MESSAGE;       1928         msg->msg[1] = CEC_MSG_CDC_MESSAGE;
1943         /* msg[2] and msg[3] (phys_addr) are     1929         /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
1944         msg->msg[4] = CEC_MSG_CDC_HPD_REPORT_    1930         msg->msg[4] = CEC_MSG_CDC_HPD_REPORT_STATE;
1945         msg->msg[5] = (hpd_state << 4) | hpd_    1931         msg->msg[5] = (hpd_state << 4) | hpd_error;
1946 }                                                1932 }
1947                                                  1933 
1948 static inline void cec_ops_cdc_hpd_report_sta    1934 static inline void cec_ops_cdc_hpd_report_state(const struct cec_msg *msg,
1949                                                  1935                                                 __u16 *phys_addr,
1950                                                  1936                                                 __u8 *hpd_state,
1951                                                  1937                                                 __u8 *hpd_error)
1952 {                                                1938 {
1953         *phys_addr = (msg->msg[2] << 8) | msg    1939         *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
1954         *hpd_state = msg->msg[5] >> 4;           1940         *hpd_state = msg->msg[5] >> 4;
1955         *hpd_error = msg->msg[5] & 0xf;          1941         *hpd_error = msg->msg[5] & 0xf;
1956 }                                                1942 }
1957                                                  1943 
1958 #endif                                           1944 #endif
1959                                                  1945 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php