Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1881880rdb; Tue, 3 Oct 2023 04:13:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHf3JLrFBQlbxoE2Xkq8t3u8cAGAwPqkub+MMiM7IsgE+O8eVQH3HVNp8pB2GNSZgl70Pln X-Received: by 2002:a17:90a:ce8c:b0:26d:43f9:11dd with SMTP id g12-20020a17090ace8c00b0026d43f911ddmr11253157pju.0.1696331632747; Tue, 03 Oct 2023 04:13:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696331632; cv=none; d=google.com; s=arc-20160816; b=vMJmFTZZy8eKxcjijcWF4Qwc7vH70LdekGIWmLWquxGWI3GBVeZ3Pw3MnOBDPssbJd Wh5hUJ6MQmtw6ouNEm03efZxyX3t9A8Y09An4BJ/AYszi+NJ0mXzTrsWtdgh/pqs48iR uWhPAQFhFoxH3fe8D6gduMnvfyAmw7C9Tm+ampXaxyPWZgyXFNxtOhD5YffKFrGImetX VNUFC7gKQvA1sJWZleR2YLZNLp/n92SephXqp1kVq59kZticLqh1/q3UsdRX46exCTAr rDvoHKcdQmRgA7zo+KXrKMGnW6BHFpE1RzvZothDC6V8jF/mAEf7w6LhBSFNrYtFrcA/ Mkrg== 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=ccxuqm7BPe/obJGZ0JRYI3uaIFICPznjHF4970iXFxs=; fh=AszCqE9IlXdA31m5wwzmLVkdhfUwK5TfZjgMrvhmBxs=; b=O1ekoHBFvjEvC4Wh4b3XWPdGdCjbaH8/YqH/SG7moQOcyJZSsmwP73W/mvmnBgLfmR uFg+sBymU16SyCb7SsUw+vQirh54J+9Dnz74IglDQifuCeoiczjJZpXNk6SbD8TOK8nc 7km34HS1eft+JNQBAmaTc07TKI6jE8Li4NBh3MrstjFzgQ6wDSEKO656P0FgsDDWEXVg FEItRSmUwr90VLBifu93I9j8mSypfVZnJMg5iGtTkI19ktW9p0QGYBMCvQpZJQBvHbcW AAsc9QOeI/O9GYTOBu8Ox4daNKO2tMYqutv5HXmMWpPyMIF3COiP9httxD8lQTRraH1o Ha2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rjHxX5pz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id mu11-20020a17090b388b00b00274e2ba0ca6si10842301pjb.134.2023.10.03.04.13.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 04:13:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rjHxX5pz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id E6CB68189093; Tue, 3 Oct 2023 04:13:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240034AbjJCLNr (ORCPT + 99 others); Tue, 3 Oct 2023 07:13:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239947AbjJCLNl (ORCPT ); Tue, 3 Oct 2023 07:13:41 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F7BE100 for ; Tue, 3 Oct 2023 04:13:26 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1c5ff5f858dso5759805ad.2 for ; Tue, 03 Oct 2023 04:13:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696331606; x=1696936406; 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=ccxuqm7BPe/obJGZ0JRYI3uaIFICPznjHF4970iXFxs=; b=rjHxX5pzanswGzD9FqPs9PwX71D4fat9NfVDQtX1mnTCG7r1u9ysvzcbhLvdFr6bwt dglDihBCMxqZ6RD/lVQIZ74rw44AMlS5F+D+4nSIGM1WEDox4/eC/9zB5/auZ25Blwrp 5wHusiRdei4y08j2MNmQERpUTw/e4zhJ5hF5V9MOhiQYvub7fDJUzvXLyOCGHXcqJVbb YRMgBn0/GaroLtmzVq18zAo7dJsO5Ck41SYrUlcqVqJ8s5Ryh0FDa9sGgf5CpqMmB57z si0xyfNDW9owaCFL2tq0g1EBLKsAjwInu1GVZ1r/JcX3KVJ2Vr68E6fKEsrGYaizKpop u8fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696331606; x=1696936406; 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=ccxuqm7BPe/obJGZ0JRYI3uaIFICPznjHF4970iXFxs=; b=Wnm09UGhddH3YtttPcdTMzFtc4U/+LQs5xYnfgRna3eyEzlj1nQDgSCdmxtGlOjBlU JR9q5SHnB2/JWdgj6jmz/zAdK8v+sQ1RYkYHOtmnIdf07WudZNDRPpPyIAGPBTVzxQ6o ICOBKiQsvdL9wHRD7A7xx27gXyEM9+3bCErX8/SBCG0Di+u16jgNrs7/KWPnswlHsfq+ ohtyRWC0o9729Qt6gj4RmitRGkU8LrMcMr1iZs/o8TbWSEMMsL6cDsLCVAJkjceZrB/W 7Zpn96K4Qy8OZnzj8N0xTmfm7eANMP2mrwC5OWQY8isXZiE6EZzKv0U5vkh4UqYQyB5V Jgzw== X-Gm-Message-State: AOJu0Yw2RQBsyXWOkrVOSZT8t4R5PEwyQ7B78n91JKV3ghO9pLZnmIKO 8mmmxlCH1JRzxPJRwqVmNCNg X-Received: by 2002:a17:903:120b:b0:1c6:1861:70c with SMTP id l11-20020a170903120b00b001c61861070cmr13871970plh.20.1696331605751; Tue, 03 Oct 2023 04:13:25 -0700 (PDT) Received: from localhost.localdomain ([117.217.185.220]) by smtp.gmail.com with ESMTPSA id d9-20020a170903230900b001ab2b4105ddsm1250328plh.60.2023.10.03.04.13.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 04:13:25 -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 v4 4/6] scsi: ufs: host: Add support for parsing OPP Date: Tue, 3 Oct 2023 16:42:30 +0530 Message-Id: <20231003111232.42663-5-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231003111232.42663-1-manivannan.sadhasivam@linaro.org> References: <20231003111232.42663-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, 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 lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Tue, 03 Oct 2023 04:13:52 -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 55de0ff1f01f..ccd7fcd18355 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 797a4dfe45d9..ffd786991244 100644 --- a/drivers/ufs/host/ufshcd-pltfrm.c +++ b/drivers/ufs/host/ufshcd-pltfrm.c @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -207,6 +208,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 @@ -373,6 +445,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 c181cc5c523b..8491b690e3ef 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -1257,6 +1257,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