Skip to contentSkip to conversation

media: cec: add new CEC_MSG_FL_REPLY_VENDOR_ID flag

PATCH Superseded Hans Verkuil 1 participant 3 messages Jul 25, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover media: cec: add new CEC_MSG_FL_REPLY_VENDOR_ID flag

Often <Vendor Command With ID> messages start with a vendor-specific opcode, and expect a reply with the same Vendor ID, but a different opcode. It is very convenient if the same CEC core framework support for waiting for replies to regular CEC messages could be used for this as well.

Add support for this by creating the CEC_MSG_FL_REPLY_VENDOR_ID flag and the CEC_CAP_REPLY_VENDOR_ID capability.

Also add support for <Vendor Command With ID> to the vivid driver to allow this feature to be tested by cec-compliance in combination with vivid.

A separate patch series will be posted for v4l-utils.

Regards,

Hans

Hans Verkuil (2):
media: cec: core: add new CEC_MSG_FL_REPLY_VENDOR_ID flag
media: vivid: add <Vendor Command With ID> support

 .../media/cec/cec-ioc-adap-g-caps.rst         |  6 +++
 .../media/cec/cec-ioc-receive.rst             | 15 ++++++
 drivers/media/cec/core/cec-adap.c             | 54 +++++++++++++------
 drivers/media/cec/core/cec-core.c             |  2 +-
 drivers/media/test-drivers/vivid/vivid-cec.c  | 48 +++++++++++++++--
 include/media/cec.h                           |  2 +
 include/uapi/linux/cec.h                      |  3 ++
 7 files changed, 110 insertions(+), 20 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 media: cec: core: add new CEC_MSG_FL_REPLY_VENDOR_ID flag

If this flag is set, then the reply is expected to consist of the CEC_MSG_VENDOR_COMMAND_WITH_ID opcode followed by the Vendor ID (as used in bytes 1-4 of the message), followed by the struct cec_msg reply field.

Note that this assumes that the byte after the Vendor ID is a vendor-specific opcode.

This flag makes it easier to wait for replies to vendor commands, using the same CEC framework support for waiting for regular replies.

Support for this flag is indicated by setting the new CEC_CAP_REPLY_VENDOR_ID capability.

---
 .../media/cec/cec-ioc-adap-g-caps.rst         |  6 +++
 .../media/cec/cec-ioc-receive.rst             | 15 ++++++
 drivers/media/cec/core/cec-adap.c             | 54 +++++++++++++------
 drivers/media/cec/core/cec-core.c             |  2 +-
 include/media/cec.h                           |  2 +
 include/uapi/linux/cec.h                      |  3 ++
 6 files changed, 65 insertions(+), 17 deletions(-)
Documentation/userspace-api/media/cec/cec-ioc-adap-g-caps.rst +6 -0
index d5e014ce19b5..1d5248979a6d 100644
@@ -137,6 +137,12 @@ returns the information to the application. The ioctl never fails.
       - 0x00000100
       - If this capability is set, then :ref:`CEC_ADAP_G_CONNECTOR_INFO` can
         be used.
+    * .. _`CEC-CAP-REPLY-VENDOR-ID`:
+
+      - ``CEC_CAP_REPLY_VENDOR_ID``
+      - 0x00000200
+      - If this capability is set, then
+        :ref:`CEC_MSG_FL_REPLY_VENDOR_ID <cec-msg-flags>` can be used.
 
 Return Value
 ============
Documentation/userspace-api/media/cec/cec-ioc-receive.rst +15 -0
index 364938ad34df..91df807b6e96 100644
@@ -232,6 +232,21 @@ View On' messages from initiator 0xf ('Unregistered') to destination 0 ('TV').
 	capability. If that is not set, then the ``EPERM`` error code is
 	returned.
 
+    * .. _`CEC-MSG-FL-REPLY-VENDOR-ID`:
+
+      - ``CEC_MSG_FL_REPLY_VENDOR_ID``
+      - 4
+      - This flag is only available if ``CEC_CAP_REPLY_VENDOR_ID`` capability
+	is set. If this flag is set, then the reply is expected to consist of
+	the ``CEC_MSG_VENDOR_COMMAND_WITH_ID`` opcode followed by the Vendor ID
+	(as used in bytes 1-4 of the message), followed by the
+	``struct cec_msg`` ``reply`` field.
+
+	Note that this assumes that the byte after the Vendor ID is a
+	vendor-specific opcode.
+
+	This flag makes it easier to wait for replies to vendor commands.
+
 .. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{10.8cm}|
 
 .. _cec-tx-status:
drivers/media/cec/core/cec-adap.c +38 -16

115 lines not on this page · raw message

drivers/media/cec/core/cec-core.c +1 -1
index 6f940df0230c..e0756826d629 100644
@@ -273,7 +273,7 @@ struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,
 	adap->cec_pin_is_high = true;
 	adap->log_addrs.cec_version = CEC_OP_CEC_VERSION_2_0;
 	adap->log_addrs.vendor_id = CEC_VENDOR_ID_NONE;
-	adap->capabilities = caps;
+	adap->capabilities = caps | CEC_CAP_REPLY_VENDOR_ID;
 	if (debug_phys_addr)
 		adap->capabilities |= CEC_CAP_PHYS_ADDR;
 	adap->needs_hpd = caps & CEC_CAP_NEEDS_HPD;
