Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1483699pxb; Fri, 6 Nov 2020 10:45:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwDtLOxlrx6bDkpWsP+VkEQWcf3vutRDAetYHayGQ5c5NX+tjGz8hyq2YkQ5EjcRpVH7is8 X-Received: by 2002:a17:906:9455:: with SMTP id z21mr3376848ejx.160.1604688326229; Fri, 06 Nov 2020 10:45:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604688326; cv=none; d=google.com; s=arc-20160816; b=GdLwN55epv0z0JBkRX30HOttmba9IMIyvxPIjrTaAOm1U5OoIy44+KVKtR+Mpv1y9C J/O2iyxqeIp6dA2qNMMaemS5bwO8+7aMRXtTsiMe9dnt1DTKv8iWprBpDnmjfBpC1UDc DBfHccjIJqJRI2nMJIYPG0iqhkyIOuqwHX6w/YSufNnV8IZsr1duutyLxi55MFKxgAG4 HjO40SWSg6Ets5nNVhK0Fgxj4TVYSV3OQybyZUJeYWzBZHNVVZyMNObsItnswPGCb2vF ALvHqqdYcpn0qtie+oWM4/yFwXlEU8+tj6kqnqvBAG4J3pVmZfQRLvlloUWq6ziBrpq3 8N/w== 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=Wq6Preoru3IfCh2dMMdaJylKOwWTSm5/Yosw2jaNCWA=; b=GDjEetyaJaQPXgJKi//Lr/we5cqJuR0e2WMnmaPT8GPAwBatQKiWLJhTeXrrofLa6o lVKD3iPMZ7Omt9uWn0tPmaCe7rwJlfXwqX9Y+Ekkgaaw07LV4eJcGT193WrC4azxa+dm xxcktskqQAs+DCNNamIgp35r/vgLvngFPsyEzql6fOgzHQxIlr5CXiDhtu6CTgvE46Aw 1lZGtYSJyAZzIIrG15s6R3LhAoDFN5oeGPIuoC1IugbZ2F4JW/cm1gb/sqmfr/FqEcNx C6dNfNXAc1lILVr+Lw1/36c+eqJKaJOTDO4bEYzD1xxeK/USdZ3FMEzqP8IDdcsmS5gT 7fMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YdIg0K5x; 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 t11si1520801edj.441.2020.11.06.10.45.03; Fri, 06 Nov 2020 10:45:26 -0800 (PST) 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=YdIg0K5x; 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 S1727800AbgKFSlm (ORCPT + 99 others); Fri, 6 Nov 2020 13:41:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727944AbgKFSlk (ORCPT ); Fri, 6 Nov 2020 13:41:40 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4294EC0613CF for ; Fri, 6 Nov 2020 10:41:40 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id g12so1600410pgm.8 for ; Fri, 06 Nov 2020 10:41:40 -0800 (PST) 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=Wq6Preoru3IfCh2dMMdaJylKOwWTSm5/Yosw2jaNCWA=; b=YdIg0K5xvHn3rYHxnyjF69EcZrXG4YQrIsW23NhkkkMfCwd0dny7SQGaI77hv42ag8 bzvC/KKaGXE0IEQVDyOToDt4AonfC6VQjNadnisCaSQaC7PaJsqzZvqiMtJajvLGiIt1 II7lzEea/elUf4VaNyXnYIwOlFOvffa1dNLB0= 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=Wq6Preoru3IfCh2dMMdaJylKOwWTSm5/Yosw2jaNCWA=; b=fMOjB/pl0ydfgPXw3TeJym7uJF8/qcuyDKWeiKv+Lw4lJLeU6US+WfzKCxp1iAjY6x 3OaplzsNiwrlYeKDik2FqkzULb37cb+Bx1OKJ2Lk8rUb+zQlhhTaepM6SZQa+nzgOhmx 6fFc1Dp1Q0slJ6CyGMD8qEKeP/nm/t2vpiPmmHvo5+ZyLZgdw8vkdrtHxiOAr6vqdjeu UO1ovEdaqYOSUuJxMjwZSPGXHvAfK9E4wMTNSu8+0OUgvM/tTK8+VlqMMTCWXAvKEDZx d2qZY3k9CWbMuM5M2OpAewuEE2zoBh1h19C0vOx1HTcgU4evQVf6G1oLJy9OC6H5Cqdp rGGw== X-Gm-Message-State: AOAM532wYwaHYt2QjkSuZZLJXYoIhkeoy75q1X25oEjSf/FfMvJkM3p4 XPLd/lS0w/Ijs9JkfoN4GODpLcbKQ/W7RQ== X-Received: by 2002:a17:90a:e20f:: with SMTP id a15mr954488pjz.12.1604688099572; Fri, 06 Nov 2020 10:41:39 -0800 (PST) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:a28c:fdff:fef0:49dd]) by smtp.gmail.com with ESMTPSA id b6sm3246143pjq.42.2020.11.06.10.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2020 10:41:39 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, gregkh@linuxfoundation.org Cc: Prashant Malani , Benson Leung , Enric Balletbo i Serra , Guenter Roeck Subject: [PATCH v2 2/6] platform/chrome: cros_ec_typec: Factor out PD identity parsing Date: Fri, 6 Nov 2020 10:41:01 -0800 Message-Id: <20201106184104.939284-3-pmalani@chromium.org> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog In-Reply-To: <20201106184104.939284-1-pmalani@chromium.org> References: <20201106184104.939284-1-pmalani@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Factor out the PD identity parsing code into a separate function. This way it can be re-used for Cable PD identity parsing in future patches. No functional changes are introduced by this patch. Signed-off-by: Prashant Malani --- Changes in v2: - No changes. drivers/platform/chrome/cros_ec_typec.c | 35 ++++++++++++++++--------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index 801c3d2c1fbd..f6d3c37c2c27 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -657,6 +657,28 @@ static int cros_typec_register_altmodes(struct cros_typec_data *typec, int port_ return ret; } +/* + * Parse the PD identity data from the EC PD discovery responses and copy that to the supplied + * PD identity struct. + */ +static void cros_typec_parse_pd_identity(struct usb_pd_identity *id, + struct ec_response_typec_discovery *disc) +{ + int i; + + /* First, update the PD identity VDOs for the partner. */ + if (disc->identity_count > 0) + id->id_header = disc->discovery_vdo[0]; + if (disc->identity_count > 1) + id->cert_stat = disc->discovery_vdo[1]; + if (disc->identity_count > 2) + id->product = disc->discovery_vdo[2]; + + /* Copy the remaining identity VDOs till a maximum of 6. */ + for (i = 3; i < disc->identity_count && i < VDO_MAX_OBJECTS; i++) + id->vdo[i - 3] = disc->discovery_vdo[i]; +} + static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_num) { struct cros_typec_port *port = typec->ports[port_num]; @@ -666,7 +688,6 @@ static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_nu .partner_type = TYPEC_PARTNER_SOP, }; int ret = 0; - int i; if (!port->partner) { dev_err(typec->dev, @@ -684,17 +705,7 @@ static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_nu 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]; + cros_typec_parse_pd_identity(&port->p_identity, sop_disc); ret = typec_partner_set_identity(port->partner); if (ret < 0) { -- 2.29.1.341.ge80a0c044ae-goog