From patchwork Thu Oct 12 07:20:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Alessandro Carminati \(Red Hat\)" X-Patchwork-Id: 733641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00BC5CDB482 for ; Thu, 12 Oct 2023 07:28:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377770AbjJLH2c (ORCPT ); Thu, 12 Oct 2023 03:28:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234125AbjJLH2b (ORCPT ); Thu, 12 Oct 2023 03:28:31 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 501CC9D; Thu, 12 Oct 2023 00:28:27 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-9b2cee40de8so125154466b.1; Thu, 12 Oct 2023 00:28:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697095706; x=1697700506; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kEqKvIWeFRr8W5s0BPeSsPwNLKn93+5XPQoiJhuCABo=; b=b5UXYZkc91cIBJ7igE7i2UsySuIydTQXjE55MupknR44qFIjeVJIL2eLMxwFvD7sSG 6h14rQqhPym0LJg/Vzb0XzLQdpSYqUhAx664sIYN12deQcb+bqTrskESdpJyaLSQKT2I rIvMTcCZzZFiR5i0BeUDTYN+s2xAuoE5uDKViBFonnPCv4H3qts1V8fIOCx8zUVCE17U Ve7GulhV/o0p6GLhQ/PXtE+0JvJYvdYZNiWtRU/PaQ3sk0aqoeevCGaXTb3qGe0TUNq9 naqOlSixCZu4HyuaUeXX0PZbun9xANgfKLsjImFXHepvL6TBt0norQ84MzrWL6Si+Ryw WpZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697095706; x=1697700506; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kEqKvIWeFRr8W5s0BPeSsPwNLKn93+5XPQoiJhuCABo=; b=IcufihXrY9gM7/bnLrIDjXMzSsTlYLJYW+0H30WIOidWyHcj1YTm1dLyAUqcxcwyTZ KrJGRegIp6MmnMVSimjwyFj/mpQEVPVOyJDU/Z4eJb7RG8FdjTaM4NhRlPIXHkyxXwcW ccXMI363j1mvzkj4Cj8Gql8DxlL6MXJU+u0HyL3AzDY9CK0h6keFU4ww3THpVXFAk0NY enXSnk4POBEm9XIR465XVRDIhk8l+ugGht0YVoEZDvDqRCllOFTXoK3tD1y2j3wsTwvU cx63jz7uiFGVlVtGCC1f57CLUmAupk4YrEt+QWVV+mgvA1PTI10wgKjbzeHqX8J4wuEk cJcA== X-Gm-Message-State: AOJu0YxoHdRTMIBmMfrOGlHgKg60eK4WfUz23ZMQj5yu6919nY+Lf0zY xopNcQhtxIs8BfpZHDS1//8= X-Google-Smtp-Source: AGHT+IFdcug422fZ9CQ3p/vnodtvTJxBtSb/0L4CdV5alrbUijpVrx+baQdM5YlE+adz/UU7cIal8g== X-Received: by 2002:a17:907:7f08:b0:9a9:9d19:b250 with SMTP id qf8-20020a1709077f0800b009a99d19b250mr16312225ejc.17.1697095705420; Thu, 12 Oct 2023 00:28:25 -0700 (PDT) Received: from lab.hqhome163.com ([194.183.10.152]) by smtp.googlemail.com with ESMTPSA id a6-20020a170906468600b009a5f7fb51dcsm10616261ejr.42.2023.10.12.00.28.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 00:28:24 -0700 (PDT) From: "Alessandro Carminati (Red Hat)" To: manivannan.sadhasivam@linaro.org Cc: alim.akhtar@samsung.com, andersson@kernel.org, avri.altman@wdc.com, bmasney@redhat.com, bvanassche@acm.org, conor+dt@kernel.org, cw00.choi@samsung.com, devicetree@vger.kernel.org, jejb@linux.ibm.com, konrad.dybcio@linaro.org, krzysztof.kozlowski+dt@linaro.org, krzysztof.kozlowski@linaro.org, kyungmin.park@samsung.com, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-scsi@vger.kernel.org, martin.petersen@oracle.com, myungjoo.ham@samsung.com, nm@ti.com, quic_asutoshd@quicinc.com, quic_bhaskarv@quicinc.com, quic_cang@quicinc.com, quic_narepall@quicinc.com, quic_nguyenb@quicinc.com, quic_nitirawa@quicinc.com, quic_richardp@quicinc.com, quic_ziqichen@quicinc.com, robh+dt@kernel.org, sboyd@kernel.org, vireshk@kernel.org, "Alessandro Carminati (Red Hat)" Subject: [PATCH] scsi: ufs: core: Fix build error: ufshcd_opp_config_clks Date: Thu, 12 Oct 2023 07:20:51 +0000 Message-Id: <20231012072051.1517826-1-alessandro.carminati@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231011122543.11922-4-manivannan.sadhasivam@linaro.org> References: <20231011122543.11922-4-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 Content-type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Building linux-6.6-rc3 with this patchset applied and the following configuration: CONFIG_SCSI_UFSHCD=m CONFIG_SCSI_UFS_BSG=y I got: scripts/mod/modpost -M -m -a -o Module.symvers -T modules.order vmlinux.o ERROR: modpost: "ufshcd_opp_config_clks" [drivers/ufs/host/ufshcd-pltfrm.ko] undefined! make[2]: *** [scripts/Makefile.modpost:145: Module.symvers] Error 1 make[1]: *** [/home/alessandro/src/linux-6.6-rc3/Makefile:1865: modpost] Error 2 make: *** [Makefile:234: __sub-make] Error 2 I needed to add an export symbol to have the build complete Signed-off-by: Alessandro Carminati (Red Hat) --- drivers/ufs/core/ufshcd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index ccd7fcd18355..c0631c37c3d1 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -1098,6 +1098,7 @@ int ufshcd_opp_config_clks(struct device *dev, struct opp_table *opp_table, return 0; } +EXPORT_SYMBOL_GPL(ufshcd_opp_config_clks); static int ufshcd_opp_set_rate(struct ufs_hba *hba, unsigned long freq) { From patchwork Wed Oct 11 12:25:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 733647 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4B18CD6E63 for ; Wed, 11 Oct 2023 12:26:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346883AbjJKM0m (ORCPT ); Wed, 11 Oct 2023 08:26:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346813AbjJKM0i (ORCPT ); Wed, 11 Oct 2023 08:26:38 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32B9AF7 for ; Wed, 11 Oct 2023 05:26:29 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-690d8fb3b7eso6063153b3a.1 for ; Wed, 11 Oct 2023 05:26:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697027188; x=1697631988; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XUVXE6lzmoWBngLejlC2l3Moj/eFOB47EeTHJHJX3rM=; b=MKwZ47MeWvNpesO+asPiJ+C6aZbLWx1iAfwUVNLfdb/f26Pq5r1fRk3Zw5jcNZCKa5 c/Lk2MZC6A9zWkRQwArGcPhGCWETXL1Ko2QrwtVulZBOa9C4oXUfGvjFjYQ6hdGwaNoW 0UmHXyhBGgPBGKVkJOmjcRBdE8s3UaSiLqCvUd1dq8yJ9GJqqmseG0XGdZ8G9Kg2ue2k /2IZMmYp2qsibcPLiH53MK7yQz4hagm5xVhsda37AaAayytYas4mZKCNOp6FuvH6df3r DfUdqS8sLaRE7dgSIzBS/uiVl6l8jBc8BfqPCa9LnQ8Z5yci51P+xd/J+k0cX5AmZ4+V 4+0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697027188; x=1697631988; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XUVXE6lzmoWBngLejlC2l3Moj/eFOB47EeTHJHJX3rM=; b=v017lccNplXLrRg/pIO+Zddbl6ZvkQey17iKVI/V0J6gg+h7J/rGnJgURAGTe/AVAJ LwDSwhBTjrIcitm5N+6YFA2XGFUwrkAQD2feOm9lCVl6/C7sozt6uj4d8U6dh+lvlbcs I3YDAYhNXxUpFd72jPrnoRqufw165Xni4WsBxEd2r796+HIuQKJQ5v2uNQtVygYRwGJA qkfGLCDC9s+/EXjn8GLnyogU7tdapZdghxE8eCgvdxuo4BcuM3NnUS76fGEDyvQy/DbP eyyx5bMG9olyqq96xxrApyR76cOLoN0w7zgkLFAUjOGNwga2sEniN/2GDlxqwno60nud VOBg== X-Gm-Message-State: AOJu0YyfBeHlqHLwNjzmgtWb6UIi6OSQ2JR/4CR0ka53LMGG9XSn9NqH 8rJ3MYX7cnRLiRBgT0sCBUxw X-Google-Smtp-Source: AGHT+IHpoBy1EO9Djts5TsVu2JayJ/1h1SBMHEZDi0AmjeoCIjjR0KIYFFLqzvgGvxHE/0MoXMa8NA== X-Received: by 2002:a05:6a00:21c9:b0:68f:c7c5:a73a with SMTP id t9-20020a056a0021c900b0068fc7c5a73amr22917270pfj.16.1697027188575; Wed, 11 Oct 2023 05:26:28 -0700 (PDT) Received: from localhost.localdomain ([120.138.12.180]) by smtp.gmail.com with ESMTPSA id a19-20020aa78653000000b0068fb8080939sm9953620pfo.65.2023.10.11.05.26.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 05:26:28 -0700 (PDT) From: Manivannan Sadhasivam To: vireshk@kernel.org, nm@ti.com, sboyd@kernel.org, myungjoo.ham@samsung.com, kyungmin.park@samsung.com, cw00.choi@samsung.com, andersson@kernel.org, konrad.dybcio@linaro.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, jejb@linux.ibm.com, martin.petersen@oracle.com Cc: alim.akhtar@samsung.com, avri.altman@wdc.com, bvanassche@acm.org, linux-scsi@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, quic_asutoshd@quicinc.com, quic_cang@quicinc.com, quic_nitirawa@quicinc.com, quic_narepall@quicinc.com, quic_bhaskarv@quicinc.com, quic_richardp@quicinc.com, quic_nguyenb@quicinc.com, quic_ziqichen@quicinc.com, bmasney@redhat.com, krzysztof.kozlowski@linaro.org, linux-kernel@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH v5 3/5] scsi: ufs: host: Add support for parsing OPP Date: Wed, 11 Oct 2023 17:55:41 +0530 Message-Id: <20231011122543.11922-4-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231011122543.11922-1-manivannan.sadhasivam@linaro.org> References: <20231011122543.11922-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org OPP framework can be used to scale the clocks along with other entities such as regulators, performance state etc... So let's add support for parsing OPP from devicetree. OPP support in devicetree is added through the "operating-points-v2" property which accepts the OPP table defining clock frequency, regulator voltage, power domain performance state etc... Since the UFS controller requires multiple clocks to be controlled for proper working, devm_pm_opp_set_config() has been used which supports scaling multiple clocks through custom ufshcd_opp_config_clks() callback. It should be noted that the OPP support is not compatible with the old "freq-table-hz" property. So only one can be used at a time even though the UFS core supports both. Co-developed-by: Krzysztof Kozlowski Signed-off-by: Krzysztof Kozlowski Signed-off-by: Manivannan Sadhasivam --- drivers/ufs/core/ufshcd.c | 35 ++++++++++++++ drivers/ufs/host/ufshcd-pltfrm.c | 78 ++++++++++++++++++++++++++++++++ include/ufs/ufshcd.h | 3 ++ 3 files changed, 116 insertions(+) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 3f52e05002e4..8cbd08f81c56 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -1064,6 +1064,41 @@ static int ufshcd_set_clk_freq(struct ufs_hba *hba, bool scale_up) return ret; } +int ufshcd_opp_config_clks(struct device *dev, struct opp_table *opp_table, + struct dev_pm_opp *opp, void *data, + bool scaling_down) +{ + struct ufs_hba *hba = dev_get_drvdata(dev); + struct list_head *head = &hba->clk_list_head; + struct ufs_clk_info *clki; + unsigned long freq; + u8 idx = 0; + int ret; + + list_for_each_entry(clki, head, list) { + if (!IS_ERR_OR_NULL(clki->clk)) { + freq = dev_pm_opp_get_freq_indexed(opp, idx++); + + /* Do not set rate for clocks having frequency as 0 */ + if (!freq) + continue; + + ret = clk_set_rate(clki->clk, freq); + if (ret) { + dev_err(dev, "%s: %s clk set rate(%ldHz) failed, %d\n", + __func__, clki->name, freq, ret); + return ret; + } + + trace_ufshcd_clk_scaling(dev_name(dev), + (scaling_down ? "scaled down" : "scaled up"), + clki->name, hba->clk_scaling.target_freq, freq); + } + } + + return 0; +} + static int ufshcd_opp_set_rate(struct ufs_hba *hba, unsigned long freq) { struct dev_pm_opp *opp; diff --git a/drivers/ufs/host/ufshcd-pltfrm.c b/drivers/ufs/host/ufshcd-pltfrm.c index 61cf8b957da4..da2558e274b4 100644 --- a/drivers/ufs/host/ufshcd-pltfrm.c +++ b/drivers/ufs/host/ufshcd-pltfrm.c @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -212,6 +213,77 @@ static void ufshcd_init_lanes_per_dir(struct ufs_hba *hba) } } +static int ufshcd_parse_operating_points(struct ufs_hba *hba) +{ + struct device *dev = hba->dev; + struct device_node *np = dev->of_node; + struct dev_pm_opp_config config = {}; + struct ufs_clk_info *clki; + const char **clk_names; + int cnt, i, ret; + + if (!of_find_property(np, "operating-points-v2", NULL)) + return 0; + + if (of_find_property(np, "freq-table-hz", NULL)) { + dev_err(dev, "%s: operating-points and freq-table-hz are incompatible\n", + __func__); + return -EINVAL; + } + + cnt = of_property_count_strings(np, "clock-names"); + if (cnt <= 0) { + dev_err(dev, "%s: Missing clock-names\n", __func__); + return -ENODEV; + } + + /* OPP expects clk_names to be NULL terminated */ + clk_names = devm_kcalloc(dev, cnt + 1, sizeof(*clk_names), GFP_KERNEL); + if (!clk_names) + return -ENOMEM; + + /* + * We still need to get reference to all clocks as the UFS core uses + * them separately. + */ + for (i = 0; i < cnt; i++) { + ret = of_property_read_string_index(np, "clock-names", i, + &clk_names[i]); + if (ret) + return ret; + + clki = devm_kzalloc(dev, sizeof(*clki), GFP_KERNEL); + if (!clki) + return -ENOMEM; + + clki->name = devm_kstrdup(dev, clk_names[i], GFP_KERNEL); + if (!clki->name) + return -ENOMEM; + + if (!strcmp(clk_names[i], "ref_clk")) + clki->keep_link_active = true; + + list_add_tail(&clki->list, &hba->clk_list_head); + } + + config.clk_names = clk_names, + config.config_clks = ufshcd_opp_config_clks; + + ret = devm_pm_opp_set_config(dev, &config); + if (ret) + return ret; + + ret = devm_pm_opp_of_add_table(dev); + if (ret) { + dev_err(dev, "Failed to add OPP table: %d\n", ret); + return ret; + } + + hba->use_pm_opp = true; + + return 0; +} + /** * ufshcd_get_pwr_dev_param - get finally agreed attributes for * power mode change @@ -378,6 +450,12 @@ int ufshcd_pltfrm_init(struct platform_device *pdev, ufshcd_init_lanes_per_dir(hba); + err = ufshcd_parse_operating_points(hba); + if (err) { + dev_err(dev, "%s: OPP parse failed %d\n", __func__, err); + goto dealloc_host; + } + err = ufshcd_init(hba, mmio_base, irq); if (err) { dev_err_probe(dev, err, "Initialization failed with error %d\n", diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index fc0d6d37319a..7f0b2c5599cd 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -1254,6 +1254,9 @@ void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba); void ufshcd_mcq_enable_esi(struct ufs_hba *hba); void ufshcd_mcq_config_esi(struct ufs_hba *hba, struct msi_msg *msg); +int ufshcd_opp_config_clks(struct device *dev, struct opp_table *opp_table, + struct dev_pm_opp *opp, void *data, + bool scaling_down); /** * ufshcd_set_variant - set variant specific data to the hba * @hba: per adapter instance