Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1041608ybh; Thu, 12 Mar 2020 16:05:59 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtdWs1vhr0xDEH7ldf3515G5njGgVmx8/ZIwAefIPK1obbPpeN6k18eY8zzSsJATneSJEp6 X-Received: by 2002:a9d:4c10:: with SMTP id l16mr8112397otf.109.1584054359834; Thu, 12 Mar 2020 16:05:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584054359; cv=none; d=google.com; s=arc-20160816; b=JcSI7iTla/sjj9XGBtlGtLCn6Ji+nIOhzVa59RBNR7KEBmmAw+j98i0Q6dYcw0U7IF c24pL6RNtdLvEd4/qVYAIuTVLN2vZPmV0b7z7pfcxsGCZjO80m4G9HC3eBTLQNqQJKsy 5axxxBUrER8V7hNbI4V/SSk2MKCKPcd0ZahVPpo7i+6bNAp2t+aqTUF6Jrx1GLik4KEM C7R5Mu6oZWJXqOAhYQbPerDYCQvAuRRf7RvR/8w/5TVi41+BMireWeTzBGfBqXBirgQ1 Ttf+FgQCDVqaBrk5txj6Gx3bYeMDRc1LC+CZ94Q7tDgyGM98e4maBjjA1ZPOhZEfsCQ0 pvpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XAdSv21dSQkMe6ASh/4rd2HigmIRXAw4ZLVXNFDtyVU=; b=c7X0UBHVwB6UoVisHjvFq9zW+pUYeNHXnf17Qot7tChUn8IH/JXDrHGvRpvbqnBIJb /qDKw0IJWJpkweRATCAqdEdyu4xtvr4NOtwdMua1PcX6JkLe3KxVHyKqSm7YyK5rXbb7 6v7n24CkKvTY1MQ7K4xQ2pW4FQ4TSVBcPnUjDFbm+HoiDmIHDbjy6yrWHoYY/MAmDnqH tlDuCF5pH6OXz766qqOLWGaVen0e928M1kS4wgoFDm1LJxpx8dC4eJHGhavUeKal7kOG L9MFoov7nxZ7X/xAQHF1H3IZeOzgwuhtfdsB6z7CT2Agiibpx+nzbIq5UlyHrpd9oon6 Yqxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JA+OPDXa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d27si2612564otf.22.2020.03.12.16.05.47; Thu, 12 Mar 2020 16:05:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JA+OPDXa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726788AbgCLXED (ORCPT + 99 others); Thu, 12 Mar 2020 19:04:03 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:44179 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726513AbgCLXEC (ORCPT ); Thu, 12 Mar 2020 19:04:02 -0400 Received: by mail-pf1-f195.google.com with SMTP id b72so3999795pfb.11 for ; Thu, 12 Mar 2020 16:04:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XAdSv21dSQkMe6ASh/4rd2HigmIRXAw4ZLVXNFDtyVU=; b=JA+OPDXa5jC/dqTY/BEaS2/VtEz+hMQLPwkTH8PkNmHkGYFL8RCOVkhO580y5J9feL NicY7eREQT5oZj3PsVQz0IPqODw6jQceJy7EWL+cyn6pTIYff70HIED0XoJiL9enhaFP 94gwRLRJ2dUCBQUV8j1eGG2g+ss9Oc1MJDrsk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XAdSv21dSQkMe6ASh/4rd2HigmIRXAw4ZLVXNFDtyVU=; b=NlBq9r0que5eWkhxqoaIf9Fvpym1xoOLp/BlE3LjQ7Qfh+xtZqVGXNTT/mpj3FGK3X vtjgpKxxMZer//EeCSv7LGCIMWYmOxPTgPeTIDkT1m+nZniSFhNCC/L2dQbMx9Lmr9bh U7PjbZCOJ/pK3mz/aAhwB0IwwlaOajz8frVu/My07Hf3HH1DUXyfUVmkyf2DGQ0soZ92 ZiGfEuHQ3y5to5+NnRIqBhO3jul7/idL9WZsnqrECnAHslWM8xn/D5DGwwYe3Mwt6YkM 1d7F+Rac+ua4ERNWdkMjYXw9YxfAijP0VMbfzXZHvtwnW7Xfw0e2cghNrRzzOLzzal2y d1Dw== X-Gm-Message-State: ANhLgQ0wEr1pYNZ1ZYoNHOpfzrj359VAj5M/xBBI0gRoZOJbbvsl8UCm W44HcnVhrpGlyWb4Lne891RYF8cKpfw= X-Received: by 2002:aa7:990e:: with SMTP id z14mr8766053pff.274.1584054241555; Thu, 12 Mar 2020 16:04:01 -0700 (PDT) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:476b:691:abc3:38db]) by smtp.gmail.com with ESMTPSA id v123sm28763161pfb.85.2020.03.12.16.04.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 16:04:01 -0700 (PDT) From: Prashant Malani To: linux-kernel@vger.kernel.org Cc: Prashant Malani , Benson Leung , Enric Balletbo i Serra , Guenter Roeck Subject: [PATCH v4 3/4] platform/chrome: typec: Get PD_CONTROL cmd version Date: Thu, 12 Mar 2020 15:57:17 -0700 Message-Id: <20200312225719.14753-4-pmalani@chromium.org> X-Mailer: git-send-email 2.25.1.481.gfbce0eb801-goog In-Reply-To: <20200312225719.14753-1-pmalani@chromium.org> References: <20200312225719.14753-1-pmalani@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Query the EC to determine the version number of the PD_CONTROL command which is supported by the EC. Also store this value in the Type C data struct since it will be used to determine how to parse the response to queries for port information from the EC. Signed-off-by: Prashant Malani --- Changes in v4: - No changes Changes in v3: - Moved if statement check in the end of probe() from this patch to a previous patch. Changes in v2: - No changes. drivers/platform/chrome/cros_ec_typec.c | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index 02e6d5cbbbf7a..9f692eb78b322 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -21,6 +21,7 @@ struct cros_typec_data { struct device *dev; struct cros_ec_device *ec; int num_ports; + unsigned int cmd_ver; /* Array of ports, indexed by port number. */ struct typec_port *ports[EC_USB_PD_MAX_PORTS]; /* Initial capabilities for each port. */ @@ -171,6 +172,31 @@ static int cros_typec_ec_command(struct cros_typec_data *typec, return ret; } +static int cros_typec_get_cmd_version(struct cros_typec_data *typec) +{ + struct ec_params_get_cmd_versions_v1 req_v1; + struct ec_response_get_cmd_versions resp; + int ret; + + /* We're interested in the PD control command version. */ + req_v1.cmd = EC_CMD_USB_PD_CONTROL; + ret = cros_typec_ec_command(typec, 1, EC_CMD_GET_CMD_VERSIONS, + &req_v1, sizeof(req_v1), &resp, + sizeof(resp)); + if (ret < 0) + return ret; + + if (resp.version_mask & EC_VER_MASK(1)) + typec->cmd_ver = 1; + else + typec->cmd_ver = 0; + + dev_dbg(typec->dev, "PD Control has version mask 0x%hhx\n", + typec->cmd_ver); + + return 0; +} + #ifdef CONFIG_ACPI static const struct acpi_device_id cros_typec_acpi_id[] = { { "GOOG0014", 0 }, @@ -202,6 +228,12 @@ static int cros_typec_probe(struct platform_device *pdev) typec->ec = dev_get_drvdata(pdev->dev.parent); platform_set_drvdata(pdev, typec); + ret = cros_typec_get_cmd_version(typec); + if (ret < 0) { + dev_err(dev, "failed to get PD command version info\n"); + return ret; + } + ret = cros_typec_ec_command(typec, 0, EC_CMD_USB_PD_PORTS, NULL, 0, &resp, sizeof(resp)); if (ret < 0) -- 2.25.1.481.gfbce0eb801-goog