Skip to content

Commit a69a168

Browse files
Hans Verkuilmchehab
authored andcommitted
[media] cec: add proper support for CDC-Only CEC devices
CDC-Only CEC devices are CEC devices that can only handle CDC messages, all other messages are ignored. Add a flag to signal that this is a CDC-Only device and act accordingly. Also add helper functions to identify if a CEC device is configured as a CDC-Only device, a second TV, a switch or a processor, since these variations cannot be determined by the logical address alone. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
1 parent f5580d8 commit a69a168

4 files changed

Lines changed: 90 additions & 6 deletions

File tree

‎drivers/staging/media/cec/TODO‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
TODOs:
22

3-
- Should CEC_LOG_ADDR_TYPE_SPECIFIC be replaced by TYPE_2ND_TV and TYPE_PROCESSOR?
4-
And also TYPE_SWITCH and TYPE_CDC_ONLY in addition to the TYPE_UNREGISTERED?
5-
This should give the framework more information about the device type
6-
since SPECIFIC and UNREGISTERED give no useful information.
73
- Once this is out of staging this should no longer be a separate
84
config option, instead it should be selected by drivers that want it.
95
- Revisit the IS_REACHABLE(RC_CORE): perhaps the RC_CORE support should

‎drivers/staging/media/cec/cec-adap.c‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,8 @@ static int cec_config_thread_func(void *arg)
12331233
mutex_unlock(&adap->lock);
12341234

12351235
for (i = 0; i < las->num_log_addrs; i++) {
1236-
if (las->log_addr[i] == CEC_LOG_ADDR_INVALID)
1236+
if (las->log_addr[i] == CEC_LOG_ADDR_INVALID ||
1237+
(las->flags & CEC_LOG_ADDRS_FL_CDC_ONLY))
12371238
continue;
12381239

12391240
/*
@@ -1355,6 +1356,29 @@ int __cec_s_log_addrs(struct cec_adapter *adap,
13551356
return 0;
13561357
}
13571358

1359+
if (log_addrs->flags & CEC_LOG_ADDRS_FL_CDC_ONLY) {
1360+
/*
1361+
* Sanitize log_addrs fields if a CDC-Only device is
1362+
* requested.
1363+
*/
1364+
log_addrs->num_log_addrs = 1;
1365+
log_addrs->osd_name[0] = '\0';
1366+
log_addrs->vendor_id = CEC_VENDOR_ID_NONE;
1367+
log_addrs->log_addr_type[0] = CEC_LOG_ADDR_TYPE_UNREGISTERED;
1368+
/*
1369+
* This is just an internal convention since a CDC-Only device
1370+
* doesn't have to be a switch. But switches already use
1371+
* unregistered, so it makes some kind of sense to pick this
1372+
* as the primary device. Since a CDC-Only device never sends
1373+
* any 'normal' CEC messages this primary device type is never
1374+
* sent over the CEC bus.
1375+
*/
1376+
log_addrs->primary_device_type[0] = CEC_OP_PRIM_DEVTYPE_SWITCH;
1377+
log_addrs->all_device_types[0] = 0;
1378+
log_addrs->features[0][0] = 0;
1379+
log_addrs->features[0][1] = 0;
1380+
}
1381+
13581382
/* Ensure the osd name is 0-terminated */
13591383
log_addrs->osd_name[sizeof(log_addrs->osd_name) - 1] = '\0';
13601384

