Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1389552rdb; Wed, 24 Jan 2024 13:51:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IH+QAwdy0/zTcrI7oMKOxHpMArudPjYfvrSacKzmMyUdqGi8PEkL57VrcNLXaOQ46OfGUch X-Received: by 2002:a17:906:1d4b:b0:a30:74da:41a0 with SMTP id o11-20020a1709061d4b00b00a3074da41a0mr290496ejh.71.1706133076714; Wed, 24 Jan 2024 13:51:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706133076; cv=pass; d=google.com; s=arc-20160816; b=PUEgowLjz2S+Qpyp7t89GY7w68+hJG/CkK+lia8Ew4BCchBYJykU5K+jX+th9gyHWN /y1gUcixVLhwk5Al1MzV1AyPqopEfnAEXQISI9lvnV8iSYY4GgQrgp8Q9E5YMxzbQkMN LUS41aFce2kGrP5jSLvSJFDHUYH6stw9TwASgRJpNPAM0Id2nXeZGASRQVcHsh1An5tN MVKy//BhJ2IKYoc84m6aOrXMS56deT6iNf6YOxC707HSWGGEoO470WW0CGztgSS0wxki RcW1dHZQfhGO0UAhJ9bWWeegQYyWepq0Rgj7p0PRl6w9baBZHoIJLCQ62hArRnSJQH+4 sGtA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=1i3cIgFM7vH1GhDS1T9+K33hCeiEOPlDdDY5WmLGi9M=; fh=0rRublaTVz+BRb0dhNkPJxz7+REher6SgdykjZ1gCgM=; b=EcQh9QP4cr5jN9eB58LD4kgXOolw8kU/e7o9pzZXfWiaEYlOmlaawP2P4e0aYKnDH0 4fljh7u3Zft3su6fa4IUL4FNrj5pnCyMKu7VzFUCTLNaYLG/B3/EZVnJT+g3yK1aTcnS qdgtgNlyQ/0DNqPRq8az2lycgbD93BcSIqScOQpUpMrXB6kAFdtvtxoT3s/+z926jOfx te21aikvGW3fz5i2GhYMjWD2bblG/Ddah0eKDxK765Nxw5yYMzyUpbfdmSfZR78znIIW Mrr40cGhAcvey2WdPLM6jTOuHaQ1g7gVf8xCcgcHg+Bh4XikN9OZ92ljP6qCHP6lpNAW B6RQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UPR7gDfu; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-37165-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37165-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l11-20020a1709060e0b00b00a30d3613cf0si266155eji.992.2024.01.24.13.51.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 13:51:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37165-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UPR7gDfu; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-37165-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37165-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 2BFD81F2305E for ; Wed, 24 Jan 2024 14:43:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B241B131E3B; Wed, 24 Jan 2024 14:31:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="UPR7gDfu" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E46013172C; Wed, 24 Jan 2024 14:31:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.55.52.120 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706106664; cv=none; b=CSc2f2Q1vg8Z6mfbrqR5SGTUMj/Ul+Fnh/s1AqAi6hvP2oSwebhsrQo9XG2cJcIOdVxaVT8bbArJovyfzR5eiLYh7uE8fatrrtLwoCOBz4fA/vbuFkrM4dUMBDMds4ry5285LLr2Q6LnkowRxO/+ZFr+tD+dMSaSJkq/xIKPA58= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706106664; c=relaxed/simple; bh=ZvKJm/sldQeRiwuP+FZg5ecSvivsElsr2/SHuRuOzBU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=j9v2fFAVybZciOzi50dmTgo4+lDXSsZxGJKX/FPDxBCjnUGBqB/tYTZi3+/A5r/MeQy7hHA4sYFPYtgUDxsxzQgMPNcu/xKccm+IyB4Iyrb9Z8cslJHb7do+dmJjjrSDq/Hk9QYzXLXlgNEZg4TpEB4uWK4KXdulCMo31ksd0x4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=UPR7gDfu; arc=none smtp.client-ip=192.55.52.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706106662; x=1737642662; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=ZvKJm/sldQeRiwuP+FZg5ecSvivsElsr2/SHuRuOzBU=; b=UPR7gDfurQ4/9OqZOUx3+WqVycaNv3qZJyT1nHXI/LrLbPHJ2fI5/v4v 2m0qH2dguZP75wYokoy9axZwNTDQEdnFWBvUWTGPkQ0MdDOFm8ZKpZKVb nHs7lb34x31SCokVJPaPyzu6R5z6i+qEFBb6Y8wd4vYf/c+DrT1uiZWHY RN6eB2gbYABWfim8Iijg9cYihuPyNP6oev8J20ERe9YaSrPF8xyx1kILW V4haLtpF8o4/a+PVzbJvtI7i3/RkhtUoDQgTqscD5xn7JtvXvHjqGXR84 7tFFeYJGVlZpB+KC0+j8JOQ0Lnbld/1GuC7ef4HxWkcnYnO4Jj0uVVjVc Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="400712685" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="400712685" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2024 06:30:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="929700627" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="929700627" Received: from kuha.fi.intel.com ([10.237.72.185]) by fmsmga001.fm.intel.com with SMTP; 24 Jan 2024 06:30:51 -0800 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Wed, 24 Jan 2024 16:30:50 +0200 Date: Wed, 24 Jan 2024 16:30:50 +0200 From: Heikki Krogerus To: Abhishek Pandit-Subedi Cc: linux-usb@vger.kernel.org, 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 , Saranya Gopal , linux-kernel@vger.kernel.org Subject: Re: [PATCH v1 3/3] usb: typec: ucsi: Get PD revision for partner Message-ID: References: <20240123223039.1471557-1-abhishekpandit@google.com> <20240123143026.v1.3.Idf7d373c3cbb54058403cb951d644f1f09973d15@changeid> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240123143026.v1.3.Idf7d373c3cbb54058403cb951d644f1f09973d15@changeid> Hi Abhishek, Few nitpicks for this one. On Tue, Jan 23, 2024 at 02:30:36PM -0800, 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. Update > 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_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); 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 +858,28 @@ 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)); 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 +949,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 94b373378f63..5e60328f398e 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) Probable better to use brackets also with that min_ver: #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) > -- > 2.43.0.429.g432eaa2c6b-goog thanks, -- heikki