Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp92278rdg; Wed, 11 Oct 2023 22:46:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEOpc71jRzZq9yKhIQ0uH2jBvIoaEhNzJHZbPfq2pfTqCYxJweBe/l0hTWGUUP+vRzj2MP0 X-Received: by 2002:a17:903:11c9:b0:1c3:c127:540 with SMTP id q9-20020a17090311c900b001c3c1270540mr24408683plh.29.1697089609553; Wed, 11 Oct 2023 22:46:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697089609; cv=none; d=google.com; s=arc-20160816; b=hyXZOee1IDe233yHilGYkWyBVg4Wc6GinQo70k2zXkXQ0XSWzhRlwH3hINv6OUWRlD 73sXnxQDMYFjGAujQ3r6CnNnYkXfhOT7q7/JmOZ+7EzUD+D1dxxhyG6NIhv1NSSFlIoe X6tCGYPCjUBoFwVJIhPg2T1Go9LdAW+5gh7iEzLuvkCsYHiSNHJVuouLBI7rsU9jfFeu kNglZKKBaiDYr2mxnTHguP1m9K1nd6HyPrK7Snlj9bgrHveDK4xSFTsZ4P6WoTF5DwDJ we+tvXRyDkWXaLA0D/8gK+kwLDkP6yIk+Kd8DSrbkKecPhe5COesKHJDsbuYaNntcQTt S16A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XUVXE6lzmoWBngLejlC2l3Moj/eFOB47EeTHJHJX3rM=; fh=AszCqE9IlXdA31m5wwzmLVkdhfUwK5TfZjgMrvhmBxs=; b=INMcGshARJTAs7a2ITQPapUyPO/Zy2H973hLEfEfSRqPsWY/d9zXlAnjJYupCf2qGP iTWSZrNLrxKUVo6Hp4NOtVZZ7fm8iaqam0DP1baMmhyRmIlpp6VWHFbbMaa4wS00Enbi 2WWV/LORyHRBFs79+1QkkxlS24xwxGQRWT1cfQ7z2n0WBoRnStQh4NXaU147rydj0csw c7HKlFogHcXtR9MPYGOjbCU1i+yeTggITSAHj4Y0S2unzXJ8wBiNNsVV3suvqyMoHK/6 ZBu+/c3HWxRVH6066+UMar0KFw8Lvsz4yLZ5aHTL0Ydn9xs0/rEgq6hCYG3XUyO3OXGk lFHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r+sR9+JG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id ij21-20020a170902ab5500b001c71eb782b0si1351136plb.94.2023.10.11.22.46.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 22:46:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r+sR9+JG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id E142E8041589; Wed, 11 Oct 2023 22:46:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235353AbjJLFqS (ORCPT + 99 others); Thu, 12 Oct 2023 01:46:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377264AbjJLFqB (ORCPT ); Thu, 12 Oct 2023 01:46:01 -0400 Received: from mail-oa1-x34.google.com (mail-oa1-x34.google.com [IPv6:2001:4860:4864:20::34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05EDDF3 for ; Wed, 11 Oct 2023 22:45:49 -0700 (PDT) Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-1e59894d105so309871fac.1 for ; Wed, 11 Oct 2023 22:45:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697089549; x=1697694349; 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=r+sR9+JG1t1T153CcKRa2n7wccPt77vomgrJNy+mDttjJ543SrFUZt1wrUoeaTuuT/ 4LXdr96ytgG+i2qKIye/ytTyhSfh4+s0+2rPXEIvz0AT3mVNhoPyF2xURXL6oAz9lW32 nbK/ERSYD3iTNdEC/9qLAqCvK30s2KMRxx5NrNzDJ7BsD7L7TcP8xM2UCsMUYRhsQgFV gCiXS1N58nMPUMTiLUCNl6kPrAtEHgvVa2ID9BfYSJ4et/S158J8mQu8Kg5SHvAoB3x8 M9JK8eM+VG1SWg++Jn5wmz07BWI6+rjke/W5zQiYjT/R6jBiKjkb/XiNFrkmNZPidb3U dBfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697089549; x=1697694349; 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=onJ6SnsFTkZDOfNMu2yv8rSZORwRfZvhaYHeuoV6aTA2av1R1Kiyvk9b8p7OJaOpCl rrGkQXX2WFKDPKS35tt4sFtaT40A0w8jAKkLHXuCTKDnK9Kh2AtfxZvL+VNHjW1A58h7 wuGEay6tRhl21OGojLT+ac3fqSmXKPkIKUhJIo+CHDvJnS+6x5/BWcsZF1C8yXlS3bPl JcelhhpnLf2SIyYrfhPS0DVfsggL0EJ2Mzfy5piZQEZPhmTefN1pJv98MtrKeS5HuK5N 5WjNMGByAW9v9kqjwk8BFqN+ndRoPUrl/Ej/PLS+fYnABIjyTddm8RvIYOxIZXkYax56 gRBQ== X-Gm-Message-State: AOJu0YzlL+xaK5H9R9Rsn4yBIGDPspZS8oH4JPkraZdZ5p3+8gpBtOhq QKiNu9h2cTf/M5wVCBVpXDRM X-Received: by 2002:a05:6870:6709:b0:1e5:525a:88a1 with SMTP id gb9-20020a056870670900b001e5525a88a1mr23150803oab.56.1697089549140; Wed, 11 Oct 2023 22:45:49 -0700 (PDT) Received: from localhost.localdomain ([120.138.12.180]) by smtp.gmail.com with ESMTPSA id c5-20020a633505000000b0057cb5a780ebsm812396pga.76.2023.10.11.22.45.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 22:45:48 -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 v6 3/5] scsi: ufs: host: Add support for parsing OPP Date: Thu, 12 Oct 2023 11:15:10 +0530 Message-Id: <20231012054512.10963-4-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231012054512.10963-1-manivannan.sadhasivam@linaro.org> References: <20231012054512.10963-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Wed, 11 Oct 2023 22:46:46 -0700 (PDT) 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 -- 2.25.1