Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1419456rdb; Wed, 24 Jan 2024 15:06:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IG5xWEBNg7o/QtqaKBqoey2bOTTCiJG+s1BKMN7cgleBDznNaRnqYlxuZJOthIir2BybRpM X-Received: by 2002:a17:902:bb8b:b0:1d7:4670:ffbf with SMTP id m11-20020a170902bb8b00b001d74670ffbfmr107431pls.64.1706137592073; Wed, 24 Jan 2024 15:06:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706137592; cv=pass; d=google.com; s=arc-20160816; b=J5/ZIjDQgSeEP7s/gGYV3aK2OTBIFq1ExiiIvKQtZtQv9OPWvpfYDElyf7HR34cbXR HKkD/C3zmznDNmL1fO/pHlOTu/jCwrWlqCoeywe9gYOTmYtit6nh0fcV2xrA63wFcChB i4FGuKWMP+60uQzlBIXitpXZrBvQmk07G2rtHP38rU84EjnFDbf7l0go8vaqRBf3EYLI e3ZGUFHlBfkdsycERnrtOi1jD8ICuxyiiXJqfOySptB0zo+f+UzN7Rv+W6oLuX8aSETS T69FNeMHFU9NvKeDxyvHBSIi5z8q9eCLR3pGqsd9ESYeJXV61mrT1521pXl1SUhqY2gY I22Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=WBrbySQu5iKGr9sNkUAtBVzTaLxKFzMhJjClQoKf5+M=; fh=Al9HDZEaHSEtCh28WOxs1Cyej0WBmp8KjtZ7yAyqgdM=; b=nga/ZeXDZuX+1gfIbU6YjaIy0Xnodco+K7wN2q79GB8QT1sZxZJmY+Tu5YbpAc4Ra6 FCqKVHP1ancgbb2PwcuxiFZd0fyeOqrGJFrFcr20K3EmXf/8FCcezPit9FUb0bBYr3gI 2BvUGe4UpwxEEiCNhW9hARtMRzNLFDU4rIstFgDv+ydzhe+kOmwO0LTLZagJUgJdUxyo rh+b638IbRMaJA7N8lsWehKLpiSSlG242pHOJr8TqZarr4fwdyfQ8q8LonO7s9wuxGIY X+HOfyKr82zqDaXQBWY/sys7+JAaaS1KQhRECA1kA9o1HmIEmX7cFevvMgsYpt8MXWyG phWg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bwqIVgNF; 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-37790-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37790-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id y8-20020a170902d64800b001d752bc5222si5838047plh.306.2024.01.24.15.06.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 15:06:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37790-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bwqIVgNF; 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-37790-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37790-linux.lists.archive=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 011B2B257CF for ; Wed, 24 Jan 2024 22:57:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B6D2136656; Wed, 24 Jan 2024 22:57:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="bwqIVgNF" Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) (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 CF92B135411 for ; Wed, 24 Jan 2024 22:57:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706137055; cv=none; b=ab35heuFuKNHnf/lCC6TH2mokxmXKZ/Paq2lcWDWmKnJqYZTmbu+6S0ZESdeCyblSR+lPTIrzTsK9jJT5kuzyUm4rXCVTH3itZiDc0LEWGSqIbEH6vyq49rhWui27+u+0mCZj/s3TBWQNT6qCfXEW0iZvvuLngG/7g/PlDVqBsE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706137055; c=relaxed/simple; bh=ZIIZJ+Jcrl8bt49eFQOrQKNSd6j5uMTJKgZ/QcCvINA=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=MyJVSurrIHGaYzu7FbgQZoTGputkDZTsYP9covA5Hkk1ap/rc8TaSpUlgAQtTMrWzgRJDkhj71Es/QCHqELa9S1bBS5jW4pX+2YjlIYLhdyJ5rl45W6wZ7I3vvI/GjfpS3kY9z0s1HQHRspT+s/L+rxvqe5OcGI1EArVfBQ3Ks0= 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=bwqIVgNF; arc=none smtp.client-ip=209.85.219.178 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-yb1-f178.google.com with SMTP id 3f1490d57ef6-dc608c3718dso1203285276.1 for ; Wed, 24 Jan 2024 14:57:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1706137053; x=1706741853; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=WBrbySQu5iKGr9sNkUAtBVzTaLxKFzMhJjClQoKf5+M=; b=bwqIVgNFNGiMnlcm0xoHKmZV95ePMfSOWLHqJSoXyvNIKcQAVgYewoWP2lHdS3ACQJ ETYVKOQnyPPqoSBYAPAusohRtqznkbyfPh8NzYiYbBCtMwK3wCp8nu+iPOn09ODHtunR Hq54FBZdUo99tXE0DidJqwhxyrOikFjh8G3g0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706137053; x=1706741853; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WBrbySQu5iKGr9sNkUAtBVzTaLxKFzMhJjClQoKf5+M=; b=tVUw5upz7b0dmFjFsmxNIcEsPphTQ8sHt98GPMV6Wp2Xni9wFpFPUraDaPYTnn+rS9 HJUnhirf9RrCq7e6PSstWvg5zPodhkIhfCg50gVT7930VOa9+h7Fnd9sj9u47i0pYHy6 1wecQEXlU04sNa/seBFibEB8CTHNk4wZgOB9rPCfyJkup9HqrM0C20rq8xM6adyq639v zfCG5Q9tV/PmLmcFjs/wjuK7TX9kEq3YehmL+ff4C3bpHlE6kRBIJvRGZIJxLizsVBiS sPtH4buVXguvx0e1z9aO+xS3Kb5roxHdGngR7qBGYcmHUmEM/G/khwBstqYkhBZLIVUg nC/A== X-Gm-Message-State: AOJu0Yz4hdUHq88joZ6N2PfMqq5QDN+SfdKRfRCllCuZcSIgdKzqYkJ7 +D9z/+PsQSPpzsKUqMWPDO0O35hbds9sz4ojwvsqNfD2n3AzC0UCWcD/8jN3BI6JzLz7RFFLcqb IpbQEqFrbFLyckRSPnvWGWo00jk+Xk7XmwX/K X-Received: by 2002:a5b:348:0:b0:dc2:66d6:b32 with SMTP id q8-20020a5b0348000000b00dc266d60b32mr96351ybp.54.1706137052904; Wed, 24 Jan 2024 14:57:32 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240123223039.1471557-1-abhishekpandit@google.com> <20240123143026.v1.3.Idf7d373c3cbb54058403cb951d644f1f09973d15@changeid> In-Reply-To: From: Abhishek Pandit-Subedi Date: Wed, 24 Jan 2024 14:57:21 -0800 Message-ID: Subject: Re: [PATCH v1 3/3] usb: typec: ucsi: Get PD revision for partner To: Prashant Malani Cc: Abhishek Pandit-Subedi , Heikki Krogerus , linux-usb@vger.kernel.org, jthies@google.com, Andy Shevchenko , Bjorn Andersson , Dmitry Baryshkov , Fabrice Gasnier , Greg Kroah-Hartman , Hans de Goede , Neil Armstrong , Saranya Gopal , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jan 24, 2024 at 11:34=E2=80=AFAM Prashant Malani wrote: > > On Wed, Jan 24, 2024 at 11:18=E2=80=AFAM Abhishek Pandit-Subedi > wrote: > > > > On Wed, Jan 24, 2024 at 10:49=E2=80=AFAM Prashant Malani wrote: > > > > > > Hi Abhishek, > > > > > > On Tue, Jan 23, 2024 at 2:30=E2=80=AFPM Abhishek Pandit-Subedi > > > wrote: > > > > > > > > From: Abhishek Pandit-Subedi > > > > > > > > PD major revision for the port partner is described in > > > > GET_CONNECTOR_CAPABILITY and is only valid on UCSI 2.0 and newer. U= pdate > > > > the pd_revision on the partner if the UCSI version is 2.0 or newer. > > > > > > > > Signed-off-by: Abhishek Pandit-Subedi > > > > --- > > > > $ cat /sys/class/typec/port2-partner/usb_power_delivery_revision > > > > 3.0 > > > > > > > > drivers/usb/typec/ucsi/ucsi.c | 25 +++++++++++++++++++++++++ > > > > drivers/usb/typec/ucsi/ucsi.h | 3 +++ > > > > 2 files changed, 28 insertions(+) > > > > > > > > diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi= /ucsi.c > > > > index 4edf785d203b..8e0a512853ba 100644 > > > > --- a/drivers/usb/typec/ucsi/ucsi.c > > > > +++ b/drivers/usb/typec/ucsi/ucsi.c > > > > @@ -782,6 +782,8 @@ static int ucsi_register_partner(struct ucsi_co= nnector *con) > > > > } > > > > > > > > desc.usb_pd =3D pwr_opmode =3D=3D UCSI_CONSTAT_PWR_OPMODE_P= D; > > > > + desc.pd_revision =3D > > > > + UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD(con->c= ap.flags); > > > > > > > > partner =3D typec_register_partner(con->port, &desc); > > > > if (IS_ERR(partner)) { > > > > @@ -856,6 +858,28 @@ static void ucsi_partner_change(struct ucsi_co= nnector *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)) > > > > > > (Mentioned side-band but reproducing here for consistency) > > > This macro is unnecessary. It's just doing a comparison, which can be= inlined > > > without any perceptible change in readability (actually, I'd argue ad= ding the ! > > > to an english idiom makes things *less* readable): > > > > I prefer the macro because it makes it easier to search where version > > checks are being done. > > I don't see how searching for "IS_MIN_VERSION_2_0" is easier > than just searching for "UCSI_VERSION_2_0". > > I didn't quite understand what you meant by > > > it keeps the `<` vs `<=3D` consistent. > > Perhaps I'm missing something... (are these comparisons being > used elsewhere/in some other fashion?). Let's say someone wants to guard code for UCSI 2.0. Should they use: // Guard against older versions. if (ucsi->version < UCSI_VERSION_2_0) return; // This also guards since the version jumps from 1.2 to 2.0. if (ucsi->version <=3D UCSI_VERSION_1_2) return; // Only do something on newer versions. if (ucsi->version >=3D UCSI_VERSION_2_0) { // Fill out something available in newer spec. } I'd rather everyone just use a macro that normalizes comparisons. It's always IS_MIN_VERSION and its inverse !IS_MIN_VERSION. It's personal preference so deferring to the maintainer is IMO the right call here. > > In any case, I don't want to bike-shed so I'll defer to the > maintainer's call on this. > > BR, > > -Prashant