From patchwork Fri Dec 8 13:13:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitin Rawat X-Patchwork-Id: 175806 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5445134vqy; Fri, 8 Dec 2023 05:14:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCqGqS5mm1x6HViSIoNmy/ehNhJ4VSDMsfH9P3PK2hM5Tu5kf6raUc0pw4YkXOdSTElzOL X-Received: by 2002:a05:6e02:16c5:b0:35d:5dcb:1dbe with SMTP id 5-20020a056e0216c500b0035d5dcb1dbemr126800ilx.1.1702041239719; Fri, 08 Dec 2023 05:13:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702041239; cv=none; d=google.com; s=arc-20160816; b=Xl9H3QJJr+w79F/Jlhvyor9/sLLprICE0qSSldkaL1twotBJVcmI7yJVd4pqF8CH/p A5p6u1omlXRqifC/avwMXDDZEuAWd9fwlRpqxL1srU8dBChsEyDMsrHnQ+QpozD475DS g0hWe+Wh69xBr4drkRl/O1NuDtUcX67BQhlP99QCUlu2LXizVt9yb5ZjFcQ9Xhyso9DX JiUZZUaYm7KAWq+XDq6xe5ZjqkbKBGaNeCt3wsnC0WCa0NNstSPh3PniaUEj9X8Qe6bv pVXPnZzTzbDf6B85uldDJcbn9pOZEUDHmXYMZTUSBODZ5eIorYViSOnk6je5LBG6AKNy 17vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=ZTxNfR2A8QHWVwL5Rht1ivTbcC1bCutQJUKwUvWSP30=; fh=ibEjyX6RHuC3V8LQTLzyGDHKLuQUMVlxbfbVZdyemVM=; b=Y4d6F4Wbgrb2s7HIM9/ozxZ/H+oQA0pquFRBpK5qXccgH/enmdZRbrzAXrd9nuUZ0d F0laSvF+ldcmy54VkPqUKWYrrlzz/TQnNHD6YBVSNWjE648R7ZpZqeHCy4w7ggQojXrN 0++npspnQWLciRyASwkvH0fiw4PCbkpPZyk17P7tIv1+NKK1XB/ARswUrVkY0SIw+Xw3 e/GrvHVW07xmO7uVK4djat7ndtpCF2E6NbG8OlNXFGf8g8wNAzHOgA08zbgg0bF96YOo Z3lUbvMpeGtwMhpUcEXyffsDunXLQXItzxLnJvS3WY1NOkU5KZ/Xph8XToP8/sk+WFKS F5jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=MX3zl17y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id a5-20020a654185000000b005c677a35334si1493963pgq.670.2023.12.08.05.13.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 05:13:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=MX3zl17y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 040A882CB874; Fri, 8 Dec 2023 05:13:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573772AbjLHNNp (ORCPT + 99 others); Fri, 8 Dec 2023 08:13:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229844AbjLHNNn (ORCPT ); Fri, 8 Dec 2023 08:13:43 -0500 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E4DBE9; Fri, 8 Dec 2023 05:13:50 -0800 (PST) Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B8CaXkm016357; Fri, 8 Dec 2023 13:13:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id; s=qcppdkim1; bh=ZTxNfR2A8QHWVwL5Rht1ivTbcC1bCutQJUKwUvWSP30=; b=MX3zl17y/OZH3uBXN9GqMBAeQqfRMgmFIdh7unJ3nZ8TCM2Sh5DkgrQyKXAIE9GFwO/g fYTFKaYa+9Z3DR9Wil+epleFHQ0106Xfh4jUMfV51OWhfwTMNrrHMILkxtXW1ziYjlUV 2S4QrjsaamPwgfWmBnUXXMRqYrzuxsUtU+Xsqt4OCX+F47sc/LeFEvBjiEUNgiGk31hD XWxIWDC/wS19GXh8FgA5yqWpUPVof07SDfkMDGG+q9cpyTiSNeVQJh5IFbUwWe8rUjXH moqjQJCzO+ZyXgf57h1iegyak5EzLkG4y2dU45EfYDd/hiyZZ9f2ElQrH3oHl2q2Miau mw== 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 3uv1x5876v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 08 Dec 2023 13:13:38 +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 3B8DDYfR023256; Fri, 8 Dec 2023 13:13:34 GMT Received: from pps.reinject (localhost [127.0.0.1]) by APBLRPPMTA01.qualcomm.com (PPS) with ESMTPS id 3uqwnmkyt5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 08 Dec 2023 13:13:34 +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 3B8DDYKn023250; Fri, 8 Dec 2023 13:13:34 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 3B8DDYli023248; Fri, 08 Dec 2023 13:13:34 +0000 Received: by hu-maiyas-hyd.qualcomm.com (Postfix, from userid 2342877) id 485425000A9; Fri, 8 Dec 2023 18:43:33 +0530 (+0530) From: Nitin Rawat To: "James E.J. Bottomley" , "Martin K. Petersen" , Manivannan Sadhasivam , Krzysztof Kozlowski Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, quic_cang@quicinc.com, Nitin Rawat , Manish Pandey Subject: [PATCH V5] scsi: ufs: core: store min and max clk freq from OPP table Date: Fri, 8 Dec 2023 18:43:31 +0530 Message-Id: <20231208131331.12596-1-quic_nitirawa@quicinc.com> X-Mailer: git-send-email 2.17.1 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: pr8Tl0DmxjZzUn2mAslRDGzq0acFUOeA X-Proofpoint-ORIG-GUID: pr8Tl0DmxjZzUn2mAslRDGzq0acFUOeA 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-08_08,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 clxscore=1015 suspectscore=0 priorityscore=1501 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 phishscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312080109 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 pete.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 (pete.vger.email [0.0.0.0]); Fri, 08 Dec 2023 05:13:54 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784719595292311250 X-GMAIL-MSGID: 1784719595292311250 OPP support added by commit 72208ebe181e ("scsi: ufs: core: Add support for parsing OPP") doesn't update the min_freq and max_freq of each clocks in 'struct ufs_clk_info'. But these values are used by the host drivers internally for controller configuration. When the OPP support is enabled in devicetree, these values will be 0, causing boot issues on the respective platforms. So add support to parse the min_freq and max_freq of all clocks while parsing the OPP table. Fixes: 72208ebe181e ("scsi: ufs: core: Add support for parsing OPP") Co-developed-by: Manish Pandey Signed-off-by: Manish Pandey Signed-off-by: Nitin Rawat Reviewed-by: Manivannan Sadhasivam --- Change from v4: - Addressed bart's comment to simplify the code Changes from v3: - updated commit description and comment to address christoph's comment Changes from v2: - increment idx in dev_pm_opp_get_freq_indexed Changes from v1: As per Manivannan's comment: - Updated commmit description - Sort include file alphabetically - Added missing dev_pm_opp_put - updated function name and documention - removed ret variable --- drivers/ufs/host/ufshcd-pltfrm.c | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) -- 2.17.1 diff --git a/drivers/ufs/host/ufshcd-pltfrm.c b/drivers/ufs/host/ufshcd-pltfrm.c index da2558e274b4..db9d9365ff55 100644 --- a/drivers/ufs/host/ufshcd-pltfrm.c +++ b/drivers/ufs/host/ufshcd-pltfrm.c @@ -8,6 +8,7 @@ * Vinayak Holikatti */ +#include #include #include #include @@ -213,6 +214,55 @@ static void ufshcd_init_lanes_per_dir(struct ufs_hba *hba) } } +/** + * ufshcd_parse_clock_min_max_freq - Parse MIN and MAX clocks freq + * @hba: per adapter instance + * + * This function parses MIN and MAX frequencies of all clocks required + * by the host drivers. + * + * Returns 0 for success and non-zero for failure + */ +static int ufshcd_parse_clock_min_max_freq(struct ufs_hba *hba) +{ + struct list_head *head = &hba->clk_list_head; + struct ufs_clk_info *clki; + struct dev_pm_opp *opp; + unsigned long freq; + u8 idx = 0; + + list_for_each_entry(clki, head, list) { + if (!clki->name) + continue; + + clki->clk = devm_clk_get(hba->dev, clki->name); + if (IS_ERR(clki->clk)) + continue; + + /* Find Max Freq */ + freq = ULONG_MAX; + opp = dev_pm_opp_find_freq_floor_indexed(hba->dev, &freq, idx); + if (IS_ERR(opp)) { + dev_err(hba->dev, "Failed to find OPP for MAX frequency\n"); + return PTR_ERR(opp); + } + clki->max_freq = dev_pm_opp_get_freq_indexed(opp, idx); + dev_pm_opp_put(opp); + + /* Find Min Freq */ + freq = 0; + opp = dev_pm_opp_find_freq_ceil_indexed(hba->dev, &freq, idx); + if (IS_ERR(opp)) { + dev_err(hba->dev, "Failed to find OPP for MIN frequency\n"); + return PTR_ERR(opp); + } + clki->min_freq = dev_pm_opp_get_freq_indexed(opp, idx++); + dev_pm_opp_put(opp); + } + + return 0; +} + static int ufshcd_parse_operating_points(struct ufs_hba *hba) { struct device *dev = hba->dev; @@ -279,6 +329,10 @@ static int ufshcd_parse_operating_points(struct ufs_hba *hba) return ret; } + ret = ufshcd_parse_clock_min_max_freq(hba); + if (ret) + return ret; + hba->use_pm_opp = true; return 0;