From patchwork Fri Jan 26 18:39:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 192750 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2395:b0:106:343:edcb with SMTP id gw21csp75860dyb; Fri, 26 Jan 2024 10:44:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IErw/blQrQmWWuxxCR9fCZKrMDRvhACUp/lsubxK5h9A7bxwBiDi0IyKoDCO/RK8hSvTLzl X-Received: by 2002:a0c:ca8c:0:b0:68a:c1d8:4395 with SMTP id a12-20020a0cca8c000000b0068ac1d84395mr2136386qvk.3.1706294651215; Fri, 26 Jan 2024 10:44:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706294651; cv=pass; d=google.com; s=arc-20160816; b=hGiMV0Na1NPH58ollzojHQ5Ngp8+0JTnyij5RnyZxZLGCiA1KyuMo8CK++7GBD7zAv f5+G7WET3V+fWbPvKmeMKSo/QgOdpDqIKH1mlfldTxVe60d/7B2zb4NHDA2pNirEnZc7 ixU6+g8EOtPAy5YXvjlYhUotEv4yRCiuiKvoljtLqDJLpXweZVf7QqtxTY58a4PdrDZU h+CsywvKxBrtoZ8tmi4ASvqRfQiaCOcelwTCjmiklYsGuinYHHInx3iwC/zlwdPXjrlx Ep92LMxxYqH3qNfee0/Kz2IWxaPYEKku1tqaENtHMQsKn0nMpiLLtGNq8fL4yIHd4ji3 LDwA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=2QQrn5zdRS2vcBUSW5uiCOjM9d8+vCQMueTf6c01I2Q=; fh=kSArWcDrdhNNVZGpbY6aYsaq5fuUnfufylfOj7rN9T4=; b=eO+uY2MOdKvSsw8vXeeiAHGcnKqA70LJx2uSZ3AqeVPgzJr6MSBp7nlAnfTtnfskn8 /QuNQ2HShpNZibBy0b+0tI1B7RbG053kkr7FwWrXrFc7qKwbmWSNbrkZJcdiZSfX12Gd /Qa9xNFJ04m91XM91JvQtnCuPXbCsRf3XW5D+qQTHoSoXl1yw7nshFfNGnjLKucIc58r /uhaW/HVk/sQEj2eTmq/93wbEP3CxFo+PrJIbj7NkQUHNpH8HD79zJOc0sE/YXmDmc+C PP5Vr7cWvBqbgzxS/ObAUSqDdXVNd/EyaQT16MBp40myVNacKYHfLJpuw8tw7YnTKz1c kx1Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=GM59ius0; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-40518-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40518-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ed12-20020ad44eac000000b00681922a623dsi1854930qvb.315.2024.01.26.10.44.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 10:44:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40518-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=GM59ius0; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-40518-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40518-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id ECF581C22BD2 for ; Fri, 26 Jan 2024 18:44:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 86F1F56766; Fri, 26 Jan 2024 18:39:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="GM59ius0" Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 174B65467D for ; Fri, 26 Jan 2024 18:39:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706294383; cv=none; b=SYfv1spTB0gIXex72cMrQZEUApmISa72oqFKcR5NK72aP8JR7gliaQTnMl1umDUKpUUPlksi6qIVGPhDBYKFNU5X+qiVXW4apgN21pJrgqD/7AWyFt50Q9LOK/UCbqQk27MxW60lrYFRVearuYmyMrKSyufADqNS4nt24Ix0HVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706294383; c=relaxed/simple; bh=qQ20mYMsYljxRmFVBXSfi1rqbWNANcAPCdD/+60IY8U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eGl4SVjKyJitnTA+5ZqtfCvq0PotQheLX4+HQFmSpSwmpIvQgS/sEMJ+xecETJRQFhZyVzdPMzdhdhwAyfcTjkwQXFN8NdzQrpcuroJtO1E8DATE/8QtYhWbQ2GPrIL5r/lDnot2lQ8zBROSREJfyBJdtTDyz/BthAaEofV7f7c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=GM59ius0; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-6de0ba30994so220334b3a.1 for ; Fri, 26 Jan 2024 10:39:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1706294381; x=1706899181; darn=vger.kernel.org; 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=2QQrn5zdRS2vcBUSW5uiCOjM9d8+vCQMueTf6c01I2Q=; b=GM59ius04vzCGUnLQqoAZYoXawSxOLreTdynV8WlIX6u/2ngpd+RqUUfnCbNs31OAd ubXnSzMA8bAH1LcXFnq8oSRnw1vOxgEyA9KOnAx3+zMiZLZVYurhiB/5Gj/7gil9iRii leZ/yVFHuScREQQ7O1MM8j1RyuQlTsB8UyJPE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706294381; x=1706899181; 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=2QQrn5zdRS2vcBUSW5uiCOjM9d8+vCQMueTf6c01I2Q=; b=Q3fogOmdzpsHC+2l+YsGpRVFT3//SUS5lzMO1MC5viZyd/uIJfmcpeT81ETluw8eTo gIa5xO0UJkmQjENadhNKErlCKiQOtxhJx2w3H+3+F9D+My5JLJU8z3Hm8H0BuqCl77hQ jcmZ8vqgwJPF6ltEcJJLH1kqMoly79lXJJs1Vfd6s+XwzefLX6J47JjHEBOfNbznrLlV 6pK6+kwVcTdhut+ZHuIV079GVqzvQ3bGwOofSCAW3I7JbZEBX1G+4pf2dAZN1DOzjLm/ FKwUx4hSEdsob9vy4fNcc/ISNrdw/IVkHLbB7c9Qkstip0L5+ephbc5S9D8sPqX17Qlx kLxw== X-Gm-Message-State: AOJu0YzFUEmjaojYUxpStzm4zfYQ9/id0bOICv1K+QrGeudJlgVkSZOK Ta+cqhBbcLoeOCLD/dSGWsBToFVz8E7NX/0+aeTYkQapDCZJev1lGKlJJS5Axw== X-Received: by 2002:aa7:8b97:0:b0:6da:af47:95f0 with SMTP id r23-20020aa78b97000000b006daaf4795f0mr272875pfd.27.1706294380577; Fri, 26 Jan 2024 10:39:40 -0800 (PST) Received: from localhost (209.148.168.34.bc.googleusercontent.com. [34.168.148.209]) by smtp.gmail.com with UTF8SMTPSA id r25-20020aa78b99000000b006dbda9a4e6bsm1410678pfd.44.2024.01.26.10.39.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Jan 2024 10:39:40 -0800 (PST) From: Abhishek Pandit-Subedi To: Heikki Krogerus , linux-usb@vger.kernel.org Cc: pmalani@chromium.org, jthies@google.com, Abhishek Pandit-Subedi , Andy Shevchenko , Bjorn Andersson , Dmitry Baryshkov , Fabrice Gasnier , Greg Kroah-Hartman , Hans de Goede , Neil Armstrong , Rajaram Regupathy , Saranya Gopal , linux-kernel@vger.kernel.org Subject: [PATCH v3 3/3] usb: typec: ucsi: Get PD revision for partner Date: Fri, 26 Jan 2024 10:39:09 -0800 Message-ID: <20240126103859.v3.3.Idf7d373c3cbb54058403cb951d644f1f09973d15@changeid> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240126183930.1170845-1-abhishekpandit@chromium.org> References: <20240126183930.1170845-1-abhishekpandit@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789179619953079426 X-GMAIL-MSGID: 1789179619953079426 PD major revision for the port partner is described in GET_CONNECTOR_CAPABILITY and is only valid on UCSI 2.0 and newer. Update the pd_revision on the partner if the UCSI version is 2.0 or newer. Signed-off-by: Abhishek Pandit-Subedi Reviewed-by: Heikki Krogerus Reviewed-by: Prashant Malani --- $ cat /sys/class/typec/port2-partner/usb_power_delivery_revision 3.0 (no changes since v2) Changes in v2: - Formatting changes and update macro to use brackets. - Fix incorrect guard condition when checking connector capability. drivers/usb/typec/ucsi/ucsi.c | 23 +++++++++++++++++++++++ drivers/usb/typec/ucsi/ucsi.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index a35056ee3e96..2b7983d2fdae 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -782,6 +782,7 @@ static int ucsi_register_partner(struct ucsi_connector *con) } desc.usb_pd = pwr_opmode == UCSI_CONSTAT_PWR_OPMODE_PD; + desc.pd_revision = UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD(con->cap.flags); partner = typec_register_partner(con->port, &desc); if (IS_ERR(partner)) { @@ -856,6 +857,27 @@ static void ucsi_partner_change(struct ucsi_connector *con) con->num, u_role); } +static int ucsi_check_connector_capability(struct ucsi_connector *con) +{ + u64 command; + int ret; + + if (!con->partner || !IS_MIN_VERSION_2_0(con->ucsi)) + return 0; + + command = UCSI_GET_CONNECTOR_CAPABILITY | UCSI_CONNECTOR_NUMBER(con->num); + ret = ucsi_send_command(con->ucsi, command, &con->cap, sizeof(con->cap)); + if (ret < 0) { + dev_err(con->ucsi->dev, "GET_CONNECTOR_CAPABILITY failed (%d)\n", ret); + return ret; + } + + typec_partner_set_pd_revision(con->partner, + UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD(con->cap.flags)); + + return ret; +} + static int ucsi_check_connection(struct ucsi_connector *con) { u8 prev_flags = con->status.flags; @@ -925,6 +947,7 @@ static void ucsi_handle_connector_change(struct work_struct *work) if (con->status.flags & UCSI_CONSTAT_CONNECTED) { ucsi_register_partner(con); ucsi_partner_task(con, ucsi_check_connection, 1, HZ); + ucsi_partner_task(con, ucsi_check_connector_capability, 1, HZ); if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) == UCSI_CONSTAT_PWR_OPMODE_PD) diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 1bae4cf8ecdc..d1d0e11b0704 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -36,6 +36,9 @@ struct dentry; #define UCSI_BCD_GET_MINOR(_v_) (((_v_) >> 4) & 0x0F) #define UCSI_BCD_GET_SUBMINOR(_v_) ((_v_) & 0x0F) +#define IS_MIN_VERSION(ucsi, min_ver) ((ucsi)->version >= (min_ver)) +#define IS_MIN_VERSION_2_0(ucsi) IS_MIN_VERSION(ucsi, UCSI_VERSION_2_0) + /* Command Status and Connector Change Indication (CCI) bits */ #define UCSI_CCI_CONNECTOR(_c_) (((_c_) & GENMASK(7, 1)) >> 1) #define UCSI_CCI_LENGTH(_c_) (((_c_) & GENMASK(15, 8)) >> 8)