Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp983654rdb; Wed, 24 Jan 2024 00:46:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IHgtnvxD6QMPCAvNr0BhmcE5Zko+fUe7PqGF8kltxmFWzM++lvScNLWlGDiCGxNjgtV3ujL X-Received: by 2002:a05:6a20:f94:b0:19a:2dc0:ee68 with SMTP id ga20-20020a056a200f9400b0019a2dc0ee68mr291995pzb.63.1706085975148; Wed, 24 Jan 2024 00:46:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706085975; cv=pass; d=google.com; s=arc-20160816; b=inzX5A9Y/LH/la1bNuQq4HmtYLgel+VTHFZE835xzHluodQAOVcq8TiQ2Ht9BONXOl A+SewTRV8jTddl9ULyXuZdG6A5R/k4G1iBbl97te08jSpcn+9o7h3rpTSQrc4SzM6OZF Qn6JAFL/TKsGCfCADmLPKMTtClx+5vbau436EZefyT9vYr5xgmzrSRbsXKQKKGXsfMGy xYJq4DCFR0UBt1C+IMotu/5vxNokBtMONIGiH9EwmgMMlEmfbF3tD0VaN36WMtdymOjY 3AquQfBI3HlWVmAf4UjjfqA8kbT+jbDs3OBtJPDNt2co1XvXlxxURO5pniNG5/Uaiwuz 002w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=xHnMGTip0k5WQr/ocF61LjVmzrROreb8ZXQsvgEPM10=; fh=uo+Qjif8WccLSAZvn/aGCUt99GimjWEru4PGG0D10Bw=; b=S1kYmzJsZlouWfmx9D9ax+0DMQYZE+dCRlwMullLgONB4/FjdjO1bcbKKNkz01SRyz TzLJat1bzPUpAxR2BOZ6gxAXY8HEQNp3G7+NEr+gNo1aePtCuP5acig4yKuxm1bdVdNX M1n1Fey61gQDdjwfnV26T7Yx1vnbm2WksmMJMsXClFPW0391bgFYuGIDbO2ckFlwQ7rj kJ1e1Xn1c6d28vE+vFwDiLZGoR79w1lzTEYXupfBi4r1qb51WcucN/GN5rbztEyq95LH 7z2mm5iq7aV8dPMZ+RRjJflvvyrxjqMCe7oEFs/cVy7PuEvUrYa89HotYkFhyn4wsyia bNGA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="eb5fDZ/D"; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-36631-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36631-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id f36-20020a631f24000000b0058556a636dbsi10968023pgf.434.2024.01.24.00.46.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 00:46:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36631-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="eb5fDZ/D"; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-36631-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36631-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 8900EB28FA5 for ; Wed, 24 Jan 2024 08:23:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C4841756B; Wed, 24 Jan 2024 08:22:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="eb5fDZ/D" Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 38CBF1774E for ; Wed, 24 Jan 2024 08:22:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706084562; cv=none; b=M0KdhEm3Man6v2Dt5Vx8RGwGhwVQAUCByaKsBHyTq8mwH/iVx+WapsCe/usP8qW0r82KuXj+RLbnSFK+sWdwe2r8WFtp/9QiOyHb+JN3moS8kHafs+0wkR9Y0e/eBP+IQnafpotmP4+3yrExQ2po0MQiAu4kl9X3Nq4Ev/HvRJM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706084562; c=relaxed/simple; bh=GwYYyIKHpPbisEwWC6WETTohGHFFDsZNlW29Ta37IRU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tQ20xxMV2Adf+tvVg5kI++x3WGoP3ePWmFxx8UwfWPUb2V/kcYZR8pPsS5Okh+hru+9f6hgbLX2cj1lb7fJCmACvVv8NFo4eXu8fYD/nnEFGifpLpMaeikfseUKY8i+1KHU1dFeoNHmh9L+Bb325PlxujjB6Rio+z0fZR43QNFA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=eb5fDZ/D; arc=none smtp.client-ip=209.85.215.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-5d42e7ab8a9so633452a12.3 for ; Wed, 24 Jan 2024 00:22:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706084559; x=1706689359; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=xHnMGTip0k5WQr/ocF61LjVmzrROreb8ZXQsvgEPM10=; b=eb5fDZ/DgdxAvh1qiMCYwQGoY6EeTDznvXpToqOE4i37MCsStZSxiCXJQI/HS8RAnm Pc+dNHBYCkxk2DnCezCoN9zhqg383U67VurebYOiWc3t2cFsOI5OHOClRL2SUmIWet+L OmbglyBreoy0XfwKP++GRtkL5+Rkqy1hD92/VKYA7OnWEzxNxEAGQuv3cwskmqkRWtFB 4PSzz4Vxom9bJnOWSeeuHplf4sS/mJSDMrbi/5UXgBveCZXA612iug/a/rZ0r1pPKtMs nua1kkaZV5uMtqEaBoYFhfjjPNo7epf2xSrEY8WavA1Ak/9squqi9KGooAHaIf/ewOSL afOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706084559; x=1706689359; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xHnMGTip0k5WQr/ocF61LjVmzrROreb8ZXQsvgEPM10=; b=usSLnzno6vTJC14xNNy/KeXlWLJO2WRvESPFEakxR18lS2tyXIUdRbyvinZZ1s3Cf3 L4LfyHkrRagnGaR/V8BYXZZMaEaVNEs3tN1hwwFxb9VUgBhl1oSqjacAQsvL3okREVdX f68lN3PPtuV3WlYpBVkG7DwwQ8sFT02KeWz0Ydhr7QH9ezGnOfGM3GRmQzUjfPVxD1bn UT4ypiOJIOnNld8z8qxsgIgLc6LC6w/jrU1YQU23seQJ5m/srIoXCNOtaWMywzn0H23U dc+t3QGtf9UgWhE4+pMPO0M7rYMRBaJIuBz08R0jHqmvwLG9UHFX4pGy/DSkG2H6YrbY CPkg== X-Gm-Message-State: AOJu0YwfU+D4EvgaX5z7HI0q86LsiJ5Yzvo62TAQauY4ydiPJg2mmKkx 5hZBKSUyMr841GFYEz9/1Srern+B7RtLzArorSApdVB95UpY6blSQIlRt6hJYQ== X-Received: by 2002:a05:6a20:6115:b0:19c:32cf:8ff2 with SMTP id m21-20020a056a20611500b0019c32cf8ff2mr273690pzb.79.1706084559474; Wed, 24 Jan 2024 00:22:39 -0800 (PST) Received: from thinkpad ([117.217.189.109]) by smtp.gmail.com with ESMTPSA id z66-20020a626545000000b006dbe6eba197sm4768321pfb.217.2024.01.24.00.22.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 00:22:39 -0800 (PST) Date: Wed, 24 Jan 2024 13:52:31 +0530 From: Manivannan Sadhasivam To: Nitin Rawat Cc: Bjorn Andersson , Konrad Dybcio , Vinod Koul , Kishon Vijay Abraham I , "James E.J. Bottomley" , "Martin K. Petersen" , Philipp Zabel , linux-arm-msm@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, Can Guo , Naveen Kumar Goud Arepalli Subject: Re: [PATCH V1 1/2] scsi: ufs: qcom : Refactor phy_power_on/off calls Message-ID: <20240124082231.GA4906@thinkpad> References: <20240112153348.2778-1-quic_nitirawa@quicinc.com> <20240112153348.2778-2-quic_nitirawa@quicinc.com> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240112153348.2778-2-quic_nitirawa@quicinc.com> On Fri, Jan 12, 2024 at 09:03:47PM +0530, Nitin Rawat wrote: > Commit 3f6d1767b1a0 ("phy: ufs-qcom: Refactor all init steps into > phy_poweron") removes the phy_power_on/off from ufs_qcom_setup_clocks s/removes/moved > to suspend/resume func. > > To have a better power saving, remove the phy_power_on/off calls from > resume/suspend path and put them back to ufs_qcom_setup_clocks, so that > PHY's regulators & clks can be turned on/off along with UFS's clocks. > > Since phy phy_power_on is separated out from phy calibrate, make > separate calls to phy_power_on and phy_calibrate calls from ufs qcom > driver. > Above change should be in a separate patch. > Also add a mutex lock to protect the usage of is_phy_pwr_on against > possible racing. > > Co-developed-by: Can Guo > Signed-off-by: Can Guo > Co-developed-by: Naveen Kumar Goud Arepalli > Signed-off-by: Naveen Kumar Goud Arepalli > Signed-off-by: Nitin Rawat > --- > drivers/ufs/host/ufs-qcom.c | 104 +++++++++++++++++++++++------------- > drivers/ufs/host/ufs-qcom.h | 4 ++ > 2 files changed, 72 insertions(+), 36 deletions(-) > > diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c > index 39eef470f8fa..2721a30f0db8 100644 > --- a/drivers/ufs/host/ufs-qcom.c > +++ b/drivers/ufs/host/ufs-qcom.c > @@ -338,6 +338,46 @@ static u32 ufs_qcom_get_hs_gear(struct ufs_hba *hba) > return UFS_HS_G3; > } > > +static int ufs_qcom_phy_power_on(struct ufs_hba *hba) > +{ > + struct ufs_qcom_host *host = ufshcd_get_variant(hba); > + struct phy *phy = host->generic_phy; > + int ret = 0; > + > + mutex_lock(&host->phy_mutex); You do not need mutex to protect a variable. If you want to ensure that the access to the flag is atomic, you can use test_and_{set/clear}_bit helpers. > + if (!host->is_phy_pwr_on) { > + ret = phy_power_on(phy); > + if (ret) { > + mutex_unlock(&host->phy_mutex); > + return ret; > + } > + host->is_phy_pwr_on = true; > + } > + mutex_unlock(&host->phy_mutex); > + > + return ret; > +} > + > +static int ufs_qcom_phy_power_off(struct ufs_hba *hba) > +{ > + struct ufs_qcom_host *host = ufshcd_get_variant(hba); > + struct phy *phy = host->generic_phy; > + int ret = 0; > + > + mutex_lock(&host->phy_mutex); > + if (host->is_phy_pwr_on) { > + ret = phy_power_off(phy); > + if (ret) { > + mutex_unlock(&host->phy_mutex); > + return ret; > + } > + host->is_phy_pwr_on = false; > + } > + mutex_unlock(&host->phy_mutex); > + > + return ret; > +} > + > static int ufs_qcom_power_up_sequence(struct ufs_hba *hba) > { > struct ufs_qcom_host *host = ufshcd_get_variant(hba); > @@ -378,13 +418,18 @@ static int ufs_qcom_power_up_sequence(struct ufs_hba *hba) > goto out_disable_phy; > > /* power on phy - start serdes and phy's power and clocks */ > - ret = phy_power_on(phy); > + ret = ufs_qcom_phy_power_on(hba); > if (ret) { > dev_err(hba->dev, "%s: phy power on failed, ret = %d\n", > __func__, ret); > goto out_disable_phy; > } > > + ret = phy_calibrate(phy); > + if (ret) { > + dev_err(hba->dev, "%s: Failed to calibrate PHY %d\n", > + __func__, ret); Even though the driver already has a lot of "__func__" to print the function names in error log, please do not add more. I will get rid of the existing ones at some point. - Mani -- மணிவண்ணன் சதாசிவம்