include/media/cec.h +2 -0
index d131514032f2..07d2ee8a3904 100644
@@ -66,6 +66,8 @@ struct cec_data {
 	struct list_head xfer_list;
 	struct cec_adapter *adap;
 	struct cec_msg msg;
+	u8 match_len;
+	u8 match_reply[5];
 	struct cec_fh *fh;
 	struct delayed_work work;
 	struct completion c;
include/uapi/linux/cec.h +3 -0
index b8e071abaea5..894fffc66f2c 100644
@@ -165,6 +165,7 @@ static inline int cec_msg_recv_is_rx_result(const struct cec_msg *msg)
 /* cec_msg flags field */
 #define CEC_MSG_FL_REPLY_TO_FOLLOWERS	(1 << 0)
 #define CEC_MSG_FL_RAW			(1 << 1)
+#define CEC_MSG_FL_REPLY_VENDOR_ID	(1 << 2)
 
 /* cec_msg tx/rx_status field */
 #define CEC_TX_STATUS_OK		(1 << 0)
@@ -339,6 +340,8 @@ static inline int cec_is_unconfigured(__u16 log_addr_mask)
 #define CEC_CAP_MONITOR_PIN	(1 << 7)
 /* CEC_ADAP_G_CONNECTOR_INFO is available */
 #define CEC_CAP_CONNECTOR_INFO	(1 << 8)
+/* CEC_MSG_FL_REPLY_VENDOR_ID is available */
+#define CEC_CAP_REPLY_VENDOR_ID	(1 << 9)
 
 /**
  * struct cec_caps - CEC capabilities structure.
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/2 media: vivid: add <Vendor Command With ID> support

In reply to Hans Verkuil

This makes it possible to test the new CEC_MSG_FL_REPLY_VENDOR_ID flag.

The vivid driver will Feature Abort any messages that do not have exactly 1 payload byte. It ignores messages where the payload byte is even, and where it is odd it will reply with the payload byte incremented by 1. Basically a simple ping-pong command.

---
 drivers/media/test-drivers/vivid/vivid-cec.c | 48 ++++++++++++++++++--
 1 file changed, 45 insertions(+), 3 deletions(-)
drivers/media/test-drivers/vivid/vivid-cec.c +45 -3
index 941ef4263214..356a988dd6a1 100644
@@ -316,15 +316,16 @@ static int vivid_received(struct cec_adapter *adap, struct cec_msg *msg)
 	struct vivid_dev *dev = cec_get_drvdata(adap);
 	struct cec_msg reply;
 	u8 dest = cec_msg_destination(msg);
-	u8 disp_ctl;
-	char osd[14];
 
 	if (cec_msg_is_broadcast(msg))
 		dest = adap->log_addrs.log_addr[0];
 	cec_msg_init(&reply, dest, cec_msg_initiator(msg));
 
 	switch (cec_msg_opcode(msg)) {
-	case CEC_MSG_SET_OSD_STRING:
+	case CEC_MSG_SET_OSD_STRING: {
+		u8 disp_ctl;
+		char osd[14];
+
 		if (!cec_is_sink(adap))
 			return -ENOMSG;
 		cec_ops_set_osd_string(msg, &disp_ctl, osd);
@@ -348,6 +349,47 @@ static int vivid_received(struct cec_adapter *adap, struct cec_msg *msg)
 			break;
 		}
 		break;
+	}
+	case CEC_MSG_VENDOR_COMMAND_WITH_ID: {
+		u32 vendor_id;
+		u8 size;
+		const u8 *vendor_cmd;
+
+		/*
+		 * If we receive <Vendor Command With ID> with our vendor ID
+		 * and with a payload of size 1, and the payload value is odd,
+		 * then we reply with the same message, but with the payload
+		 * byte incremented by 1.
+		 *
+		 * If the size is 1 and the payload value is even, then we
+		 * ignore the message.
+		 *
+		 * The reason we reply to odd instead of even payload values
+		 * is that it allows for testing of the corner case where the
+		 * reply value is 0 (0xff + 1 % 256).
+		 *
+		 * For other sizes we Feature Abort.
+		 *
+		 * This is added for the specific purpose of testing the
+		 * CEC_MSG_FL_REPLY_VENDOR_ID flag using vivid.
+		 */
+		cec_ops_vendor_command_with_id(msg, &vendor_id, &size, &vendor_cmd);
+		if (vendor_id != adap->log_addrs.vendor_id)
+			break;
+		if (size == 1) {
+			// Ignore even op values
+			if (!(vendor_cmd[0] & 1))
+				break;
+			reply.len = msg->len;
+			memcpy(reply.msg + 1, msg->msg + 1, msg->len - 1);
+			reply.msg[msg->len - 1]++;
+		} else {
+			cec_msg_feature_abort(&reply, cec_msg_opcode(msg),
+					      CEC_OP_ABORT_INVALID_OP);
+		}
+		cec_transmit_msg(adap, &reply, false);
+		break;
+	}
 	default:
 		return -ENOMSG;
 	}
Signature · 1 line
2.43.0