@@ -1575,6 +1599,11 @@ static int cec_receive_notify(struct cec_adapter *adap, struct cec_msg *msg,
15751599

15761600
dprintk(1, "cec_receive_notify: %*ph\n", msg->len, msg->msg);
15771601

1602+
/* If this is a CDC-Only device, then ignore any non-CDC messages */
1603+
if (cec_is_cdc_only(&adap->log_addrs) &&
1604+
msg->msg[1] != CEC_MSG_CDC_MESSAGE)
1605+
return 0;
1606+
15781607
if (adap->ops->received) {
15791608
/* Allow drivers to process the message first */
15801609
if (adap->ops->received(adap, msg) != -ENOMSG)

‎drivers/staging/media/cec/cec-api.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ static long cec_adap_s_log_addrs(struct cec_adapter *adap, struct cec_fh *fh,
163163
if (copy_from_user(&log_addrs, parg, sizeof(log_addrs)))
164164
return -EFAULT;
165165
log_addrs.flags &= CEC_LOG_ADDRS_FL_ALLOW_UNREG_FALLBACK |
166-
CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU;
166+
CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU |
167+
CEC_LOG_ADDRS_FL_CDC_ONLY;
167168
mutex_lock(&adap->lock);
168169
if (!adap->is_configuring &&
169170
(!log_addrs.num_log_addrs || !adap->is_configured) &&
@@ -190,6 +191,12 @@ static long cec_transmit(struct cec_adapter *adap, struct cec_fh *fh,
190191
return -ENOTTY;
191192
if (copy_from_user(&msg, parg, sizeof(msg)))
192193
return -EFAULT;
194+
195+
/* A CDC-Only device can only send CDC messages */
196+
if ((adap->log_addrs.flags & CEC_LOG_ADDRS_FL_CDC_ONLY) &&
197+
(msg.len == 1 || msg.msg[1] != CEC_MSG_CDC_MESSAGE))
198+
return -EINVAL;
199+
193200
msg.flags &= CEC_MSG_FL_REPLY_TO_FOLLOWERS;
194201
mutex_lock(&adap->lock);
195202
if (!adap->is_configured)

‎include/linux/cec.h‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ struct cec_log_addrs {
396396
#define CEC_LOG_ADDRS_FL_ALLOW_UNREG_FALLBACK (1 << 0)
397397
/* Passthrough RC messages to the input subsystem */
398398
#define CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU (1 << 1)
399+
/* CDC-Only device: supports only CDC messages */
400+
#define CEC_LOG_ADDRS_FL_CDC_ONLY (1 << 2)
399401

400402
/* Events */
401403

@@ -1016,4 +1018,54 @@ struct cec_event {
10161018
#define CEC_OP_HPD_ERROR_OTHER 3
10171019
#define CEC_OP_HPD_ERROR_NONE_NO_VIDEO 4
10181020

1021+
/* End of Messages */
1022+
1023+
/* Helper functions to identify the 'special' CEC devices */
1024+
1025+
static inline bool cec_is_2nd_tv(const struct cec_log_addrs *las)
1026+
{
1027+
/*
1028+
* It is a second TV if the logical address is 14 or 15 and the
1029+
* primary device type is a TV.
1030+
*/
1031+
return las->num_log_addrs &&
1032+
las->log_addr[0] >= CEC_LOG_ADDR_SPECIFIC &&
1033+
las->primary_device_type[0] == CEC_OP_PRIM_DEVTYPE_TV;
1034+
}
1035+
1036+
static inline bool cec_is_processor(const struct cec_log_addrs *las)
1037+
{
1038+
/*
1039+
* It is a processor if the logical address is 12-15 and the
1040+
* primary device type is a Processor.
1041+
*/
1042+
return las->num_log_addrs &&
1043+
las->log_addr[0] >= CEC_LOG_ADDR_BACKUP_1 &&
1044+
las->primary_device_type[0] == CEC_OP_PRIM_DEVTYPE_PROCESSOR;
1045+
}
1046+
1047+
static inline bool cec_is_switch(const struct cec_log_addrs *las)
1048+
{
1049+
/*
1050+
* It is a switch if the logical address is 15 and the
1051+
* primary device type is a Switch and the CDC-Only flag is not set.
1052+
*/
1053+
return las->num_log_addrs == 1 &&
1054+
las->log_addr[0] == CEC_LOG_ADDR_UNREGISTERED &&
1055+
las->primary_device_type[0] == CEC_OP_PRIM_DEVTYPE_SWITCH &&
1056+
!(las->flags & CEC_LOG_ADDRS_FL_CDC_ONLY);
1057+
}
1058+
1059+
static inline bool cec_is_cdc_only(const struct cec_log_addrs *las)
1060+
{
1061+
/*
1062+
* It is a CDC-only device if the logical address is 15 and the
1063+
* primary device type is a Switch and the CDC-Only flag is set.
1064+
*/
1065+
return las->num_log_addrs == 1 &&
1066+
las->log_addr[0] == CEC_LOG_ADDR_UNREGISTERED &&
1067+
las->primary_device_type[0] == CEC_OP_PRIM_DEVTYPE_SWITCH &&
1068+
(las->flags & CEC_LOG_ADDRS_FL_CDC_ONLY);
1069+
}
1070+
10191071
#endif

0 commit comments

Comments
 (0)