Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2372767rdd; Fri, 12 Jan 2024 07:34:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+R5yppw5ZS5fxaWXzRum3gzwgmD0RmhUPuFmTUm6Zy9CRmBJDDQmuEDuWmNFWLbpqDikr X-Received: by 2002:a17:906:cb83:b0:a28:b7e2:15b4 with SMTP id mf3-20020a170906cb8300b00a28b7e215b4mr585304ejb.88.1705073670864; Fri, 12 Jan 2024 07:34:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705073670; cv=none; d=google.com; s=arc-20160816; b=mAPBI6mn0mDpYhdpq74Vsov2WoJ869gjoIoJLMFbgfczdhSsd8oYQ8kd+aQLdQ9k0k mEO6UHqmPQE8bZhkXhXis++KpoHID629UFt2cgubGxIP7JmC42nX0Ex05QSGaCKZ3y04 lic7KcpyMMYmW+x2fhOggejLKbx1Ay27n2XQAd+M1L1kcxWyScIvFHpfW63KnYlJ99g3 7nhBE6K8hxn08q5iiCEz85F+Pu9xLiCC2iOLA7Lm+1mxlkn/ocV4IOqQTNEA7Lg9yt7t S5P3/tclBiDJ0OHI0AoWMyzMir7zLZPYRBiVtl+IMUEgvHexVPHHjp1w7I66c51gZoYa HNUQ== ARC-Message-Signature: i=1; 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=FWdpznD+WATV6lsd5Q7E3hTBYhD+waON5oTBHAuv19U=; fh=cXPMU1i773ui82DR9DHIEI6VAOyB9+cu7yO/C9NFsZc=; b=d6iXSWl/qt1NtlqXygxEpifg6bTHNPW4Ldi78KsrGUErFA6/JqEybQKRYKsQ4jWKDi 5ZNeBcIgrkOqBD0P2iO2mvXNtAGpq78egEF5qseqhH0KVEQdsYdzmKpVRhqNu0VHUDAK U5PpIuRj1rDHIdk5jP/Veb1HhSSzXeL08u9OjGoNj8OY3KJmrTPWBA9lKbW1GG+f1ea2 eqm98ySE6qkS+VlLckWYZvJAFPPvg2ekuefwPtQADrnrdnuf1PWbG5vZRsDE1QKyS1ue MBPLokcRfzptp12bsqXW+KUN37Y/i4Nsnp+/Mf40i1h91+2ab+tV1cL1kkdbZzSKf3Zd xXqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=bA3fTadF; spf=pass (google.com: domain of linux-kernel+bounces-24806-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24806-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.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 a5-20020a1709063e8500b00a2a8b469164si1398158ejj.1034.2024.01.12.07.34.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 07:34:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24806-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=@quicinc.com header.s=qcppdkim1 header.b=bA3fTadF; spf=pass (google.com: domain of linux-kernel+bounces-24806-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24806-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.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 737341F23E9C for ; Fri, 12 Jan 2024 15:34:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6F2B96EB79; Fri, 12 Jan 2024 15:34:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="bA3fTadF" Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (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 DCA076EB52; Fri, 12 Jan 2024 15:34:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qualcomm.com Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 40CFWKGF015577; Fri, 12 Jan 2024 15:33:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=qcppdkim1; bh=FWdpznD +WATV6lsd5Q7E3hTBYhD+waON5oTBHAuv19U=; b=bA3fTadFhnevYrB2ARh9IVC E2wcnuloeqJ8cBI9qRD0dhj2cokkIarcpYaVPwE/tgC11UK484njE2dLRgLfSf84 IJTdvPoWstkv2dIQHyDAcYPYT8S5MYuxBL1On8x2IVia2Nm4UAnlQJbh8qF36vN+ 06ydk7LlSpJhXztvrEhVIUPe5/nbtnTvgABYDM37dCvk6gRuC/CTNYv+1HU2hNqC mwC4JKA8yuVZD71tFC7IozUAE3ckRHvRNcsrmB9Of580iqmWzeoIYYfdCnxZT4EO 2bZHrSTXABdYB7NCNv8gcivO7y3bqgKSrrWgm+7jX6KDydx4EXUChtsk/gAsH7w= = Received: from apblrppmta01.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.18.19]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vk4vsrd5f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 12 Jan 2024 15:33:56 +0000 (GMT) Received: from pps.filterd (APBLRPPMTA01.qualcomm.com [127.0.0.1]) by APBLRPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTP id 40CFXrQP032693; Fri, 12 Jan 2024 15:33:53 GMT Received: from pps.reinject (localhost [127.0.0.1]) by APBLRPPMTA01.qualcomm.com (PPS) with ESMTPS id 3veyxnj2yj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 12 Jan 2024 15:33:53 +0000 Received: from APBLRPPMTA01.qualcomm.com (APBLRPPMTA01.qualcomm.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40CFXrj8032686; Fri, 12 Jan 2024 15:33:53 GMT Received: from hu-maiyas-hyd.qualcomm.com (hu-nitirawa-hyd.qualcomm.com [10.213.109.152]) by APBLRPPMTA01.qualcomm.com (PPS) with ESMTP id 40CFXr1r032681; Fri, 12 Jan 2024 15:33:53 +0000 Received: by hu-maiyas-hyd.qualcomm.com (Postfix, from userid 2342877) id 3B295572C41; Fri, 12 Jan 2024 21:03:52 +0530 (+0530) From: Nitin Rawat To: Bjorn Andersson , Konrad Dybcio , Vinod Koul , Kishon Vijay Abraham I , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , Philipp Zabel Cc: linux-arm-msm@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, Nitin Rawat , Can Guo , Naveen Kumar Goud Arepalli Subject: [PATCH V1 1/2] scsi: ufs: qcom : Refactor phy_power_on/off calls Date: Fri, 12 Jan 2024 21:03:47 +0530 Message-ID: <20240112153348.2778-2-quic_nitirawa@quicinc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240112153348.2778-1-quic_nitirawa@quicinc.com> References: <20240112153348.2778-1-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-Transfer-Encoding: 8bit X-QCInternal: smtphost X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: C7N-JZh34DGIwAaF3Xk_088i4JIBFbE1 X-Proofpoint-ORIG-GUID: C7N-JZh34DGIwAaF3Xk_088i4JIBFbE1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_02,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 phishscore=0 suspectscore=0 malwarescore=0 impostorscore=0 spamscore=0 lowpriorityscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401120121 Commit 3f6d1767b1a0 ("phy: ufs-qcom: Refactor all init steps into phy_poweron") removes the phy_power_on/off from ufs_qcom_setup_clocks 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. 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); + 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); + } ufs_qcom_select_unipro_mode(host); return 0; @@ -557,26 +602,17 @@ static int ufs_qcom_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op, enum ufs_notify_change_status status) { struct ufs_qcom_host *host = ufshcd_get_variant(hba); - struct phy *phy = host->generic_phy; if (status == PRE_CHANGE) return 0; - if (ufs_qcom_is_link_off(hba)) { - /* - * Disable the tx/rx lane symbol clocks before PHY is - * powered down as the PLL source should be disabled - * after downstream clocks are disabled. - */ + if (!ufs_qcom_is_link_active(hba)) ufs_qcom_disable_lane_clks(host); - phy_power_off(phy); - /* reset the connected UFS device during power down */ - ufs_qcom_device_reset_ctrl(hba, true); - } else if (!ufs_qcom_is_link_active(hba)) { - ufs_qcom_disable_lane_clks(host); - } + /* reset the connected UFS device during power down */ + if (ufs_qcom_is_link_off(hba) && host->device_reset) + ufs_qcom_device_reset_ctrl(hba, true); return ufs_qcom_ice_suspend(host); } @@ -584,26 +620,11 @@ static int ufs_qcom_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op, static int ufs_qcom_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op) { struct ufs_qcom_host *host = ufshcd_get_variant(hba); - struct phy *phy = host->generic_phy; int err; - if (ufs_qcom_is_link_off(hba)) { - err = phy_power_on(phy); - if (err) { - dev_err(hba->dev, "%s: failed PHY power on: %d\n", - __func__, err); - return err; - } - - err = ufs_qcom_enable_lane_clks(host); - if (err) - return err; - - } else if (!ufs_qcom_is_link_active(hba)) { - err = ufs_qcom_enable_lane_clks(host); - if (err) - return err; - } + err = ufs_qcom_enable_lane_clks(host); + if (err) + return err; return ufs_qcom_ice_resume(host); } @@ -908,6 +929,7 @@ static int ufs_qcom_setup_clocks(struct ufs_hba *hba, bool on, enum ufs_notify_change_status status) { struct ufs_qcom_host *host = ufshcd_get_variant(hba); + int err; /* * In case ufs_qcom_init() is not yet done, simply ignore. @@ -926,10 +948,22 @@ static int ufs_qcom_setup_clocks(struct ufs_hba *hba, bool on, /* disable device ref_clk */ ufs_qcom_dev_ref_clk_ctrl(host, false); } + err = ufs_qcom_phy_power_off(hba); + if (err) { + dev_err(hba->dev, "%s: phy power off failed, ret=%d\n", + __func__, err); + return err; + } } break; case POST_CHANGE: if (on) { + err = ufs_qcom_phy_power_on(hba); + if (err) { + dev_err(hba->dev, "%s: phy power on failed, ret = %d\n", + __func__, err); + return err; + } /* enable the device ref clock for HS mode*/ if (ufshcd_is_hs_mode(&hba->pwr_info)) ufs_qcom_dev_ref_clk_ctrl(host, true); @@ -1110,7 +1144,7 @@ static void ufs_qcom_exit(struct ufs_hba *hba) struct ufs_qcom_host *host = ufshcd_get_variant(hba); ufs_qcom_disable_lane_clks(host); - phy_power_off(host->generic_phy); + ufs_qcom_phy_power_off(hba); phy_exit(host->generic_phy); } @@ -1536,9 +1570,7 @@ static void ufs_qcom_config_scaling_param(struct ufs_hba *hba, static void ufs_qcom_reinit_notify(struct ufs_hba *hba) { - struct ufs_qcom_host *host = ufshcd_get_variant(hba); - - phy_power_off(host->generic_phy); + ufs_qcom_phy_power_off(hba); } /* Resources */ diff --git a/drivers/ufs/host/ufs-qcom.h b/drivers/ufs/host/ufs-qcom.h index 9dd9a391ebb7..241dba01672e 100644 --- a/drivers/ufs/host/ufs-qcom.h +++ b/drivers/ufs/host/ufs-qcom.h @@ -215,6 +215,10 @@ struct ufs_qcom_host { u32 phy_gear; bool esi_enabled; + /* flag to check if phy is powered on */ + bool is_phy_pwr_on; + /* Protect the usage of is_phy_pwr_on against racing */ + struct mutex phy_mutex; }; static inline u32 -- 2.43.0