Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1323964rdb; Wed, 24 Jan 2024 11:20:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IEgL2Ak7xk/05uTHCY/cm0ztfydHHAKVBpUOhvqaBjf6aafjODmQbjtfbCb6B3BpYoH8zFW X-Received: by 2002:a17:906:4e82:b0:a31:3162:4a71 with SMTP id v2-20020a1709064e8200b00a3131624a71mr643481eju.62.1706124023435; Wed, 24 Jan 2024 11:20:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706124023; cv=pass; d=google.com; s=arc-20160816; b=QFsuqk4E01P6l3g7cxzozyd5tz2wkkD1PwHAWiprBHvuAUUb9bGvEX+3f/+vGOWZrK qNZHCnuOhjvj4iP6+LKM6tj6+uDilEPF9crU46KgS9WANbggV9h5MvrKgqXC/tWgWxBy c2wN2LXf6nHCmck1E5hGdLuycKJy0A9z0SzbyIQQlGn+UX2t4DvI4s65PU4CiClC0s6N Arj06ikIYmpr4edydVG2lkq+9DaEv/YPFYJslQ3nfF9OKzc6iXYzmxkFy2ZGOBAuYJ0X 16aqzuyrsmJT+lGsYhThLKO+4Yz6yuxnpYdiSjBp8EVgAZ4UMAlvHXbx8lVYLs89WM0P Q65g== 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=kZihvGpOcawyRovSQi/D7nIlqL4G312PpvkN2EuN+3I=; fh=Al9HDZEaHSEtCh28WOxs1Cyej0WBmp8KjtZ7yAyqgdM=; b=THl++MRegh97ajUK68YINWSALyTC2OxbPF4s/EosB2tsW79/+KeSqkCNOqqZm3GeWB OW9eNoGBa62rD5IGfi0BoN0tvjONl+p5va3onS7vzsZE9ziJMXY382/8a5NddsykY0RI 7yX22WN/QZZnAROk3F7/GhVUyFab0MoJsSoMZIwU2ieiJDvQDo3fx0J8puVnHDUSuNiQ cO4vLIyn2nH5PfGevCNjN7YxP6h+w0ol7OPJkB0HpHFo6B2TvuxsWfx1uEryXcJ8AMvt jDd1kA8O7ABTVYymSqBK7u+gnppgpOQcbYT9P5biSxLkRdVd6QHxxQlBQzigsYapjkeF oPVw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="XtXzOK/v"; 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-37589-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37589-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id kf15-20020a17090776cf00b00a315c3010edsi87246ejc.626.2024.01.24.11.20.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 11:20:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37589-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="XtXzOK/v"; 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-37589-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37589-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 015221F21E22 for ; Wed, 24 Jan 2024 19:20:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A29B81339BB; Wed, 24 Jan 2024 19:18:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="XtXzOK/v" Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) (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 1A6951339AA for ; Wed, 24 Jan 2024 19:18:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706123932; cv=none; b=DVa1/QzlkY4+0ExsshfjXpgXvr4mWtGKcYdKQydaubeSdFuqGJRF025oTDg1CtjNVI/FlLAD71jicP96XYfKMnIEVOxTm1gwMnbFWNbS6Sr/Tl9j5ZD8jW+XHZRD9VGnsuZydsErIwthSKF2zstvHvF2/BsfZhJyYxAxqUoNeQc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706123932; c=relaxed/simple; bh=Kkxze+OHG8vVSjBJo2EbnIrie86i6OnbPjB0P6moSbw=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=oplxpm6wNI5Z1TVMtAX/CqlaDbeC03wLPXL5ExCbakCzL0Qz2uo8B5/NKScs/xOjVFBc4fijRCNmMLnSc+kcnDdrsA1+BY4morJerxVoUmNdvVFA5+PrJZVnixfuOZmlK1Cn2GDzHaQD8zdlW63gqO1lCAu+baIKf/joYZXtAHw= 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=XtXzOK/v; arc=none smtp.client-ip=209.85.219.175 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-f175.google.com with SMTP id 3f1490d57ef6-dc223463ee4so5261467276.2 for ; Wed, 24 Jan 2024 11:18:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1706123929; x=1706728729; 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=kZihvGpOcawyRovSQi/D7nIlqL4G312PpvkN2EuN+3I=; b=XtXzOK/v9jDb3PlsceMzqI1tK7avYg7ojmf7dSutSOZvCXg8vYpdj5i3rv2RVXRgJ5 kbr4HfrKkO5obfe0pxOX4AeJ9KOxqJln95fkEB2pKcImuA3DW5XMugKlVFSv29nEvaup vlI4U4Ya8KA/wFPXs/+iHhw7Zzy6GlTu27V3I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706123929; x=1706728729; 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=kZihvGpOcawyRovSQi/D7nIlqL4G312PpvkN2EuN+3I=; b=OKTUv1OY1NQ0eWMWv7kPCy9binFzwRe9RoeripffZlt0ceQNDFKRZX4AzXbybozcpZ 7gTpm60zkUJeCqpSWhl5513qx5UtUVFSmkW/nCWAalu7SqNcJynv/+12V3CJKg38otEr sVGHt/4zVFCBiNn1pjvMwK4CtPNjRWX2RiluAB/q693tlXxIbMdncgM4awmr5dqMV/lG bcatrgEA8hBhjYBKfyqysCy4B648nI7TrboOMvqOHycOZ8mxr8cF5SYBhYWusBfBzsJi wrq5kXZQAFMgW8CFvO5PHZw+WQlDtevPrbmYs5P0sLGsUHkT6chnfYQv71bqRnyQEcjR DV7w== X-Gm-Message-State: AOJu0YyuMYTm6hSx4Rvew0HV+PRDdShXD21SQXPxXCaBYEKopMpBFoup 46f90H646igBjB7j7kKV4x9UUvITsP41gnzWTYwSo34PWKX/9MhUO+OUAdSRZ3/4cnkTkc+p3W7 KdP4dhB8HwZGmmjP/W1nW8223p+UinPSkr86w X-Received: by 2002:a05:6902:48:b0:dc2:404c:7e93 with SMTP id m8-20020a056902004800b00dc2404c7e93mr961119ybh.25.1706123929099; Wed, 24 Jan 2024 11:18:49 -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 11:18:37 -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 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. Updat= e > > 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/ucs= i.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_connec= tor *con) > > } > > > > desc.usb_pd =3D pwr_opmode =3D=3D UCSI_CONSTAT_PWR_OPMODE_PD; > > + desc.pd_revision =3D > > + UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD(con->cap.f= lags); > > > > partner =3D typec_register_partner(con->port, &desc); > > if (IS_ERR(partner)) { > > @@ -856,6 +858,28 @@ static void ucsi_partner_change(struct ucsi_connec= tor *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 inl= ined > without any perceptible change in readability (actually, I'd argue adding= 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 and it keeps the `<` vs `<=3D` consistent. UCSI only has a few published revisions: 1.2, 2.0, 2.1 and 3.0 and major changes seem to have happened in 2.0 and 3.0 so there should be very few of these macros created/used. > > if (!con->partner && con->ucsi->version < UCSI_VERSION_2_0) > return 0; > > Besides that, I think you want an || operator instead of the && operator,= right? Good catch on that. It should be OR. i.e. if (!con->partner || !IS_MIN_VERSION_2_0(con->ucsi)) > > > + return 0; > > + > > + command =3D UCSI_GET_CONNECTOR_CAPABILITY | UCSI_CONNECTOR_NUMB= ER(con->num); > > + ret =3D ucsi_send_command(con->ucsi, command, &con->cap, sizeof= (con->cap)); > > + if (ret < 0) { > > + dev_err(con->ucsi->dev, "GET_CONNECTOR_CAPABILITY faile= d (%d)\n", ret); > > + return ret; > > + } > > + > > + typec_partner_set_pd_revision( > > + con->partner, > > + UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD(con->cap.f= lags)); > > + > > + return ret; > > +} > > + > > static int ucsi_check_connection(struct ucsi_connector *con) > > { > > u8 prev_flags =3D con->status.flags; > > Thanks,