Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp2365680rdg; Sun, 13 Aug 2023 23:10:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG8tE13E1uZC+a+BcZ+psMEG/bUbCUJ46XvY7FHBUqFDEWsw32KY7ACgm7B5PxYGfvgkwvt X-Received: by 2002:a17:902:d4c3:b0:1b9:c68f:91a5 with SMTP id o3-20020a170902d4c300b001b9c68f91a5mr7777872plg.6.1691993415110; Sun, 13 Aug 2023 23:10:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691993415; cv=none; d=google.com; s=arc-20160816; b=R3QZTMgQdB/Ml6mOp32P99XIhVAYJuVZ6263IOadTeogo/J4kRuU794PEaGfy6ylhR yh1cG7CaTt64eaY5w9SCGVG9fXF2wp0r1eKZYZJS3kzjrmqHvhF5wS6xWfqD1m5y2Q8i HIVsMSE47TYydsDAkyGu5z1WcRaceXJKcqefrAEBqtybap9X2PYSlDwaR9HoPhsetA5j HgExG3gJsO/n/0uJiITFWrShJIYS3HTPDCAhVgyoVam9Fc6OUljk7J6QYXRTkza3BtvJ azk6W4O5UrXP9DuuD7os5KTLYkRRjMkpG7esntB9pd2VNcMLRiRPDpUqnrtL6gy+znLB CMzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qn05RavKUDwCo7Nk//6BvwshJgQPYJchPE2n3kFnelU=; fh=Z54ABTjWKY0UM+xzbKZvDcqrpuAhT1VnH73TfCDbJK4=; b=d54UbPOL1PxS1WCuimXIQYGxQgjuTE9myaoobYiX7ZGFXGzPESZpdYIylx77HIXxYD VzitMa7t+ef3E8eJGxoEUgqSVbg2Pg6WM/e+DJaEvOhpeznqLE29Ql351x9j9L5OeYL5 6TGxVE+fPZWINSmvjiiGCg/12M9TsWPNbyEUiSglteC7OW1mULLcRzspQjEAZD8mviUw KBF9jruNIefW9LWrGh0UCq5pQne+8/7ZC/ApavRlyP+Rzo8Dl3TUWu1RurbeoDAlwbzm S7rVT2ygVLD4Q3kuMEw62W0VxETyI83ZyUzAxn5ryNKqxKW7qcsA/N7Qer7ehXmzWhCG oZOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=C+TalMts; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p8-20020a170902e74800b001bc463ead7asi7977615plf.247.2023.08.13.23.10.02; Sun, 13 Aug 2023 23:10:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=C+TalMts; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233176AbjHNEgw (ORCPT + 99 others); Mon, 14 Aug 2023 00:36:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233156AbjHNEg1 (ORCPT ); Mon, 14 Aug 2023 00:36:27 -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 CB7F2E6F for ; Sun, 13 Aug 2023 21:36:24 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-686b9920362so2495886b3a.1 for ; Sun, 13 Aug 2023 21:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1691987784; x=1692592584; 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=qn05RavKUDwCo7Nk//6BvwshJgQPYJchPE2n3kFnelU=; b=C+TalMts8a2m6aL+ebXUXjcz744b6n1+AI3kTmdTfz43y+y8CBXkzjV9Q+3HBCTd5C NlVKUAF+jMShWAX+WBEFtEqxIh4/zYRFR4vpCjYxme6YPbst5Og+DuBnka/Ts01mImYB v5gXUrj3PDgNrzf007Wyfv+uUtdHAF9vIds6w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691987784; x=1692592584; 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=qn05RavKUDwCo7Nk//6BvwshJgQPYJchPE2n3kFnelU=; b=amsPsmeTPyLLX3++rqDLPzTFzifVNoOWoxJQ8xaQl736lNR3mo0PT3JYuhBFzO2w5f LY4RjSP0WT8fSfTADW1RfL+i/KxCgPxwOBy8gh8XW9giIQ9VvwCJ2fG1xR9C4im2cuc6 WVFlmZs3VAw+BNISVy2KbstrfmszoTUI3jqI80egcZkxiGgAwmjVe0eDm4jVF/LvqacV ejgLnqm6Q+eRCmsa3sAc5O/5+1nb5sjCjGsdEo8uD5WfDV0sGlSW02ODFQIf8ElTWAfL o9TzA3Bk9Nr/1ZlfbynHCLSLc0D/9A3+5843uhMBMINX6wiTiDU5TnaPekIWx4uk8BWd 7YoA== X-Gm-Message-State: AOJu0YxWmMjdstuIhQuiYe0l13pRvH/w2/tIUa4q278gisXP+jDNF/Gn KpV0VcyGiG1pi7AgRJl/R8fpGA== X-Received: by 2002:a05:6a20:9191:b0:13e:da98:966a with SMTP id v17-20020a056a20919100b0013eda98966amr8970273pzd.5.1691987784310; Sun, 13 Aug 2023 21:36:24 -0700 (PDT) Received: from rekanorman3.syd.corp.google.com ([2401:fa00:9:14:4ae6:d1a4:27c2:80ff]) by smtp.gmail.com with ESMTPSA id ju17-20020a170903429100b001bdb0483e65sm6761865plb.265.2023.08.13.21.36.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Aug 2023 21:36:24 -0700 (PDT) From: Reka Norman To: Hans Verkuil Cc: Neil Armstrong , Daisuke Nojiri , 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 8/9] media: cros-ec-cec: Get number of CEC ports from EC Date: Mon, 14 Aug 2023 14:29:17 +1000 Message-ID: <20230814043140.1108917-9-rekanorman@chromium.org> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog In-Reply-To: <20230814043140.1108917-1-rekanorman@chromium.org> References: <20230814043140.1108917-1-rekanorman@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- .../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 f2f397d9a6d8..cfc0a204d591 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 * @@ -356,6 +352,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; @@ -461,7 +489,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 */ -- 2.41.0.640.ga95def55d0-goog