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