From patchwork Wed Nov 22 07:10:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Can Guo X-Patchwork-Id: 168124 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp1145827vqb; Tue, 21 Nov 2023 23:12:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4mAHs5cQ6vqe7hlulq3zu2LKbPNXwiBK7zrDgqDMJWtrsTi6bxdNPIDFyaf6/VQhz/rdb X-Received: by 2002:aca:2115:0:b0:3ad:f6ad:b9c5 with SMTP id 21-20020aca2115000000b003adf6adb9c5mr1753111oiz.59.1700637169899; Tue, 21 Nov 2023 23:12:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700637169; cv=none; d=google.com; s=arc-20160816; b=i4R9UhpAB8s5pA4Gl7E7s2PcUqzyNtcO73nfuJTHqYVcMaQG+CAo1+AY1dJegJNu+L VAo9simdf53/yEoBy9PrZcu4UL5loAlX8WYc1YZfTOmheVmW0jTj08JVGQySb2UNnbzn +X6/fxBhb9EssPzfu0Ej1klr6PBRD2JpaTnWp+DWx46KrrELRdIDy5yt3U+zn/8yY7dg VYWF3ey0mlBFgDpcwGhGCwOilJKrgzTM75mE4F8gvxQIH7werTqFkKpeJlAaxCswG8U6 9d9RxG3Zrfy4HZo/29ZW8mF/PRlGo/kHpwGKYEgvz4mESHgZqABKM4LMTL2hai5WcNWV SosA== 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=DFF6SBown3zJI3vv5koqMtjckFgbW+mpaijN5lmrUrY=; fh=lalENY90My7TZJF1CKddC9t+QyXXuf4U+2P3z4+1hVM=; b=0ubIPYSBlqv6TgdTVIhkeIneaUdKWeLY0AITYDuPz10/M+zke3AoKbJUoSgG/r+CcG 8SIsO45ep0NZdNwWsfwPW5g/fo8Dml5/lP8NDEUMh3D9Md0uQVJhWVxZdPNhGMbNVp08 kg4IitSKwgi4JvHR0x9+UqaIn1kC1huzYPpxhGNgrGrwiG6Q8BgNwlFhEYxHgM69VmH1 o+ATiUIAQb7/PTglOU1BCHxpdvYTdP82KTrlD2Lp7AG/JKqlF+RyLABlD4dE9/bi1NKk ZF3zQMBI6uJMVuVUz0nfWWbZs0vp9LTrd4Cx9RGYZeEOFkf/Ro4hGSDlYISEQkEob89R kviQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=hf8rmGXB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id t10-20020a056a0021ca00b006cb8abd39d3si6780223pfj.180.2023.11.21.23.12.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 23:12:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=hf8rmGXB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 167D0802893B; Tue, 21 Nov 2023 23:12:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235023AbjKVHMB (ORCPT + 99 others); Wed, 22 Nov 2023 02:12:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230166AbjKVHLm (ORCPT ); Wed, 22 Nov 2023 02:11:42 -0500 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92BC81A8; Tue, 21 Nov 2023 23:11:38 -0800 (PST) Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AM4xb8F008924; Wed, 22 Nov 2023 07:11:12 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=DFF6SBown3zJI3vv5koqMtjckFgbW+mpaijN5lmrUrY=; b=hf8rmGXB2J/j0b8ugHJpdN7QTg5LkHyQBX4IO58EzgErCdO3TkqnwC/XJJm019urv50v Sb6FYowR93pb/R/qurIrEWhfisbjhRK+QgdQ1ueYKInvxtX89GxiryTe/yHeXTIBpQGk XXCYHJrN7fxzwWiWbShQJoEh3mzHDLsEwYwG3zsBwTnX6tvd9OboJvypcOJeVz6jd6+G sYk1wcBkv/IZUW7Nl1X3PBYcTgXxe6MpaYK/zNl7O4Opjr6JNL33IUD8bx36FLV8/1QP 9sZeoUZcQAayH4kG2GqNozIl2jorIEpKDZYgtwYpQJu1IOHWYCDfQnyUTa4ynV04BOsQ Lw== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3uh8mw8hdj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 22 Nov 2023 07:11:11 +0000 Received: from pps.filterd (NASANPPMTA02.qualcomm.com [127.0.0.1]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTP id 3AM77Vp9004501; Wed, 22 Nov 2023 07:11:11 GMT Received: from pps.reinject (localhost [127.0.0.1]) by NASANPPMTA02.qualcomm.com (PPS) with ESMTP id 3uepbmy82y-1; Wed, 22 Nov 2023 07:11:11 +0000 Received: from NASANPPMTA02.qualcomm.com (NASANPPMTA02.qualcomm.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3AM7BAD0011287; Wed, 22 Nov 2023 07:11:10 GMT Received: from stor-dylan.qualcomm.com (stor-dylan.qualcomm.com [192.168.140.207]) by NASANPPMTA02.qualcomm.com (PPS) with ESMTP id 3AM7BAnR011286; Wed, 22 Nov 2023 07:11:10 +0000 Received: by stor-dylan.qualcomm.com (Postfix, from userid 359480) id 5852C20A65; Tue, 21 Nov 2023 23:11:10 -0800 (PST) From: Can Guo To: quic_cang@quicinc.com, bvanassche@acm.org, mani@kernel.org, stanley.chu@mediatek.com, adrian.hunter@intel.com, beanhuo@micron.com, avri.altman@wdc.com, junwoo80.lee@samsung.com, martin.petersen@oracle.com Cc: "Bao D. Nguyen" , Andy Gross , Bjorn Andersson , Konrad Dybcio , "James E.J. Bottomley" , linux-arm-msm@vger.kernel.org (open list:UNIVERSAL FLASH STORAGE HOST CONTROLLER DRIVER...), linux-scsi@vger.kernel.org (open list:UNIVERSAL FLASH STORAGE HOST CONTROLLER DRIVER...), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 11/11] scsi: ufs: ufs-qcom: Add support for UFS device version detection Date: Tue, 21 Nov 2023 23:10:42 -0800 Message-Id: <1700637042-11104-12-git-send-email-quic_cang@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1700637042-11104-1-git-send-email-quic_cang@quicinc.com> References: <1700637042-11104-1-git-send-email-quic_cang@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: 2JxcIQFQgEb8s8n8GM-w4RcOHz2QZtsN X-Proofpoint-ORIG-GUID: 2JxcIQFQgEb8s8n8GM-w4RcOHz2QZtsN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-22_05,2023-11-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 clxscore=1015 mlxlogscore=999 adultscore=0 impostorscore=0 spamscore=0 bulkscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311220051 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 21 Nov 2023 23:12:46 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783247320934512073 X-GMAIL-MSGID: 1783247320934512073 From: "Bao D. Nguyen" A spare register in UFS host controller is used to indicate the UFS device version. The spare register is populated by bootloader for now, but in future it will be populated by HW automatically during link startup with its best efforts in any boot stages prior to Linux. During host driver init, read the spare register, if it is not populated with a UFS device version, go ahead with the dual init mechanism. If a UFS device version is in there, use the UFS device version together with host controller's HW version to decide the proper PHY gear which should be used to configure the UFS PHY without going through the second init. Signed-off-by: Bao D. Nguyen Signed-off-by: Can Guo --- drivers/ufs/host/ufs-qcom.c | 23 ++++++++++++++++++----- drivers/ufs/host/ufs-qcom.h | 2 ++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c index 7bbccf4..70bedd9 100644 --- a/drivers/ufs/host/ufs-qcom.c +++ b/drivers/ufs/host/ufs-qcom.c @@ -1070,15 +1070,28 @@ static void ufs_qcom_advertise_quirks(struct ufs_hba *hba) static void ufs_qcom_set_phy_gear(struct ufs_qcom_host *host) { struct ufs_host_params *host_params = &host->host_params; + u32 val, dev_major = 0; host->phy_gear = host_params->hs_tx_gear; - /* - * Power up the PHY using the minimum supported gear (UFS_HS_G2). - * Switching to max gear will be performed during reinit if supported. - */ - if (host->hw_ver.major < 0x5) + if (host->hw_ver.major < 0x5) { + /* + * Power up the PHY using the minimum supported gear (UFS_HS_G2). + * Switching to max gear will be performed during reinit if supported. + */ host->phy_gear = UFS_HS_G2; + } else { + val = ufshcd_readl(host->hba, REG_UFS_DEBUG_SPARE_CFG); + dev_major = FIELD_GET(GENMASK(7, 4), val); + + /* UFS device version populated, no need to do init twice */ + if (dev_major != 0) + host->hba->quirks &= ~UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH; + + /* For UFS 3.1 and older, apply HS-G4 PHY gear to save power */ + if (dev_major < 0x4 && dev_major > 0) + host->phy_gear = UFS_HS_G4; + } } static void ufs_qcom_set_host_params(struct ufs_hba *hba) diff --git a/drivers/ufs/host/ufs-qcom.h b/drivers/ufs/host/ufs-qcom.h index 11419eb..d12fc5a 100644 --- a/drivers/ufs/host/ufs-qcom.h +++ b/drivers/ufs/host/ufs-qcom.h @@ -54,6 +54,8 @@ enum { UFS_AH8_CFG = 0xFC, REG_UFS_CFG3 = 0x271C, + + REG_UFS_DEBUG_SPARE_CFG = 0x284C, }; /* QCOM UFS host controller vendor specific debug registers */