From nobody Thu Dec 18 09:44:19 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4872EE49A6 for ; Fri, 25 Aug 2023 02:50:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240755AbjHYCu3 (ORCPT ); Thu, 24 Aug 2023 22:50:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237970AbjHYCuP (ORCPT ); Thu, 24 Aug 2023 22:50:15 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E83781FD2 for ; Thu, 24 Aug 2023 19:50:13 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1bdf4752c3cso4289325ad.2 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=AF1SHE93QMNW+qm8smpjZbyldhmV1M1z93A9Nu+caq3HvJGDkTts78OUilf9M3PIHF 5uoRBPh/MVoBJSwhUnfN93g/sKgo+A938GUWugJCARNGIYymLehifnErxu4gj24I8eXK ug3T1YRgA3tmUURXhthwI8BZak9r/SExgmQZT7S0cEw5Elc9tE4OsMJtnR/5Mvu7e9x6 OSOdJlfZxGIFDKGYkZPENsXpvgG62Un6Gx0Wsc9nrUeceqOY4Mt3+tvBS3xmz0gfTc33 CSIDiKG7XP9eLH7ODdVWHDiHR2K2MYLVYYp0feykmHPyx7LZc/3elZjY1f0plzkLkxD2 HQ+Q== X-Gm-Message-State: AOJu0YxzYSz+PhBZNWLNUD7oRACLxR+WrXcZo1ksb4AxGqhj4le3KOC4 DS6FSvPxebHdvnvygcT/qBytUw== 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> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/med= ia/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 =3D adap->priv; struct cros_ec_device *cros_ec =3D cros_ec_cec->cros_ec; - struct { - struct cros_ec_command msg; - struct ec_params_cec_set data; - } __packed msg =3D {}; + struct ec_params_cec_set params =3D { + .cmd =3D CEC_CMD_LOGICAL_ADDRESS, + .val =3D logical_addr, + }; int ret; =20 - msg.msg.command =3D EC_CMD_CEC_SET; - msg.msg.outsize =3D sizeof(msg.data); - msg.data.cmd =3D CEC_CMD_LOGICAL_ADDRESS; - msg.data.val =3D logical_addr; - - ret =3D cros_ec_cmd_xfer_status(cros_ec, &msg.msg); + ret =3D 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 *a= dap, u8 attempts, { struct cros_ec_cec *cros_ec_cec =3D adap->priv; struct cros_ec_device *cros_ec =3D cros_ec_cec->cros_ec; - struct { - struct cros_ec_command msg; - struct ec_params_cec_write data; - } __packed msg =3D {}; + struct ec_params_cec_write params; int ret; =20 - msg.msg.command =3D EC_CMD_CEC_WRITE_MSG; - msg.msg.outsize =3D cec_msg->len; - memcpy(msg.data.msg, cec_msg->msg, cec_msg->len); + memcpy(params.msg, cec_msg->msg, cec_msg->len); =20 - ret =3D cros_ec_cmd_xfer_status(cros_ec, &msg.msg); + ret =3D 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 =3D adap->priv; struct cros_ec_device *cros_ec =3D cros_ec_cec->cros_ec; - struct { - struct cros_ec_command msg; - struct ec_params_cec_set data; - } __packed msg =3D {}; + struct ec_params_cec_set params =3D { + .cmd =3D CEC_CMD_ENABLE, + .val =3D enable, + }; int ret; =20 - msg.msg.command =3D EC_CMD_CEC_SET; - msg.msg.outsize =3D sizeof(msg.data); - msg.data.cmd =3D CEC_CMD_ENABLE; - msg.data.val =3D enable; - - ret =3D cros_ec_cmd_xfer_status(cros_ec, &msg.msg); + ret =3D 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", --=20 2.42.0.rc2.253.gd59a3bf2b4-goog From nobody Thu Dec 18 09:44:19 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2DB5C88CB2 for ; Fri, 25 Aug 2023 02:51:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240023AbjHYCu7 (ORCPT ); Thu, 24 Aug 2023 22:50:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242054AbjHYCuo (ORCPT ); Thu, 24 Aug 2023 22:50:44 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 682241FD9 for ; Thu, 24 Aug 2023 19:50:42 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1bf3a2f4528so4571445ad.2 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=GwK/j313aFqOErDhdXzirGQp90OegHB1U0cAJuBQXUQb7FpxkukCgAbG8tRi2xDcN1 /f1XN3ySRzFiVYbkLnPTZOn5gI8Usvw+acCoFBYNcA4lTtVLL+dghN8NbFDU+6J0mDqy IhjjSQjCjVNOFNA+Fv9cPESBhBwQwG0uBcu7J7ZiXdLEbKdt/K6JhIPTZ7A//q6DDq2h ovXRjl3Ngzq3UstOeU2+6jiWnGLmX4ACvFKavK+C9lJEwV48UYgOA+Ils9MDBHOCMeFX EEztQ2KxYYcl2UuTweVxsoLgyHzuPLHuweoyJ1cRdvlEnOuSal8dcGGzIQI/576RRm6r WNUw== X-Gm-Message-State: AOJu0YymI27szP2zNYdJAUlSS1zh/Id5CIylz1263Epo4kTwSEpWaVKv jo3HxgXsVwJTxRseg/Hm2yN7YA== 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> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/med= ia/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 @@ =20 #define DRV_NAME "cros-ec-cec" =20 +/* 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]; }; =20 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 =3D cros_ec_cec->cros_ec; uint8_t *cec_message =3D cros_ec->event_data.data.cec_message; unsigned int len =3D cros_ec->event_size; + struct cros_ec_cec_port *port =3D cros_ec_cec->ports[CEC_PORT]; =20 if (len > CEC_MAX_MSG_SIZE) len =3D CEC_MAX_MSG_SIZE; - cros_ec_cec->rx_msg.len =3D len; - memcpy(cros_ec_cec->rx_msg.msg, cec_message, len); + port->rx_msg.len =3D len; + memcpy(port->rx_msg.msg, cec_message, len); =20 - cec_received_msg(cros_ec_cec->adap, &cros_ec_cec->rx_msg); + cec_received_msg(port->adap, &port->rx_msg); } =20 static void handle_cec_event(struct cros_ec_cec *cros_ec_cec) { struct cros_ec_device *cros_ec =3D cros_ec_cec->cros_ec; uint32_t events =3D cros_ec->event_data.data.cec_events; + struct cros_ec_cec_port *port =3D cros_ec_cec->ports[CEC_PORT]; =20 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); =20 /* 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, =20 static int cros_ec_cec_set_log_addr(struct cec_adapter *adap, u8 logical_a= ddr) { - struct cros_ec_cec *cros_ec_cec =3D adap->priv; + struct cros_ec_cec_port *port =3D adap->priv; + struct cros_ec_cec *cros_ec_cec =3D port->cros_ec_cec; struct cros_ec_device *cros_ec =3D cros_ec_cec->cros_ec; struct ec_params_cec_set params =3D { .cmd =3D 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 =3D adap->priv; + struct cros_ec_cec_port *port =3D adap->priv; + struct cros_ec_cec *cros_ec_cec =3D port->cros_ec_cec; struct cros_ec_device *cros_ec =3D 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 *ada= p, u8 attempts, =20 static int cros_ec_cec_adap_enable(struct cec_adapter *adap, bool enable) { - struct cros_ec_cec *cros_ec_cec =3D adap->priv; + struct cros_ec_cec_port *port =3D adap->priv; + struct cros_ec_cec *cros_ec_cec =3D port->cros_ec_cec; struct cros_ec_device *cros_ec =3D cros_ec_cec->cros_ec; struct ec_params_cec_set params =3D { .cmd =3D CEC_CMD_ENABLE, @@ -260,11 +283,55 @@ static struct device *cros_ec_cec_find_hdmi_dev(struc= t device *dev, =20 #endif =20 +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 =3D devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + if (!port) + return -ENOMEM; + + port->cros_ec_cec =3D cros_ec_cec; + port->port_num =3D port_num; + + port->adap =3D 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 =3D cec_notifier_cec_adap_register(hdmi_dev, conn, + port->adap); + if (!port->notify) { + ret =3D -ENOMEM; + goto out_probe_adapter; + } + + ret =3D cec_register_adapter(port->adap, dev); + if (ret < 0) + goto out_probe_notify; + + cros_ec_cec->ports[port_num] =3D 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 =3D dev_get_drvdata(pdev->dev.parent); struct cros_ec_device *cros_ec =3D ec_dev->ec_dev; struct cros_ec_cec *cros_ec_cec; + struct cros_ec_cec_port *port; struct device *hdmi_dev; const char *conn =3D NULL; int ret; @@ -283,18 +350,13 @@ static int cros_ec_cec_probe(struct platform_device *= pdev) =20 device_init_wakeup(&pdev->dev, 1); =20 - cros_ec_cec->adap =3D 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 =3D CEC_NUM_PORTS; =20 - cros_ec_cec->notify =3D cec_notifier_cec_adap_register(hdmi_dev, conn, - cros_ec_cec->adap); - if (!cros_ec_cec->notify) { - ret =3D -ENOMEM; - goto out_probe_adapter; + for (int i =3D 0; i < cros_ec_cec->num_ports; i++) { + ret =3D cros_ec_cec_init_port(&pdev->dev, cros_ec_cec, i, + hdmi_dev, conn); + if (ret) + goto unregister_ports; } =20 /* 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; } =20 - ret =3D cec_register_adapter(cros_ec_cec->adap, &pdev->dev); - if (ret < 0) - goto out_probe_notify; - return 0; =20 -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 =3D 0; i < cros_ec_cec->num_ports; i++) { + port =3D cros_ec_cec->ports[i]; + if (!port) + break; + cec_notifier_cec_adap_unregister(port->notify, port->adap); + cec_unregister_adapter(port->adap); + } return ret; } =20 @@ -324,6 +390,7 @@ static void cros_ec_cec_remove(struct platform_device *= pdev) { struct cros_ec_cec *cros_ec_cec =3D platform_get_drvdata(pdev); struct device *dev =3D &pdev->dev; + struct cros_ec_cec_port *port; int ret; =20 /* @@ -337,9 +404,11 @@ static void cros_ec_cec_remove(struct platform_device = *pdev) if (ret) dev_err(dev, "failed to unregister notifier\n"); =20 - cec_notifier_cec_adap_unregister(cros_ec_cec->notify, - cros_ec_cec->adap); - cec_unregister_adapter(cros_ec_cec->adap); + for (int i =3D 0; i < cros_ec_cec->num_ports; i++) { + port =3D cros_ec_cec->ports[i]; + cec_notifier_cec_adap_unregister(port->notify, port->adap); + cec_unregister_adapter(port->adap); + } } =20 static struct platform_driver cros_ec_cec_driver =3D { 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 */ =20 +#define EC_CEC_MAX_PORTS 16 + #define MAX_CEC_MSG_LEN 16 =20 /* CEC message from the AP to be written on the CEC bus */ --=20 2.42.0.rc2.253.gd59a3bf2b4-goog From nobody Thu Dec 18 09:44:19 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91AABC6FA8F for ; Fri, 25 Aug 2023 02:51:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240898AbjHYCv2 (ORCPT ); Thu, 24 Aug 2023 22:51:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242465AbjHYCvO (ORCPT ); Thu, 24 Aug 2023 22:51:14 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E9822100 for ; Thu, 24 Aug 2023 19:51:05 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-68a410316a2so442136b3a.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=UNCYn533UOBf9f/GiMiYQKgXjk5DMVT7jELHg7cbSvZA5fUK4uGWXy4M+Pzhg8m8yu Ml3hA2d4/UkyRHdl6eIlWXUCox4POJq+mgLK7848XtX+Zb7bapR3imOdvgEUCLwFutKr Mza4H8PpL85nbGfpOJu7NwXPFVuTIH/2Uz5FGgXfJPa6UFPgjM9+bDrQmVG7KR1wZc9F gva2+BOy3LasEsYjNQpbHv3lxawD8hjQWNsSbhi8/YO+xtheVUUaQkhlGFsGT13t7/z4 4G/maEM7/Z/kGlmwjWF3M1hMai6lotGUErQaNrVBW5NuCPzqIx6PXa+LpYIJhznknA3S E8bA== X-Gm-Message-State: AOJu0YzH/NpyuuAXjFChdWAYUlgBJe18SmloVJaBEBcu9ud7EKuZYzGQ Pv7u3QqynrFvCBT39RtieMzlIq59SYBMhiDo1nk= 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> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/med= ia/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 =3D cros_ec_cec->cros_ec; struct ec_params_cec_set params =3D { .cmd =3D CEC_CMD_LOGICAL_ADDRESS, + .port =3D port->port_num, .val =3D 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 =3D cros_ec_cec->cros_ec; struct ec_params_cec_set params =3D { .cmd =3D CEC_CMD_ENABLE, + .port =3D port->port_num, .val =3D 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; =20 @@ -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; =20 /** --=20 2.42.0.rc2.253.gd59a3bf2b4-goog From nobody Thu Dec 18 09:44:19 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C1CAEE49A0 for ; Fri, 25 Aug 2023 02:53:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237091AbjHYCwc (ORCPT ); Thu, 24 Aug 2023 22:52:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242629AbjHYCv6 (ORCPT ); Thu, 24 Aug 2023 22:51:58 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1CB2212A for ; Thu, 24 Aug 2023 19:51:23 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1bdc243d62bso4298045ad.3 for ; Thu, 24 Aug 2023 19:51:23 -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=QIC2dy5gwvdCdXtRe3skVAMhIYQIOA3C7tCvf4kQxyBLtgFvircw0B3CCA7Vc85muA hmD+wyzp7gi3E9aOvcE96eLBUoVjDBBSBT1PTYI7Nc6gXC4ybFas2a7Qs1CT7N1nZe3D /tHwWgRVXpWdViW/fiqqIKld0WsgnUEGu/pa8IJoS69LSMA46JyPzesmfNFmRVw4Bye9 tNRTtGK/2FF+UixeJ5FlG8u3mrki0Qrg+2br7dzsz4pXWsjRtA/AYdXymRwT9wcNr6Ge PHC3UoanfQXb6t5FL7Rc3jg8SXXN/7SwvVxL2Et1x7f0N9tTE3JqaJN2ZksUowlGy/Bf RAWg== X-Gm-Message-State: AOJu0YwsEB5RMe6pgYUefnOV7jMJKxfTHszGtYp9Fdm2lRGoOa7pdnuL gfmh9QhXIKxQ6QiAxRxY7v89Bg== 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> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/med= ia/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 *a= dap, u8 attempts, struct cros_ec_cec *cros_ec_cec =3D port->cros_ec_cec; struct cros_ec_device *cros_ec =3D cros_ec_cec->cros_ec; struct ec_params_cec_write params; + struct ec_params_cec_write_v1 params_v1; int ret; =20 - memcpy(params.msg, cec_msg->msg, cec_msg->len); + if (cros_ec_cec->write_cmd_version =3D=3D 0) { + memcpy(params.msg, cec_msg->msg, cec_msg->len); + ret =3D cros_ec_cmd(cros_ec, 0, EC_CMD_CEC_WRITE_MSG, ¶ms, + cec_msg->len, NULL, 0); + } else { + params_v1.port =3D port->port_num; + params_v1.msg_len =3D cec_msg->len; + memcpy(params_v1.msg, cec_msg->msg, cec_msg->len); + ret =3D cros_ec_cmd(cros_ec, cros_ec_cec->write_cmd_version, + EC_CMD_CEC_WRITE_MSG, ¶ms_v1, + sizeof(params_v1), NULL, 0); + } =20 - ret =3D 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, =20 #endif =20 +static int cros_ec_cec_get_write_cmd_version(struct cros_ec_cec *cros_ec_c= ec) +{ + struct cros_ec_device *cros_ec =3D cros_ec_cec->cros_ec; + struct ec_params_get_cmd_versions_v1 params =3D { + .cmd =3D EC_CMD_CEC_WRITE_MSG, + }; + struct ec_response_get_cmd_versions response; + int ret; + + ret =3D 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 =3D 1; + } else { + if (cros_ec_cec->num_ports !=3D 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 =3D 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 *p= dev) =20 cros_ec_cec->num_ports =3D CEC_NUM_PORTS; =20 + ret =3D cros_ec_cec_get_write_cmd_version(cros_ec_cec); + if (ret) + return ret; + for (int i =3D 0; i < cros_ec_cec->num_ports; i++) { ret =3D 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; =20 +/** + * 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 =20 --=20 2.42.0.rc2.253.gd59a3bf2b4-goog From nobody Thu Dec 18 09:44:19 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C419C6FA8F for ; Fri, 25 Aug 2023 02:53:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241163AbjHYCwd (ORCPT ); Thu, 24 Aug 2023 22:52:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242407AbjHYCwR (ORCPT ); Thu, 24 Aug 2023 22:52:17 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49C3B2100 for ; Thu, 24 Aug 2023 19:51:45 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-68a41035828so422268b3a.1 for ; Thu, 24 Aug 2023 19:51:45 -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=WbWUtmPF4GDWpy0r6BBfwTIoE1G0s/SQxw3pgGdYRvFYiOo/J8vGPmCFeK2MoYWxrP z/NlHt/JEFiJ+WrsFTlISvl226kaIMnvt+eIy25UaD7xPoGhP3HkalMsJGIqNJ8WsQXr g3ukBD3nn5oXKGyt+UEH58ENCCjKd8L7pmXb4sflbE415rF7o4mmXhpaWUoLpY4W3SdQ zk9TIyN+0+QIBisTXcns3dwy9jcp6l7T+yukxVfOixNhx65OX7qzqte5QPApXG+jocdN q4/CaNrMSQc7R5nid5+47XSRRFd4LjdKL763ELilVC7ahfeWMtl4KNssY6fWZsr/eAhH qkXA== X-Gm-Message-State: AOJu0YyU3Op9HluFQ0Acti5JEyTvgZQECQKmJPBeoLg6FsK2XC1k08GE K/BzeZFN1cJ7o5okD02aqtm1ww== 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> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/med= ia/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 =3D cros_ec_cec->cros_ec; - uint32_t events =3D cros_ec->event_data.data.cec_events; - struct cros_ec_cec_port *port =3D cros_ec_cec->ports[CEC_PORT]; + uint32_t cec_events =3D cros_ec->event_data.data.cec_events; + uint32_t port_num =3D EC_MKBP_EVENT_CEC_GET_PORT(cec_events); + uint32_t events =3D EC_MKBP_EVENT_CEC_GET_EVENTS(cec_events); + struct cros_ec_cec_port *port; + + if (port_num >=3D cros_ec_cec->num_ports) { + dev_err(cros_ec->dev, + "received CEC event for invalid port %d\n", port_num); + return; + } + port =3D cros_ec_cec->ports[port_num]; =20 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 { =20 #define MAX_CEC_MSG_LEN 16 =20 +/* + * 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 =20 --=20 2.42.0.rc2.253.gd59a3bf2b4-goog From nobody Thu Dec 18 09:44:19 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40BB8EE49A0 for ; Fri, 25 Aug 2023 02:53:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241765AbjHYCxH (ORCPT ); Thu, 24 Aug 2023 22:53:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242403AbjHYCwl (ORCPT ); Thu, 24 Aug 2023 22:52:41 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8506B2108 for ; Thu, 24 Aug 2023 19:52:12 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1bc3d94d40fso4502635ad.3 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=PDN9bcG3UOwgcK99n8LOm9pxov+WNfRcp4Q3eaKoU5ClEJsFp8qX4JnR5bGGimMxZu jMw0PcfoFZQMRWhK4QL8t14Uu9IOh2/CEl0hGYEsjif1KfT78JKNiW2/pLovEg1Dx3Li zoM/essSnkFHiWQXHNiXMVYbKohXHnfegjE43slCwLP/Pbc6SLQscijqp6JYmXMM/1JN 3o5EGQpIQ/WXs97OcbU8PZ02XzV27W/TU4bHFRbVG+2pKklgt/tCLL/gEwybKyyYHrNW RMgZPwfKpQlR0WxbEnbakBg45pKLj05v4vr8fuiOKt/dgqCzyrbfBM9xg++j4O9fDdXX sB0g== X-Gm-Message-State: AOJu0YzQVbacsaP/iltaR9U4AHLcRg1SKCy0P4DiCrYaAtfbeGfM/XuL 4M4dAUg2vEJ3xut4ZeWJdiDVeQ== 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> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/med= ia/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]; }; =20 +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 =3D CEC_MAX_MSG_SIZE; + + port->rx_msg.len =3D 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 =3D cros_ec_cec->cros_ec; uint8_t *cec_message =3D cros_ec->event_data.data.cec_message; unsigned int len =3D cros_ec->event_size; - struct cros_ec_cec_port *port =3D 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 !=3D 1) { + dev_err(cros_ec->dev, + "received cec_message on device with %d ports\n", + cros_ec_cec->num_ports); + return; + } + port =3D cros_ec_cec->ports[0]; =20 - if (len > CEC_MAX_MSG_SIZE) - len =3D CEC_MAX_MSG_SIZE; - port->rx_msg.len =3D len; - memcpy(port->rx_msg.msg, cec_message, len); + cros_ec_cec_received_message(port, cec_message, len); +} =20 - 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 =3D port->cros_ec_cec->cros_ec; + struct ec_params_cec_read params =3D { + .port =3D port->port_num, + }; + struct ec_response_cec_read response; + int ret; + + ret =3D 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); } =20 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); } =20 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; =20 +/* 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 =20 @@ -4529,6 +4550,8 @@ enum mkbp_cec_event { EC_MKBP_CEC_SEND_OK =3D BIT(0), /* Outgoing message was not acknowledged */ EC_MKBP_CEC_SEND_FAILED =3D BIT(1), + /* Incoming message can be read out by AP */ + EC_MKBP_CEC_HAVE_DATA =3D BIT(2), }; =20 /*************************************************************************= ****/ --=20 2.42.0.rc2.253.gd59a3bf2b4-goog From nobody Thu Dec 18 09:44:19 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30EB7C6FA8F for ; Fri, 25 Aug 2023 02:53:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237162AbjHYCxE (ORCPT ); Thu, 24 Aug 2023 22:53:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242773AbjHYCw6 (ORCPT ); Thu, 24 Aug 2023 22:52:58 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 896F3268E for ; Thu, 24 Aug 2023 19:52:29 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-68a4bcf8a97so401284b3a.1 for ; Thu, 24 Aug 2023 19:52:29 -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=G8nUdCQWwapph1mOH3ShXT6vdBX/6Fz9beFixdrWoCxbhjelf3ycg6gjoWwnB8JR02 KhdFMqFuoYRnjgwqcIwF7j5+8Lqob99qK7iPK/m6lXw57oEI52LxHqbMiLK+NAfZFvIH FKw/nz0LBm/g/ebse1ANiesPP5Mx9HH0HzGhZOUkz3l/N6qVXLsV3KSFteBIJsn1G2TT c8CGs/UZtQvbYu58/42kwXYFE+sKq49r/u4nt7XJ8OrLb50Wq7b+oGsjPEtPrKp03S2t QqKwVpgp/UkczaFzUhAv0LSTIxmVWohrK82abhY1K3ItzhSRCxZQD0JLnftIlo1okOC7 BeEg== X-Gm-Message-State: AOJu0Yx5D85ne7Kf0N7izt3BCVQgr9119M1Njmgw0GCD8Y5PzvKQMyHM M/t86js7RWcZllWdjPJdJEs66A== 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> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/med= ia/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) =20 /* - * 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 o= utput + * Specify the DRM device name handling the HDMI output and the HDMI conne= ctor + * 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 connec= tors + * must match the number of ports in the EC (which can be queried using the + * EC_CMD_CEC_PORT_COUNT host command). */ =20 struct cec_dmi_match { const char *sys_vendor; const char *product_name; const char *devname; - const char *conn; + const char *const *conns; }; =20 +static const char *const fizz_conns[] =3D { "Port B", NULL }; + static const struct cec_dmi_match cec_dmi_match_table[] =3D { /* 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 }, }; =20 static struct device *cros_ec_cec_find_hdmi_dev(struct device *dev, - const char **conn) + const char * const **conns) { int i; =20 @@ -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 =3D m->conn; + *conns =3D m->conns; return d; } } @@ -346,7 +351,7 @@ static struct device *cros_ec_cec_find_hdmi_dev(struct = device *dev, #else =20 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 cro= s_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); =20 - port->notify =3D cec_notifier_cec_adap_register(hdmi_dev, conn, + if (!conns[port_num]) { + dev_err(dev, "no conn for port %d\n", port_num); + ret =3D -ENODEV; + goto out_probe_adapter; + } + + port->notify =3D cec_notifier_cec_adap_register(hdmi_dev, conns[port_num], port->adap); if (!port->notify) { ret =3D -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 =3D NULL; + const char * const *conns =3D NULL; int ret; =20 - hdmi_dev =3D cros_ec_cec_find_hdmi_dev(&pdev->dev, &conn); + hdmi_dev =3D cros_ec_cec_find_hdmi_dev(&pdev->dev, &conns); if (IS_ERR(hdmi_dev)) return PTR_ERR(hdmi_dev); =20 @@ -460,7 +471,7 @@ static int cros_ec_cec_probe(struct platform_device *pd= ev) =20 for (int i =3D 0; i < cros_ec_cec->num_ports; i++) { ret =3D cros_ec_cec_init_port(&pdev->dev, cros_ec_cec, i, - hdmi_dev, conn); + hdmi_dev, conns); if (ret) goto unregister_ports; } --=20 2.42.0.rc2.253.gd59a3bf2b4-goog From nobody Thu Dec 18 09:44:19 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F28FC3DA6F for ; Fri, 25 Aug 2023 02:54:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236009AbjHYCyI (ORCPT ); Thu, 24 Aug 2023 22:54:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239391AbjHYCxl (ORCPT ); Thu, 24 Aug 2023 22:53:41 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D1A02105 for ; Thu, 24 Aug 2023 19:53:15 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1c0c6d4d650so4788395ad.0 for ; Thu, 24 Aug 2023 19:53:15 -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=fKEER5+O0opXOTAI2xgLFXYGZe8KOQ6Zjyt1VK/lNRxFSMtWw3trrz3pQK5B0WG4pf ULJwlnN9mUkYXE5cxbTUSti+ZjWeSfooL1Qs1nwTHniSj0dHnBheNCjSFUzrJr8h2Nek +yAr+9q0smCpWO/1glyueQUVN4Z9RS32q7APahTKI82wZaMYYtR92n/wHDfMuzEiQ+4c u6Rum7Z3pauy2HYWZBKdAQw2dhyQkkSgtbPhSaaNJ+c42VFEi9EqNne2H7KI9+OwuPzW /rzpP0qo3zOeekMSKeBWOgRNlpoj+IJygdY7SpKvX8OpAg9vqaxIin0ZzEd9Xb3r86vj reSg== X-Gm-Message-State: AOJu0YxFHstRpKXvfCKwf1DDE/Auuz40jCS3qVcsnMfGK735igNx/ihm 0UxP6tzmEZ22y9oKdUrvjRVlEA== 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> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/med= ia/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 @@ =20 #define DRV_NAME "cros-ec-cec" =20 -/* 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, =20 #endif =20 +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 =3D 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 =3D 1; + return 0; + } + + if (response.port_count =3D=3D 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 =3D response.port_count; + return 0; +} + static int cros_ec_cec_get_write_cmd_version(struct cros_ec_cec *cros_ec_c= ec) { struct cros_ec_device *cros_ec =3D cros_ec_cec->cros_ec; @@ -463,7 +491,9 @@ static int cros_ec_cec_probe(struct platform_device *pd= ev) =20 device_init_wakeup(&pdev->dev, 1); =20 - cros_ec_cec->num_ports =3D CEC_NUM_PORTS; + ret =3D cros_ec_cec_get_num_ports(cros_ec_cec); + if (ret) + return ret; =20 ret =3D 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; =20 +/* 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 */ --=20 2.42.0.rc2.253.gd59a3bf2b4-goog From nobody Thu Dec 18 09:44:19 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 948E5C88CB2 for ; Fri, 25 Aug 2023 02:54:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240621AbjHYCyK (ORCPT ); Thu, 24 Aug 2023 22:54:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242463AbjHYCxv (ORCPT ); Thu, 24 Aug 2023 22:53:51 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68BFD2686 for ; Thu, 24 Aug 2023 19:53:30 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1bdca7cc28dso4794765ad.1 for ; Thu, 24 Aug 2023 19:53:30 -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=QzPf0dKBaHHz7fwgN16SXpg5eirbIyusR2CUQrmL7CrzZUeTuxHwrpJ4KoPpP/h2S8 J9CtcFzKoG+yD2Acxjivy9Y0gxaEc5SkBjxRGGQx9EnXDya9RBFAe/FtcTKwGd2wMVhJ E+guyTX18k3cZfIrhRqn0uZvcRKSdB9JY94iDjESH2HR3hp1HXXRd+7211lFfe1OSYIp xG6RpmtsnAHaLH4ug9dmnubhgv9xy7DJ+dQITtuQu31bOtQxsjEovwUDWttZnabAK2p1 UF5CUYUpaUMZgH0t7zEDQlgPTIDeWLa4tV8MBXdakVTVXcVzwpmAwBZQUxUcv8tyaSE6 8DEA== X-Gm-Message-State: AOJu0YyutPeGpcHGxM1VPBGWeoFQRpzMtYHE/8thp++zlC8EUC7CFSR2 rWzLj3BL90h7+plf1gsZ+VaFJA== 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> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/med= ia/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 { }; =20 static const char *const fizz_conns[] =3D { "Port B", NULL }; +static const char *const dibbi_conns[] =3D { "Port D", "Port B", NULL }; =20 static const struct cec_dmi_match cec_dmi_match_table[] =3D { /* Google Fizz */ @@ -313,6 +314,8 @@ static const struct cec_dmi_match cec_dmi_match_table[]= =3D { { "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 }, }; =20 static struct device *cros_ec_cec_find_hdmi_dev(struct device *dev, --=20 2.42.0.rc2.253.gd59a3bf2b4-goog