media: cros-ec-cec: Support multiple ports in MKBP cec_events
authorReka Norman <rekanorman@chromium.org>
Fri, 25 Aug 2023 02:43:58 +0000 (12:43 +1000)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Wed, 27 Sep 2023 07:39:54 +0000 (09:39 +0200)
Use the top four bits of the cec_events MKBP event to store the port
number.

Signed-off-by: Reka Norman <rekanorman@chromium.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/cec/platform/cros-ec/cros-ec-cec.c
include/linux/platform_data/cros_ec_commands.h

index d674a432dfdd12df3a94a0e3349c15473f5e1918..18f78b7e034a132dd72fd4dab003c1e430bf5496 100644 (file)
@@ -77,8 +77,17 @@ static void handle_cec_message(struct cros_ec_cec *cros_ec_cec)
 static void handle_cec_event(struct cros_ec_cec *cros_ec_cec)
 {
        struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec;
-       uint32_t events = cros_ec->event_data.data.cec_events;
-       struct cros_ec_cec_port *port = cros_ec_cec->ports[CEC_PORT];
+       uint32_t cec_events = cros_ec->event_data.data.cec_events;
+       uint32_t port_num = EC_MKBP_EVENT_CEC_GET_PORT(cec_events);
+       uint32_t events = EC_MKBP_EVENT_CEC_GET_EVENTS(cec_events);
+       struct cros_ec_cec_port *port;
+
+       if (port_num >= cros_ec_cec->num_ports) {
+               dev_err(cros_ec->dev,
+                       "received CEC event for invalid port %d\n", port_num);
+               return;
+       }
+       port = cros_ec_cec->ports[port_num];
 
        if (events & EC_MKBP_CEC_SEND_OK)
                cec_transmit_attempt_done(port->adap, CEC_TX_STATUS_OK);
index 9a0c6e28f370448b39448f4bd55f714617a37e6e..b7e8573a8a495b5628f20d0f771b0044183c30b5 100644 (file)
@@ -4440,6 +4440,16 @@ struct ec_response_i2c_passthru_protect {
 
 #define MAX_CEC_MSG_LEN 16
 
+/*
+ * Helper macros for packing/unpacking cec_events.
+ * bits[27:0] : bitmask of events from enum mkbp_cec_event
+ * bits[31:28]: port number
+ */
+#define EC_MKBP_EVENT_CEC_PACK(events, port) \
+               (((events) & GENMASK(27, 0)) | (((port) & 0xf) << 28))
+#define EC_MKBP_EVENT_CEC_GET_EVENTS(event) ((event) & GENMASK(27, 0))
+#define EC_MKBP_EVENT_CEC_GET_PORT(event) (((event) >> 28) & 0xf)
+
 /* CEC message from the AP to be written on the CEC bus */
 #define EC_CMD_CEC_WRITE_MSG 0x00B8