Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2284292imm; Thu, 11 Oct 2018 07:58:53 -0700 (PDT) X-Google-Smtp-Source: ACcGV62jIx8lwua9lo7wS2L51S4lBlFvMIRyfm3+7BB/4NPQSv6UBowl24IpaHgnFMD9BT/sgeAZ X-Received: by 2002:a17:902:369:: with SMTP id 96-v6mr1920378pld.36.1539269933261; Thu, 11 Oct 2018 07:58:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539269933; cv=none; d=google.com; s=arc-20160816; b=NDEDie6m5j5I6BmpbrRk2Hfo3eQYp8UKbroSg5vPRSdrSsz+7G/yUlyWdFqfOOFDnp 8+xqIMUf9hZ8s05zBxsUOclDtxAeamSy0RhVb4bYH3ALYKBd7fxYrBfJixHpZpRwy02b /guPyoA0JcTO8RitBLCiB2Vq/H3+ltl/7vt3XJ6PgkbF+x/S11V3FyzcN6E8sFt5IyeP xUwrxA/gDsUQq0LWpY9Ws+8QRTDvAvEFQ4OGuQYLXM8122D9HGfd6IfyU2h96pUwnuJH r35LSzaMc/odWrdKMc4jVFJbcEOwJUaerYk39o8G7UpNHbrLQeMrSfdfslpdYXn9ScL+ FgQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=UQV1qy5OgBmh0gbeb60UhcC41PZScPfWtmnUdm+xUOw=; b=E28ln/YQCabYyA3G9ZOozXIzUyeNdVAzVhAFb2/uiKuy1LAyGSFnALwaodd2gwC4Nv KHRFIm20WWyoH84psS9+zuk+pE+YtCkw0HrHPZmc6M2PDkXZJVYsb1CC9nMzJBZX4LlO QBojK/q/yoQZa43OmzUFIUIJBCC//0+BfccXmDiUnymTrj1nn3YTjeYJxuj28YJWpDyl rZhdn2B9EY6FgYih5Z6/+dUWqvH7cHhKZvhE1pYpYScuuU9OM90lizbiK8sUaYt3qe1q 0qK7c4cABKDq0/bzP+qd1kl5rlpHmko4HKHqIOxnnJI4Eq66d6ZiBiyIaLj79oGOdUmA Hibg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BaEZCO9R; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y14-v6si3166263pll.385.2018.10.11.07.58.38; Thu, 11 Oct 2018 07:58:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BaEZCO9R; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728458AbeJKVep (ORCPT + 99 others); Thu, 11 Oct 2018 17:34:45 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:45526 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727983AbeJKVep (ORCPT ); Thu, 11 Oct 2018 17:34:45 -0400 Received: by mail-io1-f65.google.com with SMTP id e12-v6so6644645iok.12 for ; Thu, 11 Oct 2018 07:07:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=UQV1qy5OgBmh0gbeb60UhcC41PZScPfWtmnUdm+xUOw=; b=BaEZCO9RGu629nfl4raf4ZW+bmsrcPCphnM9qRpKU7fwZY/Fa/S8C3eQAf1vYa7M8c UkziqAYyFSdVpfP9lmM0JL0RfFR5nJae0GQUCpLVTihoehLMTLH+B66ckLK+7F1xhxw+ VW/mBeRcb4wbyCOPBywHyTwDMeW0p+lPlPhrU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=UQV1qy5OgBmh0gbeb60UhcC41PZScPfWtmnUdm+xUOw=; b=G7tyzteWKEi61M6ijxCmfUG7ERMn8cLVJAsLZRarnIqbkE3RKQDtkXHbAe91Ls8Rl9 KbgXR3gxt4eFWPaAJNzVo3FF/TYc2iDnvsKbz7uoRCdL/Pa6E85OgDJsfLY4Ybjffk4j +3Q+fV67r/c3RnNJrpuFzKQlqdpJImIEGQOxTqLS6vj2CAu9XEpUlsaOHJACGHQ9sYIo TWV1GxNSZIE0PxpRtcOICuZkae3KjrlCMPmIYAeb+hauYbzP+K2hsRoCZ00lHX4imuzw 14QX1Unb4w4R9QMLxpocFTN9w6/QzyA1qu+t57eDFhXLFUsfu/hR/7k9QfIXaIvPPgBF V//Q== X-Gm-Message-State: ABuFfogm+uFFU24syoFboGenJSYnLOwwHEDgiHzO1AIgl8DYp+yepKFV RiFIzFA1aj6ujXf5ucEp95Tm3YIhRpXi3pwjexR1GA== X-Received: by 2002:a6b:8fcb:: with SMTP id r194-v6mr1243746iod.266.1539266843294; Thu, 11 Oct 2018 07:07:23 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a02:3941:0:0:0:0:0 with HTTP; Thu, 11 Oct 2018 07:06:42 -0700 (PDT) In-Reply-To: <20181011120336.9129-1-georgi.djakov@linaro.org> References: <20181011120336.9129-1-georgi.djakov@linaro.org> From: Ulf Hansson Date: Thu, 11 Oct 2018 16:06:42 +0200 Message-ID: Subject: Re: [RFC] mmc: host: sdhci-msm: Use the interconnect API To: Georgi Djakov Cc: Linux PM , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Mike Turquette , Kevin Hilman , Vincent Guittot , Saravana Kannan , Bjorn Andersson , Amit Kucheria , seansw@qti.qualcomm.com, daidavid1@codeaurora.org, Evan Green , Mark Rutland , Lorenzo Pieralisi , abailon@baylibre.com, Maxime Ripard , Arnd Bergmann , DTML , Linux Kernel Mailing List , Linux ARM , linux-arm-msm , Adrian Hunter , "linux-mmc@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11 October 2018 at 14:03, Georgi Djakov wrote: > The interconnect API provides an interface for consumer drivers to express > their bandwidth needs in the SoC. This data is aggregated and the on-chip > interconnect hardware is configured to the appropriate power/performance > profile. > > Use the interconnect API to get() the path between the endpoints used for > data transfers by the SD host controller and report the needed bandwidth > based on the clock rate, bus width and mode. Overall, this makes sense to me! > > Signed-off-by: Georgi Djakov > --- > > This depends on the interconnect API: https://lkml.org/lkml/2018/8/31/444 > > TODO: Use macros for converting and rounding to icc units instead of > converting between kilobits and kilobytes in the consumer drivers. > > drivers/mmc/host/sdhci-msm.c | 46 ++++++++++++++++++++++++++++++++++-- > 1 file changed, 44 insertions(+), 2 deletions(-) > > diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c > index 3cc8bfee6c18..8ca99ccdb035 100644 > --- a/drivers/mmc/host/sdhci-msm.c > +++ b/drivers/mmc/host/sdhci-msm.c > @@ -20,6 +20,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -258,6 +259,7 @@ struct sdhci_msm_host { > bool mci_removed; > const struct sdhci_msm_variant_ops *var_ops; > const struct sdhci_msm_offset *offset; > + struct icc_path *path; > }; > > static const struct sdhci_msm_offset *sdhci_priv_msm_offset(struct sdhci_host *host) > @@ -1627,6 +1629,30 @@ static const struct sdhci_msm_variant_info sdhci_msm_v5_var = { > .offset = &sdhci_msm_v5_offset, > }; > > +static int sdhci_msm_icc_update(struct sdhci_msm_host *msm_host) > +{ > + struct sdhci_host *host = dev_get_drvdata(&msm_host->pdev->dev); > + struct mmc_host *mmc = host->mmc; > + struct mmc_ios *ios = &mmc->ios; > + unsigned char bus_width = 1 << ios->bus_width; > + u32 bw; > + > + /* calculate the needed bandwidth */ > + bw = host->clock; According to my understanding of the code, host->clock doesn't necessarily reflect the actual set clock rate. For example, clk_set_rate() doesn't mean that requested rate is set exactly to the requested rate. Moreover, it may not be evident, but from mmc core perspective, it's strongly recommended for mmc host drivers to set ->actual_clock to the "actual clock rate" in the corresponding struct mmc_host. I suggest sdhci-msm convert to that, in a first step. Once that is done, I would rather move the below computations, to find the bandwidth, into a helper function inside the mmc core. > + > + if (host->timing == MMC_TIMING_UHS_DDR50 || > + host->timing == MMC_TIMING_MMC_DDR52) { > + bw *= 2; > + } > + > + if (bus_width == 4) > + bw /= 2; > + else if (bus_width == 1) > + bw /= 8; > + > + return icc_set(msm_host->path, 0, bw / 1000); > +} > + > static const struct of_device_id sdhci_msm_dt_match[] = { > {.compatible = "qcom,sdhci-msm-v4", .data = &sdhci_msm_mci_var}, > {.compatible = "qcom,sdhci-msm-v5", .data = &sdhci_msm_v5_var}, > @@ -1698,16 +1724,27 @@ static int sdhci_msm_probe(struct platform_device *pdev) > > msm_host->saved_tuning_phase = INVALID_TUNING_PHASE; > > + msm_host->path = of_icc_get(&pdev->dev, "sdhc-mem"); > + if (IS_ERR(msm_host->path)) { > + ret = PTR_ERR(msm_host->path); > + goto pltfm_free; > + } > + ret = sdhci_msm_icc_update(msm_host); > + if (ret) { > + dev_warn(&pdev->dev, "Interconnect setup failed (%d)\n", ret); > + goto icc_disable; > + } > + > /* Setup SDCC bus voter clock. */ > msm_host->bus_clk = devm_clk_get(&pdev->dev, "bus"); > if (!IS_ERR(msm_host->bus_clk)) { > /* Vote for max. clk rate for max. performance */ > ret = clk_set_rate(msm_host->bus_clk, INT_MAX); > if (ret) > - goto pltfm_free; > + goto icc_disable; > ret = clk_prepare_enable(msm_host->bus_clk); > if (ret) > - goto pltfm_free; > + goto icc_disable; > } > > /* Setup main peripheral bus clock */ > @@ -1883,6 +1920,8 @@ static int sdhci_msm_probe(struct platform_device *pdev) > bus_clk_disable: > if (!IS_ERR(msm_host->bus_clk)) > clk_disable_unprepare(msm_host->bus_clk); > +icc_disable: > + icc_put(msm_host->path); > pltfm_free: > sdhci_pltfm_free(pdev); > return ret; > @@ -1902,6 +1941,7 @@ static int sdhci_msm_remove(struct platform_device *pdev) > pm_runtime_disable(&pdev->dev); > pm_runtime_put_noidle(&pdev->dev); > > + icc_put(msm_host->path); > clk_bulk_disable_unprepare(ARRAY_SIZE(msm_host->bulk_clks), > msm_host->bulk_clks); > if (!IS_ERR(msm_host->bus_clk)) > @@ -1917,6 +1957,7 @@ static int sdhci_msm_runtime_suspend(struct device *dev) > struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); > struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host); > > + icc_set(msm_host->path, 0, 0); > clk_bulk_disable_unprepare(ARRAY_SIZE(msm_host->bulk_clks), > msm_host->bulk_clks); > > @@ -1929,6 +1970,7 @@ static int sdhci_msm_runtime_resume(struct device *dev) > struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); > struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host); > > + sdhci_msm_icc_update(msm_host); > return clk_bulk_prepare_enable(ARRAY_SIZE(msm_host->bulk_clks), > msm_host->bulk_clks); > } Besides the above, this makes sense to me. Kind regards Uffe