From patchwork Fri Aug 25 02:43:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reka Norman X-Patchwork-Id: 13364948 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFE8D7E0 for ; Fri, 25 Aug 2023 02:50:13 +0000 (UTC) Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1bc83a96067so4488645ad.0 for ; Thu, 24 Aug 2023 19:50:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692931813; x=1693536613; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gbs3zfrjEkioEJ9A7S9+7yIB9Y9LXlYVB3KW5HxvSkY=; b=Z2e4gZAsfIorNq2oTPkyzzN9+rjHyuYMHyjsUQ5E8ZKHqEPkOKJ+m7jwoNZLJgiA/V gJck18tgBflBykMf2U9MPRFJGt33miqjeQMRNdq59fC4Cu5kCjisnkZ1D/cLkivM6q7Z LS1r0MfEDAY6eTMyIva+Mv8A7BQAUEP2qjoh8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692931813; x=1693536613; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gbs3zfrjEkioEJ9A7S9+7yIB9Y9LXlYVB3KW5HxvSkY=; b=IyCGr8QSu+Qx8gLYOTnC8nwcyqsOyCq90AfUAP/TbWJUFgRrr1+PQ8Pthi0IKmjsBu x3TKvXMgf2XTCDHZTteLzyDaK1AyeshuBspcwxO44yiokFLqf4H25IkLtFyTZ98MKcD3 +xGn3S40WCLlkyf3ij/x4P9Mo2KGOCiSjF5SdxE+6DbA492kZR7nCdfsT4iYAcj6W55F dgWvYa7uVERVmdExadJaWWdP5eGKDpgnhvfOt37ipL2V+L9IHGt2rjMHdlkbzziDMZln f2rdWQJlDy56kZ4fSaR6Sa52bPF8HHuSnovlKWd965gjkS7/Vr/tGUawgZn81aczS7bh 6lEQ== X-Gm-Message-State: AOJu0YzbRGOtT6tMuvI3Fy4C/rW/ECyXRNQipNUppufQL167SYMz1x5/ ZmwYPBfatQRgrGhSfx1VAasOpA== X-Google-Smtp-Source: AGHT+IHYQNJF+LrXZHfOiEcos54AW3bUXshSIa9aYDvLHBGxuDWvRqvvXT3Gao/lVXpH37Om06ayag== X-Received: by 2002:a17:902:e74b:b0:1b8:aef2:773e with SMTP id p11-20020a170902e74b00b001b8aef2773emr17278466plf.46.1692931813384; Thu, 24 Aug 2023 19:50:13 -0700 (PDT) Received: from rekanorman3.syd.corp.google.com ([2401:fa00:9:14:9fe1:d4b1:42cc:882f]) by smtp.gmail.com with ESMTPSA id q10-20020a170902a3ca00b001bb0eebd90asm420847plb.245.2023.08.24.19.50.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 19:50:12 -0700 (PDT) From: Reka Norman To: Hans Verkuil Cc: Daisuke Nojiri , Neil Armstrong , Stefan Adolfsson , Reka Norman , Benson Leung , Guenter Roeck , Mauro Carvalho Chehab , chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH v2 1/9] media: cros-ec-cec: Use cros_ec_cmd to send host commands Date: Fri, 25 Aug 2023 12:43:54 +1000 Message-ID: <20230825024735.1443836-2-rekanorman@chromium.org> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog In-Reply-To: <20230825024735.1443836-1-rekanorman@chromium.org> References: <20230825024735.1443836-1-rekanorman@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the cros_ec_cmd helper function to reduce the amount of boilerplate when sending host commands. Signed-off-by: Reka Norman --- (no changes since v1) .../media/cec/platform/cros-ec/cros-ec-cec.c | 44 +++++++------------ 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c index c17faf002877..8dd95fb38546 100644 --- a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c +++ b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c @@ -95,18 +95,14 @@ static int cros_ec_cec_set_log_addr(struct cec_adapter *adap, u8 logical_addr) { struct cros_ec_cec *cros_ec_cec = adap->priv; struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec; - struct { - struct cros_ec_command msg; - struct ec_params_cec_set data; - } __packed msg = {}; + struct ec_params_cec_set params = { + .cmd = CEC_CMD_LOGICAL_ADDRESS, + .val = logical_addr, + }; int ret; - msg.msg.command = EC_CMD_CEC_SET; - msg.msg.outsize = sizeof(msg.data); - msg.data.cmd = CEC_CMD_LOGICAL_ADDRESS; - msg.data.val = logical_addr; - - ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg); + ret = cros_ec_cmd(cros_ec, 0, EC_CMD_CEC_SET, ¶ms, sizeof(params), + NULL, 0); if (ret < 0) { dev_err(cros_ec->dev, "error setting CEC logical address on EC: %d\n", ret); @@ -121,17 +117,13 @@ static int cros_ec_cec_transmit(struct cec_adapter *adap, u8 attempts, { struct cros_ec_cec *cros_ec_cec = adap->priv; struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec; - struct { - struct cros_ec_command msg; - struct ec_params_cec_write data; - } __packed msg = {}; + struct ec_params_cec_write params; int ret; - msg.msg.command = EC_CMD_CEC_WRITE_MSG; - msg.msg.outsize = cec_msg->len; - memcpy(msg.data.msg, cec_msg->msg, cec_msg->len); + memcpy(params.msg, cec_msg->msg, cec_msg->len); - ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg); + ret = cros_ec_cmd(cros_ec, 0, EC_CMD_CEC_WRITE_MSG, ¶ms, + cec_msg->len, NULL, 0); if (ret < 0) { dev_err(cros_ec->dev, "error writing CEC msg on EC: %d\n", ret); @@ -145,18 +137,14 @@ static int cros_ec_cec_adap_enable(struct cec_adapter *adap, bool enable) { struct cros_ec_cec *cros_ec_cec = adap->priv; struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec; - struct { - struct cros_ec_command msg; - struct ec_params_cec_set data; - } __packed msg = {}; + struct ec_params_cec_set params = { + .cmd = CEC_CMD_ENABLE, + .val = enable, + }; int ret; - msg.msg.command = EC_CMD_CEC_SET; - msg.msg.outsize = sizeof(msg.data); - msg.data.cmd = CEC_CMD_ENABLE; - msg.data.val = enable; - - ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg); + ret = cros_ec_cmd(cros_ec, 0, EC_CMD_CEC_SET, ¶ms, sizeof(params), + NULL, 0); if (ret < 0) { dev_err(cros_ec->dev, "error %sabling CEC on EC: %d\n", From patchwork Fri Aug 25 02:43:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reka Norman X-Patchwork-Id: 13364949 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FDB97E0 for ; Fri, 25 Aug 2023 02:50:42 +0000 (UTC) Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1c06f6f98c0so4575085ad.3 for ; Thu, 24 Aug 2023 19:50:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692931842; x=1693536642; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wwICLIlnF2PyH3qiH1kQTn5EruolauYY2CVfJRzsF/M=; b=BPPniuRdIiMJVP4lAndNN/lKagYyq2VUzOzwi5CEuD5vcuagOLX7H5vyKsFlfpPTQ4 w8xDxVf0phpzfvZILMWjOvM3aqPb+0JxbVZVHWq8wuy06LeCM9AtV2oGoK6FfE0rj6qg hoZD6l66tIz8sOI/4Qjo/dlkKmr5tCS1KCIWw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692931842; x=1693536642; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wwICLIlnF2PyH3qiH1kQTn5EruolauYY2CVfJRzsF/M=; b=WQ6bwxmfldW7z8JU5omBJ/B82znA5maenPMnUBbYwetJOlcclU5paEAXmwwlUittdf sCJz1VCtQ97WaZkr1ZSF5GrKgDJ8ihc5qGGPRMof89NAmZHeVXGKB9915FMjES4UMJ0v 9VxNt9RSGngHeodOTHOjhSxfS7C82J0aQIiX77COmEwPw28LjZn2y7dRO6hYkcJ9wnLG m18OoqYJBvo6DtAt2fvG5Szzbgit4zrQEIfNmzmWvQ+rE/TEM2zjzBBWmpHnLpHEhwAw jDUYKE5XDo4kJ1AmrKp5RO+bpIqYaQ1BM32766fqN71qDSsn7hlFRP3TnRXtm+GrZ0Us +OsA== X-Gm-Message-State: AOJu0YxzwzCcyIsSTurpn0z/E6+PhQnSJ4bW4c7ru35J9+e6phxcDlRh HeTffo0uvEsYv/L3/KLsf1c5LA== X-Google-Smtp-Source: AGHT+IGLpuSuNPhPZKzf14nGeV/qQhAaXcXBtZJBmWZWhIyS1pRKJf0xPSsydJtyvVgCSpQ/V4KqHA== X-Received: by 2002:a17:902:c404:b0:1b5:64a4:be8b with SMTP id k4-20020a170902c40400b001b564a4be8bmr23137100plk.35.1692931841795; Thu, 24 Aug 2023 19:50:41 -0700 (PDT) Received: from rekanorman3.syd.corp.google.com ([2401:fa00:9:14:9fe1:d4b1:42cc:882f]) by smtp.gmail.com with ESMTPSA id q10-20020a170902a3ca00b001bb0eebd90asm420847plb.245.2023.08.24.19.50.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 19:50:40 -0700 (PDT) From: Reka Norman To: Hans Verkuil Cc: Daisuke Nojiri , Neil Armstrong , Stefan Adolfsson , Reka Norman , Benson Leung , Guenter Roeck , Mauro Carvalho Chehab , chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH v2 2/9] media: cros-ec-cec: Manage an array of ports Date: Fri, 25 Aug 2023 12:43:55 +1000 Message-ID: <20230825024735.1443836-3-rekanorman@chromium.org> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog In-Reply-To: <20230825024735.1443836-1-rekanorman@chromium.org> References: <20230825024735.1443836-1-rekanorman@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To support multiple CEC ports, change cros_ec_cec to contain an array of ports, each with their own CEC adapter, etc. For now, only create a single port and use that port everywhere, so there is no functional change. Support for multiple ports will be added in the following patches. Signed-off-by: Reka Norman --- (no changes since v1) .../media/cec/platform/cros-ec/cros-ec-cec.c | 147 +++++++++++++----- .../linux/platform_data/cros_ec_commands.h | 2 + 2 files changed, 110 insertions(+), 39 deletions(-) diff --git a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c index 8dd95fb38546..d76a25ae0cf1 100644 --- a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c +++ b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c @@ -21,21 +21,40 @@ #define DRV_NAME "cros-ec-cec" +/* Only one port is supported for now */ +#define CEC_NUM_PORTS 1 +#define CEC_PORT 0 + /** - * struct cros_ec_cec - Driver data for EC CEC + * struct cros_ec_cec_port - Driver data for a single EC CEC port * - * @cros_ec: Pointer to EC device - * @notifier: Notifier info for responding to EC events + * @port_num: port number * @adap: CEC adapter * @notify: CEC notifier pointer * @rx_msg: storage for a received message + * @cros_ec_cec: pointer to the parent struct */ -struct cros_ec_cec { - struct cros_ec_device *cros_ec; - struct notifier_block notifier; +struct cros_ec_cec_port { + int port_num; struct cec_adapter *adap; struct cec_notifier *notify; struct cec_msg rx_msg; + struct cros_ec_cec *cros_ec_cec; +}; + +/** + * struct cros_ec_cec - Driver data for EC CEC + * + * @cros_ec: Pointer to EC device + * @notifier: Notifier info for responding to EC events + * @num_ports: Number of CEC ports + * @ports: Array of ports + */ +struct cros_ec_cec { + struct cros_ec_device *cros_ec; + struct notifier_block notifier; + int num_ports; + struct cros_ec_cec_port *ports[EC_CEC_MAX_PORTS]; }; static void handle_cec_message(struct cros_ec_cec *cros_ec_cec) @@ -43,27 +62,28 @@ static void handle_cec_message(struct cros_ec_cec *cros_ec_cec) struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec; uint8_t *cec_message = cros_ec->event_data.data.cec_message; unsigned int len = cros_ec->event_size; + struct cros_ec_cec_port *port = cros_ec_cec->ports[CEC_PORT]; if (len > CEC_MAX_MSG_SIZE) len = CEC_MAX_MSG_SIZE; - cros_ec_cec->rx_msg.len = len; - memcpy(cros_ec_cec->rx_msg.msg, cec_message, len); + port->rx_msg.len = len; + memcpy(port->rx_msg.msg, cec_message, len); - cec_received_msg(cros_ec_cec->adap, &cros_ec_cec->rx_msg); + cec_received_msg(port->adap, &port->rx_msg); } 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]; if (events & EC_MKBP_CEC_SEND_OK) - cec_transmit_attempt_done(cros_ec_cec->adap, - CEC_TX_STATUS_OK); + cec_transmit_attempt_done(port->adap, CEC_TX_STATUS_OK); /* FW takes care of all retries, tell core to avoid more retries */ if (events & EC_MKBP_CEC_SEND_FAILED) - cec_transmit_attempt_done(cros_ec_cec->adap, + cec_transmit_attempt_done(port->adap, CEC_TX_STATUS_MAX_RETRIES | CEC_TX_STATUS_NACK); } @@ -93,7 +113,8 @@ static int cros_ec_cec_event(struct notifier_block *nb, static int cros_ec_cec_set_log_addr(struct cec_adapter *adap, u8 logical_addr) { - struct cros_ec_cec *cros_ec_cec = adap->priv; + struct cros_ec_cec_port *port = adap->priv; + struct cros_ec_cec *cros_ec_cec = port->cros_ec_cec; struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec; struct ec_params_cec_set params = { .cmd = CEC_CMD_LOGICAL_ADDRESS, @@ -115,7 +136,8 @@ static int cros_ec_cec_set_log_addr(struct cec_adapter *adap, u8 logical_addr) static int cros_ec_cec_transmit(struct cec_adapter *adap, u8 attempts, u32 signal_free_time, struct cec_msg *cec_msg) { - struct cros_ec_cec *cros_ec_cec = adap->priv; + struct cros_ec_cec_port *port = adap->priv; + struct cros_ec_cec *cros_ec_cec = port->cros_ec_cec; struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec; struct ec_params_cec_write params; int ret; @@ -135,7 +157,8 @@ static int cros_ec_cec_transmit(struct cec_adapter *adap, u8 attempts, static int cros_ec_cec_adap_enable(struct cec_adapter *adap, bool enable) { - struct cros_ec_cec *cros_ec_cec = adap->priv; + struct cros_ec_cec_port *port = adap->priv; + struct cros_ec_cec *cros_ec_cec = port->cros_ec_cec; struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec; struct ec_params_cec_set params = { .cmd = CEC_CMD_ENABLE, @@ -260,11 +283,55 @@ static struct device *cros_ec_cec_find_hdmi_dev(struct device *dev, #endif +static int cros_ec_cec_init_port(struct device *dev, + struct cros_ec_cec *cros_ec_cec, + int port_num, struct device *hdmi_dev, + const char *conn) +{ + struct cros_ec_cec_port *port; + int ret; + + port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + if (!port) + return -ENOMEM; + + port->cros_ec_cec = cros_ec_cec; + port->port_num = port_num; + + port->adap = cec_allocate_adapter(&cros_ec_cec_ops, port, DRV_NAME, + CEC_CAP_DEFAULTS | + CEC_CAP_CONNECTOR_INFO, 1); + if (IS_ERR(port->adap)) + return PTR_ERR(port->adap); + + port->notify = cec_notifier_cec_adap_register(hdmi_dev, conn, + port->adap); + if (!port->notify) { + ret = -ENOMEM; + goto out_probe_adapter; + } + + ret = cec_register_adapter(port->adap, dev); + if (ret < 0) + goto out_probe_notify; + + cros_ec_cec->ports[port_num] = port; + + return 0; + +out_probe_notify: + cec_notifier_cec_adap_unregister(port->notify, port->adap); +out_probe_adapter: + cec_delete_adapter(port->adap); + return ret; +} + static int cros_ec_cec_probe(struct platform_device *pdev) { struct cros_ec_dev *ec_dev = dev_get_drvdata(pdev->dev.parent); struct cros_ec_device *cros_ec = ec_dev->ec_dev; struct cros_ec_cec *cros_ec_cec; + struct cros_ec_cec_port *port; struct device *hdmi_dev; const char *conn = NULL; int ret; @@ -283,18 +350,13 @@ static int cros_ec_cec_probe(struct platform_device *pdev) device_init_wakeup(&pdev->dev, 1); - cros_ec_cec->adap = cec_allocate_adapter(&cros_ec_cec_ops, cros_ec_cec, - DRV_NAME, - CEC_CAP_DEFAULTS | - CEC_CAP_CONNECTOR_INFO, 1); - if (IS_ERR(cros_ec_cec->adap)) - return PTR_ERR(cros_ec_cec->adap); + cros_ec_cec->num_ports = CEC_NUM_PORTS; - cros_ec_cec->notify = cec_notifier_cec_adap_register(hdmi_dev, conn, - cros_ec_cec->adap); - if (!cros_ec_cec->notify) { - ret = -ENOMEM; - goto out_probe_adapter; + for (int i = 0; i < cros_ec_cec->num_ports; i++) { + ret = cros_ec_cec_init_port(&pdev->dev, cros_ec_cec, i, + hdmi_dev, conn); + if (ret) + goto unregister_ports; } /* Get CEC events from the EC. */ @@ -303,20 +365,24 @@ static int cros_ec_cec_probe(struct platform_device *pdev) &cros_ec_cec->notifier); if (ret) { dev_err(&pdev->dev, "failed to register notifier\n"); - goto out_probe_notify; + goto unregister_ports; } - ret = cec_register_adapter(cros_ec_cec->adap, &pdev->dev); - if (ret < 0) - goto out_probe_notify; - return 0; -out_probe_notify: - cec_notifier_cec_adap_unregister(cros_ec_cec->notify, - cros_ec_cec->adap); -out_probe_adapter: - cec_delete_adapter(cros_ec_cec->adap); +unregister_ports: + /* + * Unregister any adapters which have been registered. We don't add the + * port to the array until the adapter has been registered successfully, + * so any non-NULL ports must have been registered. + */ + for (int i = 0; i < cros_ec_cec->num_ports; i++) { + port = cros_ec_cec->ports[i]; + if (!port) + break; + cec_notifier_cec_adap_unregister(port->notify, port->adap); + cec_unregister_adapter(port->adap); + } return ret; } @@ -324,6 +390,7 @@ static void cros_ec_cec_remove(struct platform_device *pdev) { struct cros_ec_cec *cros_ec_cec = platform_get_drvdata(pdev); struct device *dev = &pdev->dev; + struct cros_ec_cec_port *port; int ret; /* @@ -337,9 +404,11 @@ static void cros_ec_cec_remove(struct platform_device *pdev) if (ret) dev_err(dev, "failed to unregister notifier\n"); - cec_notifier_cec_adap_unregister(cros_ec_cec->notify, - cros_ec_cec->adap); - cec_unregister_adapter(cros_ec_cec->adap); + for (int i = 0; i < cros_ec_cec->num_ports; i++) { + port = cros_ec_cec->ports[i]; + cec_notifier_cec_adap_unregister(port->notify, port->adap); + cec_unregister_adapter(port->adap); + } } static struct platform_driver cros_ec_cec_driver = { diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h index ab721cf13a98..cb2ddd10a613 100644 --- a/include/linux/platform_data/cros_ec_commands.h +++ b/include/linux/platform_data/cros_ec_commands.h @@ -4436,6 +4436,8 @@ struct ec_response_i2c_passthru_protect { * These commands are for sending and receiving message via HDMI CEC */ +#define EC_CEC_MAX_PORTS 16 + #define MAX_CEC_MSG_LEN 16 /* CEC message from the AP to be written on the CEC bus */ From patchwork Fri Aug 25 02:43:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reka Norman X-Patchwork-Id: 13364950 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 865E87E0 for ; Fri, 25 Aug 2023 02:51:05 +0000 (UTC) Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-68a410316a2so442137b3a.0 for ; Thu, 24 Aug 2023 19:51:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692931865; x=1693536665; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y4EGzm9bw0XByI1m8+dZAvw1r82ELdr/2MKF8VZnDhM=; b=L/peUxfv5ek1T9o7T4v/BvKO3klCtt5UyahYL2j2G6cWn+PuHUyKzkMFohwOPvt6cE hvdVtBIHC04XCH9bmcBvDAvr3SKql2+OHyX7CrprdBHGfQvQRTGxgHxTEkjtj3+3hzv3 /KSYrOS8DSJLx9HIpLQJVR1l6cNPvJIAwjjt8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692931865; x=1693536665; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y4EGzm9bw0XByI1m8+dZAvw1r82ELdr/2MKF8VZnDhM=; b=ST7xYLOtOenhFY3SRSA2A/nCWhDYBLD3kNStxxQo/N5cXftahYkkIbU787bh+0WpFE wB/7dVmbzraml5dNgGfoh7ENU59IRM8l/10Hb/lmoi+ldJRjAwy+sa/QmIp8k4Q5N+BY PHFYKqUKRmH//OPJ3Xjjk2su2oQZ34z+jOW7zWtmKTpayOHx/AbBPYHXhbDd6UnEmLbu K+glgpsfuWSIENzRN/LYN71sk27Vx3gaaBymDfNbXWapNbnwnUSUCZinPEKLZrGCaiah 7XgFNdZ4C0s6V44G+Pno5h0xXmjKTJxdsgnwBC9wn5l5DBN7B1XX5INYtN0FyPUTNEve GGqw== X-Gm-Message-State: AOJu0Yxtwfuw3vfs425X9PwGkB/6x+V+inSElJldiPhL4CsXETO9kDi6 Q3LZppVUugzmU5QkYDf3oKTfjA== X-Google-Smtp-Source: AGHT+IGNvt6/DD1lGIo+aVfNdQV4LtnbDVTQ3+AyPfWDl8BKFxGOBCCuVYRHGLggtterkcO3Ny3whg== X-Received: by 2002:a05:6a20:2449:b0:13f:3d25:d83 with SMTP id t9-20020a056a20244900b0013f3d250d83mr18540213pzc.19.1692931864876; Thu, 24 Aug 2023 19:51:04 -0700 (PDT) Received: from rekanorman3.syd.corp.google.com ([2401:fa00:9:14:9fe1:d4b1:42cc:882f]) by smtp.gmail.com with ESMTPSA id q10-20020a170902a3ca00b001bb0eebd90asm420847plb.245.2023.08.24.19.51.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 19:51:03 -0700 (PDT) From: Reka Norman To: Hans Verkuil Cc: Daisuke Nojiri , Neil Armstrong , Stefan Adolfsson , Reka Norman , Benson Leung , Guenter Roeck , Mauro Carvalho Chehab , chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH v2 3/9] media: cros-ec-cec: Support multiple ports in set/get host commands Date: Fri, 25 Aug 2023 12:43:56 +1000 Message-ID: <20230825024735.1443836-4-rekanorman@chromium.org> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog In-Reply-To: <20230825024735.1443836-1-rekanorman@chromium.org> References: <20230825024735.1443836-1-rekanorman@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reuse the top four bits of the cmd field to specify the port number. The reason for doing this as opposed to adding a separate uint8_t field is it avoids the need to add new versions of these commands. The change is backwards compatible since these bits were previously always zero, so the default behaviour is to always operate on port 0. Signed-off-by: Reka Norman --- (no changes since v1) drivers/media/cec/platform/cros-ec/cros-ec-cec.c | 2 ++ include/linux/platform_data/cros_ec_commands.h | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c index d76a25ae0cf1..e969031e1e0e 100644 --- a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c +++ b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c @@ -118,6 +118,7 @@ static int cros_ec_cec_set_log_addr(struct cec_adapter *adap, u8 logical_addr) struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec; struct ec_params_cec_set params = { .cmd = CEC_CMD_LOGICAL_ADDRESS, + .port = port->port_num, .val = logical_addr, }; int ret; @@ -162,6 +163,7 @@ static int cros_ec_cec_adap_enable(struct cec_adapter *adap, bool enable) struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec; struct ec_params_cec_set params = { .cmd = CEC_CMD_ENABLE, + .port = port->port_num, .val = enable, }; int ret; diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h index cb2ddd10a613..e8bb05db360f 100644 --- a/include/linux/platform_data/cros_ec_commands.h +++ b/include/linux/platform_data/cros_ec_commands.h @@ -4457,13 +4457,15 @@ struct ec_params_cec_write { /** * struct ec_params_cec_set - CEC parameters set * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS + * @port: CEC port to set the parameter on * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC * or 1 to enable CEC functionality, in case cmd is * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical * address between 0 and 15 or 0xff to unregister */ struct ec_params_cec_set { - uint8_t cmd; /* enum cec_command */ + uint8_t cmd : 4; /* enum cec_command */ + uint8_t port : 4; uint8_t val; } __ec_align1; @@ -4473,9 +4475,11 @@ struct ec_params_cec_set { /** * struct ec_params_cec_get - CEC parameters get * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS + * @port: CEC port to get the parameter on */ struct ec_params_cec_get { - uint8_t cmd; /* enum cec_command */ + uint8_t cmd : 4; /* enum cec_command */ + uint8_t port : 4; } __ec_align1; /** From patchwork Fri Aug 25 02:43:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reka Norman X-Patchwork-Id: 13364951 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F4B37E0 for ; Fri, 25 Aug 2023 02:51:20 +0000 (UTC) Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1c0d5b16aacso2828895ad.1 for ; Thu, 24 Aug 2023 19:51:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692931880; x=1693536680; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d39TfJDQpMKkFpdB9oQY3MYsthNxEY5fmlt/kOu0zbY=; b=hfGZqD9To6qCBphRqf6VDsKXyPLekIyvGVJX89tfvNPW6y8Qr+9U7njbsx6ECh7bK8 CRR/ICu2LV7K6XYJmQnrl8fnNDf1Es898tOGOScz+/hHenz32dg2iOUJWCyn7nXI5WvR Je54fJhAOGUZ3c3I8LcOp3LrUsiLiQebenUms= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692931880; x=1693536680; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d39TfJDQpMKkFpdB9oQY3MYsthNxEY5fmlt/kOu0zbY=; b=MUpoI/N3PMWURKOpF2WIVk0lLKki2/LALOQFVnzvzF++YH8OF7ZD3Uw5gPuOMeg9oM x/nN0GlpeI7gGy6/AMFJ/jOVy5LEqjBb0RYoKoTzLN66TsZ99+E7BX1ASNIxVT7PT/xE Zj975leOUN6tUQL++fOPr7NZ3fz+CO5XPKhfO4DU1cYJ+7Dcni7dSoxUuk984o9sH4Bl nRsvGv0gs9/EubJ5m+oNoGxniqFE/CgX6mrqqq/2vMmwO3QLWXWbt1f9HjhA1x1hK7eW HcC49JeAqhW2kWdch2wM9/Se7ouXC7qugqE6w2guWxdkw2mWkixqFzWxgKGw5XvzZuqx jJiQ== X-Gm-Message-State: AOJu0YxXfDIllS/9EXPLCA26z60H0ileWhwzEyosOs0VygTJt9tTJHlH uPjPN2iLaAoEiHKCAfqD1gOVDg== X-Google-Smtp-Source: AGHT+IGKaEmBN2CUW201gX/b8UH6PvTksEYJ4zA03HaBivXE2dQTcfLHRxnu6Y6z9DlAtwzFSgWFEA== X-Received: by 2002:a17:903:2792:b0:1bd:d141:f02d with SMTP id jw18-20020a170903279200b001bdd141f02dmr12240585plb.68.1692931879817; Thu, 24 Aug 2023 19:51:19 -0700 (PDT) Received: from rekanorman3.syd.corp.google.com ([2401:fa00:9:14:9fe1:d4b1:42cc:882f]) by smtp.gmail.com with ESMTPSA id q10-20020a170902a3ca00b001bb0eebd90asm420847plb.245.2023.08.24.19.51.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 19:51:18 -0700 (PDT) From: Reka Norman To: Hans Verkuil Cc: Daisuke Nojiri , Neil Armstrong , Stefan Adolfsson , Reka Norman , Benson Leung , Guenter Roeck , Mauro Carvalho Chehab , chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH v2 4/9] media: cros-ec-cec: Support multiple ports in write command Date: Fri, 25 Aug 2023 12:43:57 +1000 Message-ID: <20230825024735.1443836-5-rekanorman@chromium.org> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog In-Reply-To: <20230825024735.1443836-1-rekanorman@chromium.org> References: <20230825024735.1443836-1-rekanorman@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a v1 of the CEC write command which contains a port parameter. Check which versions of the write command the EC supports and use the highest supported version. If it only supports v0, check that there is only one port. With v0, the EC will assume all write commands are for port 0. Signed-off-by: Reka Norman --- (no changes since v1) .../media/cec/platform/cros-ec/cros-ec-cec.c | 54 +++++++++++++++++-- .../linux/platform_data/cros_ec_commands.h | 12 +++++ 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c index e969031e1e0e..d674a432dfdd 100644 --- a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c +++ b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c @@ -47,12 +47,14 @@ struct cros_ec_cec_port { * * @cros_ec: Pointer to EC device * @notifier: Notifier info for responding to EC events + * @write_cmd_version: Highest supported version of EC_CMD_CEC_WRITE_MSG. * @num_ports: Number of CEC ports * @ports: Array of ports */ struct cros_ec_cec { struct cros_ec_device *cros_ec; struct notifier_block notifier; + int write_cmd_version; int num_ports; struct cros_ec_cec_port *ports[EC_CEC_MAX_PORTS]; }; @@ -141,12 +143,22 @@ static int cros_ec_cec_transmit(struct cec_adapter *adap, u8 attempts, struct cros_ec_cec *cros_ec_cec = port->cros_ec_cec; struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec; struct ec_params_cec_write params; + struct ec_params_cec_write_v1 params_v1; int ret; - memcpy(params.msg, cec_msg->msg, cec_msg->len); + if (cros_ec_cec->write_cmd_version == 0) { + memcpy(params.msg, cec_msg->msg, cec_msg->len); + ret = cros_ec_cmd(cros_ec, 0, EC_CMD_CEC_WRITE_MSG, ¶ms, + cec_msg->len, NULL, 0); + } else { + params_v1.port = port->port_num; + params_v1.msg_len = cec_msg->len; + memcpy(params_v1.msg, cec_msg->msg, cec_msg->len); + ret = cros_ec_cmd(cros_ec, cros_ec_cec->write_cmd_version, + EC_CMD_CEC_WRITE_MSG, ¶ms_v1, + sizeof(params_v1), NULL, 0); + } - ret = cros_ec_cmd(cros_ec, 0, EC_CMD_CEC_WRITE_MSG, ¶ms, - cec_msg->len, NULL, 0); if (ret < 0) { dev_err(cros_ec->dev, "error writing CEC msg on EC: %d\n", ret); @@ -285,6 +297,38 @@ static struct device *cros_ec_cec_find_hdmi_dev(struct device *dev, #endif +static int cros_ec_cec_get_write_cmd_version(struct cros_ec_cec *cros_ec_cec) +{ + struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec; + struct ec_params_get_cmd_versions_v1 params = { + .cmd = EC_CMD_CEC_WRITE_MSG, + }; + struct ec_response_get_cmd_versions response; + int ret; + + ret = cros_ec_cmd(cros_ec, 1, EC_CMD_GET_CMD_VERSIONS, ¶ms, + sizeof(params), &response, sizeof(response)); + if (ret < 0) { + dev_err(cros_ec->dev, + "error getting CEC write command version: %d\n", ret); + return ret; + } + + if (response.version_mask & EC_VER_MASK(1)) { + cros_ec_cec->write_cmd_version = 1; + } else { + if (cros_ec_cec->num_ports != 1) { + dev_err(cros_ec->dev, + "v0 write command only supports 1 port, %d reported\n", + cros_ec_cec->num_ports); + return -EINVAL; + } + cros_ec_cec->write_cmd_version = 0; + } + + return 0; +} + static int cros_ec_cec_init_port(struct device *dev, struct cros_ec_cec *cros_ec_cec, int port_num, struct device *hdmi_dev, @@ -354,6 +398,10 @@ static int cros_ec_cec_probe(struct platform_device *pdev) cros_ec_cec->num_ports = CEC_NUM_PORTS; + ret = cros_ec_cec_get_write_cmd_version(cros_ec_cec); + if (ret) + return ret; + for (int i = 0; i < cros_ec_cec->num_ports; i++) { ret = cros_ec_cec_init_port(&pdev->dev, cros_ec_cec, i, hdmi_dev, conn); diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h index e8bb05db360f..9a0c6e28f370 100644 --- a/include/linux/platform_data/cros_ec_commands.h +++ b/include/linux/platform_data/cros_ec_commands.h @@ -4451,6 +4451,18 @@ struct ec_params_cec_write { uint8_t msg[MAX_CEC_MSG_LEN]; } __ec_align1; +/** + * struct ec_params_cec_write_v1 - Message to write to the CEC bus + * @port: CEC port to write the message on + * @msg_len: length of msg in bytes + * @msg: message content to write to the CEC bus + */ +struct ec_params_cec_write_v1 { + uint8_t port; + uint8_t msg_len; + uint8_t msg[MAX_CEC_MSG_LEN]; +} __ec_align1; + /* Set various CEC parameters */ #define EC_CMD_CEC_SET 0x00BA From patchwork Fri Aug 25 02:43:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reka Norman X-Patchwork-Id: 13364952 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB5ED7E0 for ; Fri, 25 Aug 2023 02:51:41 +0000 (UTC) Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-68becf931bfso432629b3a.0 for ; Thu, 24 Aug 2023 19:51:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692931901; x=1693536701; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UoorNgyABvybX2N9IoeEyWhrUT8xIewGPwdORVnknF0=; b=K8Lf4oK6ktUjrkQ68iwm6vPV8GIRczhwBm429iWOBzINCynZyca6b3meAALHmNhsiT 3xLO4pWxeMBDLLiMC7ZL5vSuU6Vc8ZIO/0pLW/bgsZLRPutSUL22aw/VMbxJOH5bDy1V 4hOnKpX5ZVIHfNMu7KTDTPkHuscv4C2QUNsIA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692931901; x=1693536701; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UoorNgyABvybX2N9IoeEyWhrUT8xIewGPwdORVnknF0=; b=Kg33CRoSMAA7OtGMN2NTdRqnIzKbEW7XpmFkyyjRwyBkdnr9dNz/ijWf3+BCTO+S7S i0Xd3yOthVuQv5EJiAJtLn6kPRHKXzqEN1eiS54D/M/4TCwOK9n2puj9aaAygY6P1hzt Hru+HN2WPnqdFDb4UTqsfmirwzoT0RFJM8Rx3FhDzLQcYiXrbNvqjLYg8G2f4lOgfwNw Ta31d1+ZqYgZ9YTRaSG4ruQL7gj7ZjhszIfQiptfpoOX0wpM4ZM/uAVHstR7cPid8H1e js9uiVU3gujHKsKyZnddeq+dBO2D1FHJtXWpMHTnx2DsbHF30Awyb2STDf2IQ5q8FLgV qeUQ== X-Gm-Message-State: AOJu0YxQ7LqP+lW2P63GamS6Fb2ODsDSnbzLGFOObKv33GJaRCucSLMm T/uuLGBGYApyySg6hrW8FrCSTw== X-Google-Smtp-Source: AGHT+IHJEWkbTkPNvjUmAuW8N3dHFgd6FLUeujMwWF6UFo7ranfDCfQ0KEffXNcO3qtYPsIntNy+Zg== X-Received: by 2002:a05:6a20:4910:b0:141:d54e:a90a with SMTP id ft16-20020a056a20491000b00141d54ea90amr13229510pzb.56.1692931901197; Thu, 24 Aug 2023 19:51:41 -0700 (PDT) Received: from rekanorman3.syd.corp.google.com ([2401:fa00:9:14:9fe1:d4b1:42cc:882f]) by smtp.gmail.com with ESMTPSA id q10-20020a170902a3ca00b001bb0eebd90asm420847plb.245.2023.08.24.19.51.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 19:51:40 -0700 (PDT) From: Reka Norman To: Hans Verkuil Cc: Daisuke Nojiri , Neil Armstrong , Stefan Adolfsson , Reka Norman , Benson Leung , Guenter Roeck , Mauro Carvalho Chehab , chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH v2 5/9] media: cros-ec-cec: Support multiple ports in MKBP cec_events Date: Fri, 25 Aug 2023 12:43:58 +1000 Message-ID: <20230825024735.1443836-6-rekanorman@chromium.org> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog In-Reply-To: <20230825024735.1443836-1-rekanorman@chromium.org> References: <20230825024735.1443836-1-rekanorman@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the top four bits of the cec_events MKBP event to store the port number. Signed-off-by: Reka Norman --- Changes in v2: - Make port_num unsigned in handle_cec_event drivers/media/cec/platform/cros-ec/cros-ec-cec.c | 13 +++++++++++-- include/linux/platform_data/cros_ec_commands.h | 10 ++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c index d674a432dfdd..18f78b7e034a 100644 --- a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c +++ b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c @@ -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); diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h index 9a0c6e28f370..b7e8573a8a49 100644 --- a/include/linux/platform_data/cros_ec_commands.h +++ b/include/linux/platform_data/cros_ec_commands.h @@ -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 From patchwork Fri Aug 25 02:43:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reka Norman X-Patchwork-Id: 13364964 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93ADD7E0 for ; Fri, 25 Aug 2023 02:52:12 +0000 (UTC) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1bf092a16c9so4714935ad.0 for ; Thu, 24 Aug 2023 19:52:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692931932; x=1693536732; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jYcbBdAIrsQLNnjQMklJ793CjZQNy73htJnU1NwxXiU=; b=C8kuC1LL98oeM8aIMmk+MXgZ9217C7GVnktd+aRxZm4Gyq7e5QYfJaMR85aC+HeyP/ ZUPTdw5pPo9qjtoC4cQP7gHsmyrEOenLPTe/0UMe8GUOQp/OSzZawxCUDVdcszWHBPJi Id3KSe8uQd6eocAd6J/3wo4U0g4lcO0r+WLSk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692931932; x=1693536732; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jYcbBdAIrsQLNnjQMklJ793CjZQNy73htJnU1NwxXiU=; b=JmBtXohQjGc6CSo2ue0D8StkeEijjN0dmBNqORoV6pTVPHMINpZT8VtOMh7f8kVGbh Rri4jcJo2pFwuyfBv3m9jcJR7RhaA8tzMohWIObXhHWaCFKPeUCF/d64NDD7rkZsg9+M ZNoaq8rWaMxlYya6ImPMDxk7LQG5EVU9JMZ0zcpChSnrNWN9JMl6wX/YVvbVYKEqSC0G w4khn9eFVCUfjPtWwlZQBob1R1HP1FHmVV899vGgi09zWIfA38TZlyghu3e1qGC6d9fh UDFkyyR69M60fNIraGkNb4XdHyo9d0GpPY6pT3lPt9ETuSwZZoyK+VoWI89KkX2UtFwV 7MQw== X-Gm-Message-State: AOJu0YyJgIbRaqUYoBR4XBd6DpiT2ElUvcBzq6PD45hbeG44XKRFpqfc 7WHWM2YE/9ejOTQRRPpUJJzV1A== X-Google-Smtp-Source: AGHT+IGJOPJ+CKWfPlqb86VYhTSiWBWSDpetoBBpmiTm1a4wgATGmNdDfSTC4SdW10SucR1xUBDCtw== X-Received: by 2002:a17:902:c612:b0:1bb:7b6c:983a with SMTP id r18-20020a170902c61200b001bb7b6c983amr15263225plr.59.1692931931907; Thu, 24 Aug 2023 19:52:11 -0700 (PDT) Received: from rekanorman3.syd.corp.google.com ([2401:fa00:9:14:9fe1:d4b1:42cc:882f]) by smtp.gmail.com with ESMTPSA id q10-20020a170902a3ca00b001bb0eebd90asm420847plb.245.2023.08.24.19.52.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 19:52:10 -0700 (PDT) From: Reka Norman To: Hans Verkuil Cc: Daisuke Nojiri , Neil Armstrong , Stefan Adolfsson , Reka Norman , Benson Leung , Guenter Roeck , Mauro Carvalho Chehab , chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH v2 6/9] media: cros-ec-cec: Support receiving messages from multiple ports Date: Fri, 25 Aug 2023 12:43:59 +1000 Message-ID: <20230825024735.1443836-7-rekanorman@chromium.org> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog In-Reply-To: <20230825024735.1443836-1-rekanorman@chromium.org> References: <20230825024735.1443836-1-rekanorman@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently, received messages are sent from the EC in the cec_message MKBP event. Since the size of ec_response_get_next_data_v1 is 16 bytes, which is also the maximum size of a CEC message, there is no space to add a port parameter. Increasing the size of ec_response_get_next_data_v1 is an option, but this would increase EC-kernel traffic for all MKBP event types. Instead, use an event to notify that data is ready, and add a new read command to read the data. For backwards compatibility with old EC firmware, continue to handle cec_message events as well. Signed-off-by: Reka Norman --- (no changes since v1) .../media/cec/platform/cros-ec/cros-ec-cec.c | 59 +++++++++++++++++-- .../linux/platform_data/cros_ec_commands.h | 23 ++++++++ 2 files changed, 76 insertions(+), 6 deletions(-) diff --git a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c index 18f78b7e034a..6989e63c05be 100644 --- a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c +++ b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c @@ -59,19 +59,63 @@ struct cros_ec_cec { struct cros_ec_cec_port *ports[EC_CEC_MAX_PORTS]; }; +static void cros_ec_cec_received_message(struct cros_ec_cec_port *port, + uint8_t *msg, uint8_t len) +{ + if (len > CEC_MAX_MSG_SIZE) + len = CEC_MAX_MSG_SIZE; + + port->rx_msg.len = len; + memcpy(port->rx_msg.msg, msg, len); + + cec_received_msg(port->adap, &port->rx_msg); +} + static void handle_cec_message(struct cros_ec_cec *cros_ec_cec) { struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec; uint8_t *cec_message = cros_ec->event_data.data.cec_message; unsigned int len = cros_ec->event_size; - struct cros_ec_cec_port *port = cros_ec_cec->ports[CEC_PORT]; + struct cros_ec_cec_port *port; + /* + * There are two ways of receiving CEC messages: + * 1. Old EC firmware which only supports one port sends the data in a + * cec_message MKBP event. + * 2. New EC firmware which supports multiple ports uses + * EC_MKBP_CEC_HAVE_DATA to notify that data is ready and + * EC_CMD_CEC_READ_MSG to read it. + * Check that the EC only has one CEC port, and then we can assume the + * message is from port 0. + */ + if (cros_ec_cec->num_ports != 1) { + dev_err(cros_ec->dev, + "received cec_message on device with %d ports\n", + cros_ec_cec->num_ports); + return; + } + port = cros_ec_cec->ports[0]; - if (len > CEC_MAX_MSG_SIZE) - len = CEC_MAX_MSG_SIZE; - port->rx_msg.len = len; - memcpy(port->rx_msg.msg, cec_message, len); + cros_ec_cec_received_message(port, cec_message, len); +} - cec_received_msg(port->adap, &port->rx_msg); +static void cros_ec_cec_read_message(struct cros_ec_cec_port *port) +{ + struct cros_ec_device *cros_ec = port->cros_ec_cec->cros_ec; + struct ec_params_cec_read params = { + .port = port->port_num, + }; + struct ec_response_cec_read response; + int ret; + + ret = cros_ec_cmd(cros_ec, 0, EC_CMD_CEC_READ_MSG, ¶ms, + sizeof(params), &response, sizeof(response)); + if (ret < 0) { + dev_err(cros_ec->dev, + "error reading CEC message on EC: %d\n", ret); + return; + } + + cros_ec_cec_received_message(port, response.msg, response.msg_len); } static void handle_cec_event(struct cros_ec_cec *cros_ec_cec) @@ -97,6 +141,9 @@ static void handle_cec_event(struct cros_ec_cec *cros_ec_cec) cec_transmit_attempt_done(port->adap, CEC_TX_STATUS_MAX_RETRIES | CEC_TX_STATUS_NACK); + + if (events & EC_MKBP_CEC_HAVE_DATA) + cros_ec_cec_read_message(port); } static int cros_ec_cec_event(struct notifier_block *nb, diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h index b7e8573a8a49..ad61c7ff0b28 100644 --- a/include/linux/platform_data/cros_ec_commands.h +++ b/include/linux/platform_data/cros_ec_commands.h @@ -4473,6 +4473,27 @@ struct ec_params_cec_write_v1 { uint8_t msg[MAX_CEC_MSG_LEN]; } __ec_align1; +/* CEC message read from a CEC bus reported back to the AP */ +#define EC_CMD_CEC_READ_MSG 0x00B9 + +/** + * struct ec_params_cec_read - Read a message from the CEC bus + * @port: CEC port to read a message on + */ +struct ec_params_cec_read { + uint8_t port; +} __ec_align1; + +/** + * struct ec_response_cec_read - Message read from the CEC bus + * @msg_len: length of msg in bytes + * @msg: message content read from the CEC bus + */ +struct ec_response_cec_read { + uint8_t msg_len; + uint8_t msg[MAX_CEC_MSG_LEN]; +} __ec_align1; + /* Set various CEC parameters */ #define EC_CMD_CEC_SET 0x00BA @@ -4529,6 +4550,8 @@ enum mkbp_cec_event { EC_MKBP_CEC_SEND_OK = BIT(0), /* Outgoing message was not acknowledged */ EC_MKBP_CEC_SEND_FAILED = BIT(1), + /* Incoming message can be read out by AP */ + EC_MKBP_CEC_HAVE_DATA = BIT(2), }; /*****************************************************************************/ From patchwork Fri Aug 25 02:44:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reka Norman X-Patchwork-Id: 13364965 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE86B7E0 for ; Fri, 25 Aug 2023 02:52:28 +0000 (UTC) Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-68bed28cb22so394278b3a.2 for ; Thu, 24 Aug 2023 19:52:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692931948; x=1693536748; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=m3+URBqZpZF2x77jWPMvlepFC5eyrNLor5lT2YRYaCA=; b=jwSGOFVLVU0xCoY5pLfoOIfVqNP8RbKX7XksFTPUAFAqV6iwheXJgNjC8ZtGGe6m1x CotQ0N88c1rbuo3NZtpi8JoLZhjBMz8TjxRUUiYVCMASj9wYBBpvCU/Yhl9LNYZRpeqt sNA4eLMBgnzgSrLHMhAFDs6rXjqpsxbWgdoVg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692931948; x=1693536748; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m3+URBqZpZF2x77jWPMvlepFC5eyrNLor5lT2YRYaCA=; b=VfKa2K7KdkqrQNt5QxSvq5FrFC47OB65uEdzE4czLR41BmVm2qoyGI4DMcHtnynuJ3 81aqCdv6Y9BtF9xv81K5laFUHDaLqgQpsogksHxP/vIz1dsn2vAM+ZOIGbcHI8SoSYnD IhEeWcPCKdDS8XCm+4LWKMNF2KtEfl6Q8/VWmFIjblkmubwVf2hyHfPKaO7thCsTBp81 qk+AwF7AqqtLcPCfQVjItIfGrlUuKcrYHY+KiZOWyEADFOA9f6fPdw45Wt+Zw2EU7xjk SJMFb8MqxtF4hdXplMm+5HB/ITudD5cCGEEwN1pW5z9xHeUuQtQc7mQc7KRYdXWKjeKR qEpA== X-Gm-Message-State: AOJu0YzYwNZ3aG9A94NCJELp6Yy5KPjtui2frdw9oLNtaLquu4ttaddm uzDNkijVt8fZgp3tFVB31QqfZg== X-Google-Smtp-Source: AGHT+IEC1VIJWj32bHEOO6xQnrTuBhX+AC88P89p+LUarmfmkZr7HIRKlDIkSrMR0GjJYmfbF0GsRw== X-Received: by 2002:a05:6a20:1447:b0:148:40cf:b832 with SMTP id a7-20020a056a20144700b0014840cfb832mr18251618pzi.18.1692931948099; Thu, 24 Aug 2023 19:52:28 -0700 (PDT) Received: from rekanorman3.syd.corp.google.com ([2401:fa00:9:14:9fe1:d4b1:42cc:882f]) by smtp.gmail.com with ESMTPSA id q10-20020a170902a3ca00b001bb0eebd90asm420847plb.245.2023.08.24.19.52.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 19:52:27 -0700 (PDT) From: Reka Norman To: Hans Verkuil Cc: Daisuke Nojiri , Neil Armstrong , Stefan Adolfsson , Reka Norman , Benson Leung , Guenter Roeck , Mauro Carvalho Chehab , chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH v2 7/9] media: cros-ec-cec: Allow specifying multiple HDMI connectors Date: Fri, 25 Aug 2023 12:44:00 +1000 Message-ID: <20230825024735.1443836-8-rekanorman@chromium.org> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog In-Reply-To: <20230825024735.1443836-1-rekanorman@chromium.org> References: <20230825024735.1443836-1-rekanorman@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Update the cec_dmi_match_table to allow specifying multiple HDMI connectors for each device. Signed-off-by: Reka Norman --- Changes in v2: - Use NULL-terminated arrays for the conns field of cec_dmi_match .../media/cec/platform/cros-ec/cros-ec-cec.c | 49 ++++++++++++------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c index 6989e63c05be..371699d599de 100644 --- a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c +++ b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c @@ -284,38 +284,43 @@ static SIMPLE_DEV_PM_OPS(cros_ec_cec_pm_ops, #if IS_ENABLED(CONFIG_PCI) && IS_ENABLED(CONFIG_DMI) /* - * The Firmware only handles a single CEC interface tied to a single HDMI - * connector we specify along with the DRM device name handling the HDMI output + * Specify the DRM device name handling the HDMI output and the HDMI connector + * corresponding to each CEC port. The order of connectors must match the order + * in the EC (first connector is EC port 0, ...), and the number of connectors + * must match the number of ports in the EC (which can be queried using the + * EC_CMD_CEC_PORT_COUNT host command). */ struct cec_dmi_match { const char *sys_vendor; const char *product_name; const char *devname; - const char *conn; + const char *const *conns; }; +static const char *const fizz_conns[] = { "Port B", NULL }; + static const struct cec_dmi_match cec_dmi_match_table[] = { /* Google Fizz */ - { "Google", "Fizz", "0000:00:02.0", "Port B" }, + { "Google", "Fizz", "0000:00:02.0", fizz_conns }, /* Google Brask */ - { "Google", "Brask", "0000:00:02.0", "Port B" }, + { "Google", "Brask", "0000:00:02.0", fizz_conns }, /* Google Moli */ - { "Google", "Moli", "0000:00:02.0", "Port B" }, + { "Google", "Moli", "0000:00:02.0", fizz_conns }, /* Google Kinox */ - { "Google", "Kinox", "0000:00:02.0", "Port B" }, + { "Google", "Kinox", "0000:00:02.0", fizz_conns }, /* Google Kuldax */ - { "Google", "Kuldax", "0000:00:02.0", "Port B" }, + { "Google", "Kuldax", "0000:00:02.0", fizz_conns }, /* Google Aurash */ - { "Google", "Aurash", "0000:00:02.0", "Port B" }, + { "Google", "Aurash", "0000:00:02.0", fizz_conns }, /* Google Gladios */ - { "Google", "Gladios", "0000:00:02.0", "Port B" }, + { "Google", "Gladios", "0000:00:02.0", fizz_conns }, /* Google Lisbon */ - { "Google", "Lisbon", "0000:00:02.0", "Port B" }, + { "Google", "Lisbon", "0000:00:02.0", fizz_conns }, }; static struct device *cros_ec_cec_find_hdmi_dev(struct device *dev, - const char **conn) + const char * const **conns) { int i; @@ -332,7 +337,7 @@ static struct device *cros_ec_cec_find_hdmi_dev(struct device *dev, if (!d) return ERR_PTR(-EPROBE_DEFER); put_device(d); - *conn = m->conn; + *conns = m->conns; return d; } } @@ -346,7 +351,7 @@ static struct device *cros_ec_cec_find_hdmi_dev(struct device *dev, #else static struct device *cros_ec_cec_find_hdmi_dev(struct device *dev, - const char **conn) + const char * const **conns) { return ERR_PTR(-ENODEV); } @@ -388,7 +393,7 @@ static int cros_ec_cec_get_write_cmd_version(struct cros_ec_cec *cros_ec_cec) static int cros_ec_cec_init_port(struct device *dev, struct cros_ec_cec *cros_ec_cec, int port_num, struct device *hdmi_dev, - const char *conn) + const char * const *conns) { struct cros_ec_cec_port *port; int ret; @@ -406,7 +411,13 @@ static int cros_ec_cec_init_port(struct device *dev, if (IS_ERR(port->adap)) return PTR_ERR(port->adap); - port->notify = cec_notifier_cec_adap_register(hdmi_dev, conn, + if (!conns[port_num]) { + dev_err(dev, "no conn for port %d\n", port_num); + ret = -ENODEV; + goto out_probe_adapter; + } + + port->notify = cec_notifier_cec_adap_register(hdmi_dev, conns[port_num], port->adap); if (!port->notify) { ret = -ENOMEM; @@ -435,10 +446,10 @@ static int cros_ec_cec_probe(struct platform_device *pdev) struct cros_ec_cec *cros_ec_cec; struct cros_ec_cec_port *port; struct device *hdmi_dev; - const char *conn = NULL; + const char * const *conns = NULL; int ret; - hdmi_dev = cros_ec_cec_find_hdmi_dev(&pdev->dev, &conn); + hdmi_dev = cros_ec_cec_find_hdmi_dev(&pdev->dev, &conns); if (IS_ERR(hdmi_dev)) return PTR_ERR(hdmi_dev); @@ -460,7 +471,7 @@ static int cros_ec_cec_probe(struct platform_device *pdev) for (int i = 0; i < cros_ec_cec->num_ports; i++) { ret = cros_ec_cec_init_port(&pdev->dev, cros_ec_cec, i, - hdmi_dev, conn); + hdmi_dev, conns); if (ret) goto unregister_ports; } From patchwork Fri Aug 25 02:44:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reka Norman X-Patchwork-Id: 13364966 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAE047E0 for ; Fri, 25 Aug 2023 02:53:14 +0000 (UTC) Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1c06f6f98c0so4584855ad.3 for ; Thu, 24 Aug 2023 19:53:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692931994; x=1693536794; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7dugPNPrpRp20Yd0O9nctENrWeeR3ORCR/xP4x4RAic=; b=kUsFiECEZpTrPQFc8F/uDF4rHYH4vybiNaFnPghtvyBKKmZ9Bje+SEjmmjEerhmzCl CYVBghYEA1/TUoIx5EEUOkcuwx53A+/kBvFdIoh711qp6sbLW0dgQqSjk9DiamKGlit+ 6vj+hK0sMuyscmmRkQ01q9gFDoU77NtaBIcYA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692931994; x=1693536794; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7dugPNPrpRp20Yd0O9nctENrWeeR3ORCR/xP4x4RAic=; b=FErnJcJBq0uuwhEFxjdJjv6dSCflZzMjSBd+wxPRld2rJ2373Teqov6Ua5Zz7T4XKw 8hE2NZhbf1vtbZKVN+cLPAoSZLX+4vKVPPlB/mmkPprAdv4t1v46nbko1/9vw36/msT2 msFZIEXzhY+eDe2NSfT99JH9FNKRORfB0+9NVVUsU/codtn52xvaYJN/D8noUOjV/x8+ GopOoPmr1pzZrfaCeHKu8/GFnzMuIN6R6HFLZH+RnG7ar3mNnNupp4y9b23mSWbk9jLn 3URGuZL4LO6CJ7OZa5g8+SrTKyDq1+hvrdoWaSnZkM+R3ePPJ9NmVNF39WMCpig3XUOq OeMQ== X-Gm-Message-State: AOJu0YxDwB4+IJAyiTf2DF4vZtopHW5MCqVn2cuPZeCXZInXTSobE6aG vLEv2jLdoCpUMEIW9cBKZwXV6w== X-Google-Smtp-Source: AGHT+IEkc7Xs+45n58w3dsFPGkMtOXljc3EaX3VUWt/vtWRbIjVktIboj9yBRphEmhsRVco1KvBeAg== X-Received: by 2002:a17:903:187:b0:1bd:b7ad:a584 with SMTP id z7-20020a170903018700b001bdb7ada584mr22007289plg.44.1692931994207; Thu, 24 Aug 2023 19:53:14 -0700 (PDT) Received: from rekanorman3.syd.corp.google.com ([2401:fa00:9:14:9fe1:d4b1:42cc:882f]) by smtp.gmail.com with ESMTPSA id q10-20020a170902a3ca00b001bb0eebd90asm420847plb.245.2023.08.24.19.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 19:53:13 -0700 (PDT) From: Reka Norman To: Hans Verkuil Cc: Daisuke Nojiri , Neil Armstrong , Stefan Adolfsson , Reka Norman , Benson Leung , Guenter Roeck , Mauro Carvalho Chehab , chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH v2 8/9] media: cros-ec-cec: Get number of CEC ports from EC Date: Fri, 25 Aug 2023 12:44:01 +1000 Message-ID: <20230825024735.1443836-9-rekanorman@chromium.org> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog In-Reply-To: <20230825024735.1443836-1-rekanorman@chromium.org> References: <20230825024735.1443836-1-rekanorman@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a new CEC port count host command and use it to query the number of CEC ports from the EC. If the host command is not supported then it must be old EC firmware which only supports one port, so fall back to assuming one port. This patch completes support for multiple ports in cros-ec-cec. Signed-off-by: Reka Norman --- (no changes since v1) .../media/cec/platform/cros-ec/cros-ec-cec.c | 40 ++++++++++++++++--- .../linux/platform_data/cros_ec_commands.h | 11 +++++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c index 371699d599de..993deb85d3e2 100644 --- a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c +++ b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c @@ -21,10 +21,6 @@ #define DRV_NAME "cros-ec-cec" -/* Only one port is supported for now */ -#define CEC_NUM_PORTS 1 -#define CEC_PORT 0 - /** * struct cros_ec_cec_port - Driver data for a single EC CEC port * @@ -358,6 +354,38 @@ static struct device *cros_ec_cec_find_hdmi_dev(struct device *dev, #endif +static int cros_ec_cec_get_num_ports(struct cros_ec_cec *cros_ec_cec) +{ + struct ec_response_cec_port_count response; + int ret; + + ret = cros_ec_cmd(cros_ec_cec->cros_ec, 0, EC_CMD_CEC_PORT_COUNT, NULL, + 0, &response, sizeof(response)); + if (ret < 0) { + /* + * Old EC firmware only supports one port and does not support + * the port count command, so fall back to assuming one port. + */ + cros_ec_cec->num_ports = 1; + return 0; + } + + if (response.port_count == 0) { + dev_err(cros_ec_cec->cros_ec->dev, + "EC reports 0 CEC ports\n"); + return -ENODEV; + } + + if (response.port_count > EC_CEC_MAX_PORTS) { + dev_err(cros_ec_cec->cros_ec->dev, + "EC reports too many ports: %d\n", response.port_count); + return -EINVAL; + } + + cros_ec_cec->num_ports = response.port_count; + return 0; +} + static int cros_ec_cec_get_write_cmd_version(struct cros_ec_cec *cros_ec_cec) { struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec; @@ -463,7 +491,9 @@ static int cros_ec_cec_probe(struct platform_device *pdev) device_init_wakeup(&pdev->dev, 1); - cros_ec_cec->num_ports = CEC_NUM_PORTS; + ret = cros_ec_cec_get_num_ports(cros_ec_cec); + if (ret) + return ret; ret = cros_ec_cec_get_write_cmd_version(cros_ec_cec); if (ret) diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h index ad61c7ff0b28..7dae17b62a4d 100644 --- a/include/linux/platform_data/cros_ec_commands.h +++ b/include/linux/platform_data/cros_ec_commands.h @@ -4536,6 +4536,17 @@ struct ec_response_cec_get { uint8_t val; } __ec_align1; +/* Get the number of CEC ports */ +#define EC_CMD_CEC_PORT_COUNT 0x00C1 + +/** + * struct ec_response_cec_port_count - CEC port count response + * @port_count: number of CEC ports + */ +struct ec_response_cec_port_count { + uint8_t port_count; +} __ec_align1; + /* CEC parameters command */ enum cec_command { /* CEC reading, writing and events enable */ From patchwork Fri Aug 25 02:44:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reka Norman X-Patchwork-Id: 13364967 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CEB9A7E0 for ; Fri, 25 Aug 2023 02:53:28 +0000 (UTC) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1bf078d5f33so4732385ad.3 for ; Thu, 24 Aug 2023 19:53:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692932008; x=1693536808; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ka8P5b/GzyZWqOM50pHONHl9tEIZnwSQ0LsDJccYJvI=; b=BzlEs8cAdigCMb3vJPqRNzIb1J1HMXhrk6+GbBQGA0k1l767wGfP7XvKmyt9yAyOSA 4etFUTYoIV32HK7WWxK7y/MW35VnO29t51VsENsZjk8D0lNdCawf9uRWsfhEM9kerzDP pqrTeOgtNfEw/WuzoRZxu8+I4r+gFLu83Og5A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692932008; x=1693536808; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ka8P5b/GzyZWqOM50pHONHl9tEIZnwSQ0LsDJccYJvI=; b=f0NLSTmLLLwkJGBOVh8TpW61PlR70dKwKn+c8R0VDM4eZ74UrVdhjWGobwDIOJTP06 vRtCP1Lq7qghxTpMad1jFj456H8Rc7APDRjE5+2qBHXRejmHO0lXzd8Vyvr9uWsBCxhG BX5NRjScD4U7z3YRzK81J4RGWepcaWDLTbKNuzWx+/4MfXDzqqKHSWbP9BxlETj93TNs CKPHGZxxMei/463s3BvNnAy+fwplwG0ixTE/aPDuUZTDK8COxaw7eThz5H04zL3xby2K khYE6Ka1oH9dkQh6hTCwujhSkM7Tv8dNTq9bjTkyRDfwGeQwWkNQTkBt2zZNpxfooVq5 jgEw== X-Gm-Message-State: AOJu0YxB7MWoD12j3f4qszFeIyv0L/x4m+a/a6rZJ6plNHveUFVUNT+0 4HnvSL6uNp8q85wLfWYAiXqKVw== X-Google-Smtp-Source: AGHT+IH938af/Jkw37fRHmw130aKNQYszXvCGp+5zNX3Tkto4r7N0993i9603PTTX5fDrm5uQLkqvg== X-Received: by 2002:a17:902:f54b:b0:1b8:92fc:7429 with SMTP id h11-20020a170902f54b00b001b892fc7429mr20923761plf.53.1692932008269; Thu, 24 Aug 2023 19:53:28 -0700 (PDT) Received: from rekanorman3.syd.corp.google.com ([2401:fa00:9:14:9fe1:d4b1:42cc:882f]) by smtp.gmail.com with ESMTPSA id q10-20020a170902a3ca00b001bb0eebd90asm420847plb.245.2023.08.24.19.53.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 19:53:27 -0700 (PDT) From: Reka Norman To: Hans Verkuil Cc: Daisuke Nojiri , Neil Armstrong , Stefan Adolfsson , Reka Norman , Benson Leung , Guenter Roeck , Mauro Carvalho Chehab , chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH v2 9/9] media: cros-ec-cec: Add Dibbi to the match table Date: Fri, 25 Aug 2023 12:44:02 +1000 Message-ID: <20230825024735.1443836-10-rekanorman@chromium.org> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog In-Reply-To: <20230825024735.1443836-1-rekanorman@chromium.org> References: <20230825024735.1443836-1-rekanorman@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Dibbi has two HDMI ports which support CEC: Port D is EC port 0 Port B is EC port 1 Signed-off-by: Reka Norman --- Changes in v2: - Use a NULL-terminated conns array for the Dibbi match table entry drivers/media/cec/platform/cros-ec/cros-ec-cec.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c index 993deb85d3e2..21361eff50ff 100644 --- a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c +++ b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c @@ -295,6 +295,7 @@ struct cec_dmi_match { }; static const char *const fizz_conns[] = { "Port B", NULL }; +static const char *const dibbi_conns[] = { "Port D", "Port B", NULL }; static const struct cec_dmi_match cec_dmi_match_table[] = { /* Google Fizz */ @@ -313,6 +314,8 @@ static const struct cec_dmi_match cec_dmi_match_table[] = { { "Google", "Gladios", "0000:00:02.0", fizz_conns }, /* Google Lisbon */ { "Google", "Lisbon", "0000:00:02.0", fizz_conns }, + /* Google Dibbi */ + { "Google", "Dibbi", "0000:00:02.0", dibbi_conns }, }; static struct device *cros_ec_cec_find_hdmi_dev(struct device *dev,