Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp103909rdb; Sat, 2 Sep 2023 01:48:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGm3r0CpBaYBShPT3ebh7CS6W6/sLe3B8iiSeSCPVLwFSe1gAatY/jEHxSWaIB93J8aA5RL X-Received: by 2002:a05:6870:b49f:b0:1d0:c03c:897e with SMTP id y31-20020a056870b49f00b001d0c03c897emr5434089oap.12.1693644497244; Sat, 02 Sep 2023 01:48:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693644497; cv=none; d=google.com; s=arc-20160816; b=xLGxPyhjhjLwy+E6J08QXNAFZ6ZyKylOuI0T8KmcDSDiK2GLINlM374oIlRX1Pg18z mcFIWUlrhimYf3BrlKdNo/a3FBujiw4/CIDqn68gVwQnd0zbk+rh4oyK/K3GuBaWAa5T aoHbSNg7ksqkssz/gtMBwFPV+KVtkn6Ax+7ogiDtG6okavcgArpv0M2BniHdXgavWrgZ w+PIrOIF6btC+XNI9Zym49IMniF3JWY8mGgI8nwts/mVTCJGZY3PooiEKM6vi69xZ78p 0M8gbmPYC+ENtV2g4UBiKkG/mYb6ORFwk10W/wYQPgGFZPfZIQ83+NIid0R+Npo6wO7x 09gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=/LDI4xbTTZJEZhw8SQsuXul4NtFZ4wMk1vLaQ+gPH08=; fh=2dt3Kp+l4XBRp1RD+gVhd9yuJjH8khlqjCqbR7yesQk=; b=iyDXtu4Vvg+o9ZUVkcKBcKsfyEez3mWXaoWY+183Fj1/2Ij8G4tzzx96XvjbPxKLGM y3aXHgtMmvaEy5Ic2wt8bQXPpVOUPORfyeF8bZwt/pQyuCI7ZaJgtV+b/+LP8UyVfLDq r0N0WA8hyrXUMOZk+TpzefJ47JqSY37OiiI/j3VtUFRY7B51kJE832dr3NRxBWwVGsH/ p2MWXY9JGjMULHBGKHvoke1/E08M6y3jDWJPcoCCTP3GxTWDT4gKp8HNmo4WYIVsy/bm k402S7qCr1tSDrP0pjrp+v+y3DPJA9EAxrVS251y5TGSJiYvMPa3RP06Y4coDySuyVzn 5wOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Dm+uNPVn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n24-20020a63f818000000b0056476f15584si4272873pgh.541.2023.09.02.01.48.04; Sat, 02 Sep 2023 01:48:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Dm+uNPVn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349268AbjIALow (ORCPT + 99 others); Fri, 1 Sep 2023 07:44:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233935AbjIALop (ORCPT ); Fri, 1 Sep 2023 07:44:45 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0E0710F5; Fri, 1 Sep 2023 04:44:05 -0700 (PDT) Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 381808lw027521; Fri, 1 Sep 2023 11:43:44 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; s=qcppdkim1; bh=/LDI4xbTTZJEZhw8SQsuXul4NtFZ4wMk1vLaQ+gPH08=; b=Dm+uNPVnOMxOnIZ32zHbP6RJ520f1+/64YWg4wb44MZuBb5V3o5tP6umWMwbokmYYt9e HkGDpOAkwBhMuIPbPsD5FwycAfmhNIz4o7h7TumnHazHiFO13pq2wuTZUgEQdYgHsiBU G58hqmr7E6rR3r268Z95+5x2DTIs64+cjl/jwDpUQ+QDuNrvppPjLju74bWRKEp4WUZ/ kZE+1bNPCXvWpmFzbK2+86DPvHEH7Ga49D/LkARoEbKUTfX5VXPB2R5+Z9Foyo9mp1Tv 3/XR1y6vwJFb+K93D++soVF5rxhDRhwrB1fcxPQxZ+iKU2o9H3mCx8XJbE4V7DUXjN1U vw== 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 3suc22ggjn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 01 Sep 2023 11:43:43 +0000 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 381BhevY014674; Fri, 1 Sep 2023 11:43:40 GMT Received: from pps.reinject (localhost [127.0.0.1]) by APBLRPPMTA01.qualcomm.com (PPS) with ESMTP id 3sqafmj081-1; Fri, 01 Sep 2023 11:43:40 +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 381BgpDE013971; Fri, 1 Sep 2023 11:43:40 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 381BhegY014667; Fri, 01 Sep 2023 11:43:40 +0000 Received: by hu-maiyas-hyd.qualcomm.com (Postfix, from userid 2342877) id 960BD5006A6; Fri, 1 Sep 2023 17:13:39 +0530 (+0530) From: Nitin Rawat To: mani@kernel.org, agross@kernel.org, andersson@kernel.org, konrad.dybcio@linaro.org, jejb@linux.ibm.com, martin.petersen@oracle.com Cc: quic_cang@quicinc.com, quic_nguyenb@quicinc.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Nitin Rawat , Naveen Kumar Goud Arepalli Subject: [PATCH V6 2/6] scsi: ufs: qcom: Configure PA_VS_CORE_CLK_40NS_CYCLES Date: Fri, 1 Sep 2023 17:13:32 +0530 Message-Id: <20230901114336.31339-3-quic_nitirawa@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901114336.31339-1-quic_nitirawa@quicinc.com> References: <20230901114336.31339-1-quic_nitirawa@quicinc.com> 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: Sij0xJ03g9MOQxKB-T5-bejpP2X-pCu7 X-Proofpoint-ORIG-GUID: Sij0xJ03g9MOQxKB-T5-bejpP2X-pCu7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-01_09,2023-08-31_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 clxscore=1015 mlxscore=0 impostorscore=0 suspectscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 lowpriorityscore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309010109 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Configure PA_VS_CORE_CLK_40NS_CYCLES with frequency of unipro core clk for Qualcomm UFS controller V4.0 and onwards to align with the hardware specification. 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 | 47 ++++++++++++++++++++++++++++--------- drivers/ufs/host/ufs-qcom.h | 2 ++ 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c index fe36003faaa8..018e391c276e 100644 --- a/drivers/ufs/host/ufs-qcom.c +++ b/drivers/ufs/host/ufs-qcom.c @@ -93,8 +93,9 @@ static const struct __ufs_qcom_bw_table { static struct ufs_qcom_host *ufs_qcom_hosts[MAX_UFS_QCOM_HOSTS]; static void ufs_qcom_get_default_testbus_cfg(struct ufs_qcom_host *host); -static int ufs_qcom_set_dme_vs_core_clk_ctrl_clear_div(struct ufs_hba *hba, - u32 clk_cycles); +static int ufs_qcom_set_core_clk_ctrl(struct ufs_hba *hba, + u32 clk_cycles, + u32 clk_40ns_cycles); static struct ufs_qcom_host *rcdev_to_ufs_host(struct reset_controller_dev *rcd) { @@ -690,8 +691,8 @@ static int ufs_qcom_link_startup_notify(struct ufs_hba *hba, * set unipro core clock cycles to 150 & clear clock * divider */ - err = ufs_qcom_set_dme_vs_core_clk_ctrl_clear_div(hba, - 150); + err = ufs_qcom_set_core_clk_ctrl(hba, + 150, 6); /* * Some UFS devices (and may be host) have issues if LCC is @@ -1295,12 +1296,12 @@ static void ufs_qcom_exit(struct ufs_hba *hba) phy_power_off(host->generic_phy); phy_exit(host->generic_phy); } - -static int ufs_qcom_set_dme_vs_core_clk_ctrl_clear_div(struct ufs_hba *hba, - u32 cycles_in_1us) +static int ufs_qcom_set_core_clk_ctrl(struct ufs_hba *hba, + u32 cycles_in_1us, + u32 cycles_in_40ns) { struct ufs_qcom_host *host = ufshcd_get_variant(hba); - u32 core_clk_ctrl_reg; + u32 core_clk_ctrl_reg, reg; int ret; ret = ufshcd_dme_get(hba, @@ -1325,9 +1326,33 @@ static int ufs_qcom_set_dme_vs_core_clk_ctrl_clear_div(struct ufs_hba *hba, /* Clear CORE_CLK_DIV_EN */ core_clk_ctrl_reg &= ~DME_VS_CORE_CLK_CTRL_CORE_CLK_DIV_EN_BIT; - return ufshcd_dme_set(hba, + err = ufshcd_dme_set(hba, UIC_ARG_MIB(DME_VS_CORE_CLK_CTRL), core_clk_ctrl_reg); + /* + * UFS host controller V4.0.0 onwards needs to program + * PA_VS_CORE_CLK_40NS_CYCLES attribute per programmed + * frequency of unipro core clk of UFS host controller. + */ + if (!err && (host->hw_ver.major >= 4)) { + if (cycles_in_40ns > PA_VS_CORE_CLK_40NS_CYCLES_MASK) + return -EINVAL; + + err = ufshcd_dme_get(hba, + UIC_ARG_MIB(PA_VS_CORE_CLK_40NS_CYCLES), + ®); + if (err) + return err; + + reg &= ~PA_VS_CORE_CLK_40NS_CYCLES_MASK; + reg |= cycles_in_40ns; + + err = ufshcd_dme_set(hba, + UIC_ARG_MIB(PA_VS_CORE_CLK_40NS_CYCLES), + reg); + } + + return err; } static int ufs_qcom_clk_scale_up_pre_change(struct ufs_hba *hba) @@ -1344,7 +1369,7 @@ static int ufs_qcom_clk_scale_up_post_change(struct ufs_hba *hba) return 0; /* set unipro core clock cycles to 150 and clear clock divider */ - return ufs_qcom_set_dme_vs_core_clk_ctrl_clear_div(hba, 150); + return ufs_qcom_set_core_clk_ctrl(hba, 150, 6); } static int ufs_qcom_clk_scale_down_pre_change(struct ufs_hba *hba) @@ -1380,7 +1405,7 @@ static int ufs_qcom_clk_scale_down_post_change(struct ufs_hba *hba) return 0; /* set unipro core clock cycles to 75 and clear clock divider */ - return ufs_qcom_set_dme_vs_core_clk_ctrl_clear_div(hba, 75); + return ufs_qcom_set_core_clk_ctrl(hba, 75, 3); } static int ufs_qcom_clk_scale_notify(struct ufs_hba *hba, diff --git a/drivers/ufs/host/ufs-qcom.h b/drivers/ufs/host/ufs-qcom.h index 8a9d3dbec297..d81bf1a1b77a 100644 --- a/drivers/ufs/host/ufs-qcom.h +++ b/drivers/ufs/host/ufs-qcom.h @@ -132,6 +132,8 @@ enum { #define CLK_1US_CYCLES_MASK_V4 GENMASK(27, 16) #define CLK_1US_CYCLES_MASK GENMASK(7, 0) #define DME_VS_CORE_CLK_CTRL_CORE_CLK_DIV_EN_BIT BIT(8) +#define PA_VS_CORE_CLK_40NS_CYCLES 0x9007 +#define PA_VS_CORE_CLK_40NS_CYCLES_MASK GENMASK(6, 0) static inline void ufs_qcom_get_controller_revision(struct ufs_hba *hba, -- 2.17.1