Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2140474imm; Thu, 11 Oct 2018 05:53:25 -0700 (PDT) X-Google-Smtp-Source: ACcGV62z39vbisvPIfr/QcMwQfBKTyrnJvE+SXGpKqLeXINj3cgbHmxf9gbf1qW6c4JqOw6TI7+r X-Received: by 2002:a17:902:5e3:: with SMTP id f90-v6mr1519212plf.286.1539262405125; Thu, 11 Oct 2018 05:53:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539262405; cv=none; d=google.com; s=arc-20160816; b=Yg8Uzi5eIyx9rHxqm6G8XHKVYZesAQidEKLxWIIxzs7ZhNIZHb0rx99YBnesKVR0vi bYk5UIJE8hj7PEoU8C/IeZ/rZq0FwrVNqXhbIEDUAVhYovzr1OMrVphtIRWd4ihQBISE nruqaK2+4EOEW2M69/AtHoyDHbp9c9DsMGl4raXDokdyAldp+OCZO70nV1NZe+8Xkfd/ 20r8p4v2hp+aLWEZySiJ3fCQzQBUT0bqKvWKpTweeSINJtInfMdlu11iFumVOQ6wh6Xm +3aZp5Tqbvoev3DwaHM36uWZtHRb0d7kUq1yIOYLO4+MY6EZTwjKHCvEmOxx/0Pio2Iv Lb/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=/MGODQWupRFp3ivTTqHI0aavG641+71/uDj7XngGFGg=; b=LIJ10YHEjWADBH1Gtdp7P3MNckMW3sZt5hXVLjqT9zOQk0vafL2m65EpowLJw79hq6 jIcTiQoRB8LfK5HGFsD13tSSSXE0JwVUA1Yl0IzXFboA0lgmPJkPg60CHM/dXG3sjOjZ GtQydeLuRe27srJ1rX6ha2ymwocV3Jybl6DBf+hUnT9FIr7jOynFbt1cwSNTVbiAPq5X qtI1gdUwk0fYiGnYemvBhe01OtKuDYP7i6HViA0R0OA0cHP/2RKxPMAODGZAZmSoQzi7 q0abp6GXHZ1az2aDXh7MWy5Uk0jVMdBlXrfJTASoO0Zm0FzpdiYvul6VCvjDQpOwLrXW 6+zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C+5c2I05; 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 h1-v6si24324841pgs.493.2018.10.11.05.53.10; Thu, 11 Oct 2018 05:53:25 -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=C+5c2I05; 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 S1728134AbeJKTah (ORCPT + 99 others); Thu, 11 Oct 2018 15:30:37 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:55379 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726537AbeJKTah (ORCPT ); Thu, 11 Oct 2018 15:30:37 -0400 Received: by mail-wm1-f67.google.com with SMTP id 206-v6so8733155wmb.5 for ; Thu, 11 Oct 2018 05:03:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/MGODQWupRFp3ivTTqHI0aavG641+71/uDj7XngGFGg=; b=C+5c2I05jSUqxANNB3NqXT8WI2wpxGAsfPQxfTK55p8V+0WSQtmDVy8PFQyAkiMw3l ZiF1tGQCYK4Pu3JjLis3/SJc9kotg2LihaWehrllXnJScN/BEM5khS2sRBNYF7CSba7l PpE+DkRofX0SwHpNNCQWygEZTr6uORNidxi5c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/MGODQWupRFp3ivTTqHI0aavG641+71/uDj7XngGFGg=; b=tJkbG5yd1jUjVs84kG7yBI9o08CFj0kcUlNsrg+jYLMe4R2Pp6j+Bl+EsXD5TExWCf ZfoK77GcubT6VySf9NnMoRbGOvi2mS/hxYWybDAUCRnhN/GqsgaoxECjoSoPJ8FFyopM cj08gb59+N6ic1p7pFMRmKkOYzx5U8yH3hpW9pbpO/vIw6ca6irl/McvnXUfTBcgVoRp t0oRNaNV9fHxDCdBiOzX2pVH95ziMm/MLL1Z19Ai51e97uttZiWBnaDBnUWAtSVClP/6 o8H53OxVdZLvowSlwHVCka0XWNLInhx9CMqKlCRNyKXyvWmkfXGZ6vD5A1AIdWwn9a7V G29A== X-Gm-Message-State: ABuFfohFhzBHY0NvAv1bzweLOwXJhl1fgL4Dt3DVfVSIsNMlIxJZUaxF PAAc51jgLpIIkphwCj0ZB0V3Xw== X-Received: by 2002:a1c:f010:: with SMTP id a16-v6mr1378710wmb.5.1539259418847; Thu, 11 Oct 2018 05:03:38 -0700 (PDT) Received: from localhost.localdomain ([212.45.67.2]) by smtp.googlemail.com with ESMTPSA id 193-v6sm21983286wmj.21.2018.10.11.05.03.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Oct 2018 05:03:38 -0700 (PDT) From: Georgi Djakov To: linux-pm@vger.kernel.org Cc: gregkh@linuxfoundation.org, rjw@rjwysocki.net, robh+dt@kernel.org, mturquette@baylibre.com, khilman@baylibre.com, vincent.guittot@linaro.org, skannan@codeaurora.org, bjorn.andersson@linaro.org, amit.kucheria@linaro.org, seansw@qti.qualcomm.com, daidavid1@codeaurora.org, evgreen@chromium.org, mark.rutland@arm.com, lorenzo.pieralisi@arm.com, abailon@baylibre.com, maxime.ripard@bootlin.com, arnd@arndb.de, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, ulf.hansson@linaro.org, adrian.hunter@intel.com, linux-mmc@vger.kernel.org, georgi.djakov@linaro.org Subject: [RFC] mmc: host: sdhci-msm: Use the interconnect API Date: Thu, 11 Oct 2018 15:03:36 +0300 Message-Id: <20181011120336.9129-1-georgi.djakov@linaro.org> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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; + + 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); }