Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp819035pxx; Thu, 29 Oct 2020 15:31:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtGi0C7jRh902XNFZf4WGpIO9HMwOtHGi40L3gi/sIwLLQN2ChgXOC3lz3CpPt70w6YDXg X-Received: by 2002:a05:6402:1bcc:: with SMTP id ch12mr6379553edb.339.1604010699549; Thu, 29 Oct 2020 15:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604010699; cv=none; d=google.com; s=arc-20160816; b=tbUPTeoUO6ZbJWhJsLWK6JzOG/sbuEmmSW8+yu9RV+nTLKimudIiH7Xv0hTCQ+SONE nj5EtnJreQvGnB3CXrZOjA31t0kPuuT+GNZ10Rx+KZfObNwKM/YjMMclUROJwdg6pl9O Ic9ztRReZG6i5t4hNNrgj3GneUhOT+E2aRFXwCLexblp7TMaKJIVDOiE1enYEeiADZ1e /ka1osZSKylFwMBwEFvGpYcuzn1rb4tnh3KrDM3ZMf6iXTGAC9zIZ1XhXplZC5ZYRXT+ wYx365BCd3ekfyNH9Vo/qxz1hx8MVD0kv2pD3/yyLdZL8CD0NpRpNZ/jN4jxz9RY/civ Q2ag== 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=AL6bc4JXBQj7VOdOG7p2V9Qp28jEf6yhcQGxqCF+RYo=; b=n8tkQ0F4k9f5F5q6a664o6ftIYudSkiKrCUbUOG5c5PHOuca3+u9bLN4xbds3It2H/ E5eDVjDf4aImfk35FzDYliGCOAji8Dv3STVpEDobp0/MTe19v0VdbfgxQgiBAE6c4dBa YMB6cA1MzhGqiX4jzayJeRGcD1bsqfQA1FmzvFhkXQvboDu7Et9hYGrsLM3lWzGlmf/K EBHVK1DAwJ6W+QyzF63SPBy3vNUWeH0t2C2f0LBkZMBS4k1Y0DWqKz4HkgOtQcTypDE6 aVggWzF3zwomfRjoY1Ow8zgUQ3TqzxmCIHyq/XZsadTh7olbL/dR6HagMWOuftuAQXZn 6X7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=XKe5FKCJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id nw19si2771346ejb.586.2020.10.29.15.31.15; Thu, 29 Oct 2020 15:31:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=XKe5FKCJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726017AbgJ2W3E (ORCPT + 99 others); Thu, 29 Oct 2020 18:29:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725952AbgJ2W3D (ORCPT ); Thu, 29 Oct 2020 18:29:03 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC4BAC0613CF for ; Thu, 29 Oct 2020 15:29:03 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id o129so3586323pfb.1 for ; Thu, 29 Oct 2020 15:29:03 -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=AL6bc4JXBQj7VOdOG7p2V9Qp28jEf6yhcQGxqCF+RYo=; b=XKe5FKCJ45HUs+9mdk6ZWuk90VD/wTZZ7pep615Elz5B62tpdPhSJ+1X3AmIHk+WAZ rxovV5+CdWZ+rvLgkWCqeP/NR5f2MtJlU+Y1S474KetdvmF4YzhBO3gcO0mwkIOJovRG JYRRizHXz0clso/AWgujHrVEDxiBpxwzUnHNs= 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=AL6bc4JXBQj7VOdOG7p2V9Qp28jEf6yhcQGxqCF+RYo=; b=N16RFn3vL/fadMmKbWSKO8DO8TlvXzRwn53n9xZoUp8avZVqsrgsKoVn1YbythZSNs fsGii17c2Xjq6xQPq1GRSA/Ro+etWM4ICf0lPpZvNtQ6tPQfbWsxyUmaFrJPZduaM4fM X7XTB8Bbv/OsYbmnprU1B9Qk9QN0BH5wFHvEdTqAMvvFBQ7nbbMR5QnpwR6Geqj+lgJJ 4XoWG+cUv2YSE1cxt/3Ygui62ZbAh8GxIVgqd6bJFqLcMyRv+uIRVWVbsWnQ4kYr/XHY 35PIgg7VkfMmpId32C/nyCAsV9laJAx55gPSxzsyJADRRhuCMYs2LOwKRdKuL/O/DMu3 a8PQ== X-Gm-Message-State: AOAM532KL5DJTdSpk30tL8Z+eppRap3yTFKhwW3p63b0KV4ZLh9K2NXP bRUrvAi10EhrBky1qBahFCtJV50HazHfvw== X-Received: by 2002:a17:90b:148c:: with SMTP id js12mr1356251pjb.175.1604010543118; Thu, 29 Oct 2020 15:29:03 -0700 (PDT) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:a28c:fdff:fef0:49dd]) by smtp.gmail.com with ESMTPSA id f5sm3573886pgi.86.2020.10.29.15.29.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 15:29:02 -0700 (PDT) From: Prashant Malani To: linux-kernel@vger.kernel.org Cc: heikki.krogerus@linux.intel.com, dzigterman@chromium.org, alevkoy@chromium.org, Prashant Malani , Benson Leung , Enric Balletbo i Serra , Guenter Roeck Subject: [PATCH v2 6/7] platform/chrome: cros_ec_typec: Parse partner PD ID VDOs Date: Thu, 29 Oct 2020 15:27:40 -0700 Message-Id: <20201029222738.482366-7-pmalani@chromium.org> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog In-Reply-To: <20201029222738.482366-1-pmalani@chromium.org> References: <20201029222738.482366-1-pmalani@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use EC_CMD_TYPE_DISCOVERY to retrieve and store the discovery data for the port partner. With that data, update the PD Identity VDO values for the partner, which were earlier not initialized. Cc: Heikki Krogerus Signed-off-by: Prashant Malani --- Changes in v2: - No changes drivers/platform/chrome/cros_ec_typec.c | 60 ++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index f578d0bfbe5a..f14550dac614 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +52,7 @@ struct cros_typec_port { /* Flag indicating that PD discovery data parsing is completed. */ bool disc_done; + struct ec_response_typec_discovery *sop_disc; }; /* Platform-specific data for the Chrome OS EC Type C controller. */ @@ -298,6 +300,12 @@ static int cros_typec_init_ports(struct cros_typec_data *typec) port_num); cros_typec_register_port_altmodes(typec, port_num); + + cros_port->sop_disc = devm_kzalloc(dev, EC_PROTO2_MAX_RESPONSE_SIZE, GFP_KERNEL); + if (!cros_port->sop_disc) { + ret = -ENOMEM; + goto unregister_ports; + } } return 0; @@ -582,6 +590,51 @@ static int cros_typec_get_mux_info(struct cros_typec_data *typec, int port_num, sizeof(req), resp, sizeof(*resp)); } +static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_num) +{ + struct cros_typec_port *port = typec->ports[port_num]; + struct ec_response_typec_discovery *sop_disc = port->sop_disc; + struct ec_params_typec_discovery req = { + .port = port_num, + .partner_type = TYPEC_PARTNER_SOP, + }; + int ret = 0; + int i; + + if (!port->partner) { + dev_err(typec->dev, + "SOP Discovery received without partner registered, port: %d\n", + port_num); + ret = -EINVAL; + goto disc_exit; + } + + memset(sop_disc, 0, EC_PROTO2_MAX_RESPONSE_SIZE); + ret = cros_typec_ec_command(typec, 0, EC_CMD_TYPEC_DISCOVERY, &req, sizeof(req), + sop_disc, EC_PROTO2_MAX_RESPONSE_SIZE); + if (ret < 0) { + dev_err(typec->dev, "Failed to get SOP discovery data for port: %d\n", port_num); + goto disc_exit; + } + + /* First, update the PD identity VDOs for the partner. */ + if (sop_disc->identity_count > 0) + port->p_identity.id_header = sop_disc->discovery_vdo[0]; + if (sop_disc->identity_count > 1) + port->p_identity.cert_stat = sop_disc->discovery_vdo[1]; + if (sop_disc->identity_count > 2) + port->p_identity.product = sop_disc->discovery_vdo[2]; + + /* Copy the remaining identity VDOs till a maximum of 6. */ + for (i = 3; i < sop_disc->identity_count && i < VDO_MAX_OBJECTS; i++) + port->p_identity.vdo[i - 3] = sop_disc->discovery_vdo[i]; + + ret = typec_partner_set_identity(port->partner); + +disc_exit: + return ret; +} + static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num) { struct ec_response_typec_status resp; @@ -602,7 +655,12 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num /* Handle any events appropriately. */ if (resp.events & PD_STATUS_EVENT_SOP_DISC_DONE) { - dev_dbg(typec->dev, "SOP Discovery done for port: %d\n", port_num); + ret = cros_typec_handle_sop_disc(typec, port_num); + if (ret < 0) { + dev_err(typec->dev, "Couldn't parse SOP Disc data, port: %d\n", port_num); + return; + } + typec->ports[port_num]->disc_done = true; } } -- 2.29.1.341.ge80a0c044ae-goog