From patchwork Sun Jun 7 18:55:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 211879 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E39EC433E2 for ; Sun, 7 Jun 2020 18:58:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2079020760 for ; Sun, 7 Jun 2020 18:58:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lEQ8UVkl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730169AbgFGS6b (ORCPT ); Sun, 7 Jun 2020 14:58:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728965AbgFGS5x (ORCPT ); Sun, 7 Jun 2020 14:57:53 -0400 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEFADC061A0E; Sun, 7 Jun 2020 11:57:52 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id 9so8119355ljv.5; Sun, 07 Jun 2020 11:57:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2FWL4m/VvTzCnby3H7z+0WC/QAPekJVOtv1G/JGRyfU=; b=lEQ8UVklwBZX3PXUJEKVKloYVSlhpfqTKCM2RYyMrSu2WFsviuZRN4mnw1vh54Bma/ Pm84MDaTBVEYVyeOJCx1EiHSq/PJd8IWNKjG8ETQiZHOQebQGVTADRrWneQV8KBG+uv1 /C/ayXIuTxd99QPwSJIFmH3ahl8BYkprGuq9bo2G7fmjF8WwGdGtJujS5dTn5D+GSsf6 Jq065O8RWXAGIhVIjt7uvg0H+r5nuh68+UiIKMH2v6VL+AGhVWA+VZQf8beDOKhD9E6q mC4VuOzeF+HMo8imxMB8XqiKHsWdR+DDBO79WhS1VWzz32ifKEVb6Wq3XJ4VEXL7c/Dp PZ+Q== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=2FWL4m/VvTzCnby3H7z+0WC/QAPekJVOtv1G/JGRyfU=; b=rDuCOJpZdXXTxiVUHvrbTj2tLC8z7pvg+mtGqByhEUTPTUlp6KvdJLTduECu03aO0a Rxh3qYe84ZLqM94ybAfHaHJhujFkX8rZDxWcxXO5AILkI7v21qmN97KSJwSTfDj1I2ZB S7PZebru3zBTP3TfC2G2D/NRP5qvljfZpyu2PIiKAd0RMpWUZacwMa2Uy/hw3qIQbErq R95EoenxTY5v8UjEPx/COOx+KACyF+MzN+59EJZzC0ggsQRsQhmx4pGnS9rJyOUdsWZL 7lCKjU2hzLmdcBwNTIiIi/WQgfs/WCQ6FD5x2UnwZi3dF11IkZt2EZVH1sTx+9+egjRB 09VA== X-Gm-Message-State: AOAM533mTUhMAsJitr9TiM0qOudnl2/JKk+lUn/SQJZC+UR1OofvRXMz tDDSrJRh2P/0n3g5L5zXP4g= X-Google-Smtp-Source: ABdhPJwD98GttckIkFwB4hNnZe/iTbpUVrOLxqSXn8Xq5av99HLdI8/LRLOBgo7G+mBE/dYMb8kgLw== X-Received: by 2002:a2e:145e:: with SMTP id 30mr9869151lju.205.1591556271418; Sun, 07 Jun 2020 11:57:51 -0700 (PDT) Received: from localhost.localdomain (79-139-237-54.dynamic.spd-mgts.ru. [79.139.237.54]) by smtp.gmail.com with ESMTPSA id e21sm3650953ljb.135.2020.06.07.11.57.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jun 2020 11:57:50 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Georgi Djakov , Rob Herring , Michael Turquette , Stephen Boyd , Peter De Schrijver , MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Mikko Perttunen Cc: =?utf-8?b?QXJ0dXIgxZp3aWdvxYQ=?= , linux-tegra@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org Subject: [PATCH v3 31/39] memory: tegra20-emc: Register as interconnect provider Date: Sun, 7 Jun 2020 21:55:22 +0300 Message-Id: <20200607185530.18113-32-digetx@gmail.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200607185530.18113-1-digetx@gmail.com> References: <20200607185530.18113-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Now memory controller is a memory interconnection provider. This allows us to use interconnect API in order to change memory configuration. Signed-off-by: Dmitry Osipenko --- drivers/memory/tegra/tegra20-emc.c | 115 +++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/drivers/memory/tegra/tegra20-emc.c b/drivers/memory/tegra/tegra20-emc.c index 8d1967f4b4aa..2281bf9b784b 100644 --- a/drivers/memory/tegra/tegra20-emc.c +++ b/drivers/memory/tegra/tegra20-emc.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -148,6 +149,7 @@ struct emc_timing { struct tegra_emc { struct device *dev; struct notifier_block clk_nb; + struct icc_provider provider; struct clk *clk; void __iomem *regs; @@ -661,6 +663,112 @@ static void tegra_emc_debugfs_init(struct tegra_emc *emc) emc, &tegra_emc_debug_max_rate_fops); } +static inline struct tegra_emc * +to_tegra_emc_provider(struct icc_provider *provider) +{ + return container_of(provider, struct tegra_emc, provider); +} + +static struct icc_node * +emc_of_icc_xlate(struct of_phandle_args *spec, void *data) +{ + struct icc_provider *provider = data; + struct icc_node *node; + + /* External Memory is the only possible ICC route */ + list_for_each_entry(node, &provider->nodes, node_list) { + if (node->id == TEGRA_ICC_EMEM) + return node; + } + + return ERR_PTR(-EINVAL); +} + +static int emc_icc_set(struct icc_node *src, struct icc_node *dst) +{ + struct tegra_emc *emc = to_tegra_emc_provider(dst->provider); + unsigned long long rate = icc_units_to_bps(dst->avg_bw); + unsigned int dram_data_bus_width_bytes = 4; + unsigned int ddr = 2; + int err; + + do_div(rate, ddr * dram_data_bus_width_bytes); + rate = min_t(u64, rate, U32_MAX); + + err = clk_set_min_rate(emc->clk, rate); + if (err) + return err; + + err = clk_set_rate(emc->clk, rate); + if (err) + return err; + + return 0; +} + +static int emc_icc_aggregate(struct icc_node *node, + u32 tag, u32 avg_bw, u32 peak_bw, + u32 *agg_avg, u32 *agg_peak) +{ + *agg_avg = min((u64)avg_bw + (*agg_avg), (u64)U32_MAX); + *agg_peak = max(*agg_peak, peak_bw); + + return 0; +} + +static int tegra_emc_interconnect_init(struct tegra_emc *emc) +{ + struct icc_node *node; + int err; + + /* older device-trees don't have interconnect properties */ + if (!of_find_property(emc->dev->of_node, "#interconnect-cells", NULL)) + return 0; + + emc->provider.dev = emc->dev; + emc->provider.set = emc_icc_set; + emc->provider.data = &emc->provider; + emc->provider.xlate = emc_of_icc_xlate; + emc->provider.aggregate = emc_icc_aggregate; + + err = icc_provider_add(&emc->provider); + if (err) + return err; + + /* create External Memory Controller node */ + node = icc_node_create(TEGRA_ICC_EMC); + err = PTR_ERR_OR_ZERO(node); + if (err) + goto del_provider; + + node->name = "External Memory Controller"; + icc_node_add(node, &emc->provider); + + /* link External Memory Controller to External Memory (DRAM) */ + err = icc_link_create(node, TEGRA_ICC_EMEM); + if (err) + goto remove_nodes; + + /* create External Memory node */ + node = icc_node_create(TEGRA_ICC_EMEM); + err = PTR_ERR_OR_ZERO(node); + if (err) + goto remove_nodes; + + node->name = "External Memory (DRAM)"; + icc_node_add(node, &emc->provider); + + return 0; + +remove_nodes: + icc_nodes_remove(&emc->provider); + +del_provider: + icc_provider_del(&emc->provider); + + return err; +} + static int tegra_emc_init_mc_timings(struct tegra_emc *emc) { struct tegra_mc_timing *timing; @@ -767,6 +875,13 @@ static int tegra_emc_probe(struct platform_device *pdev) platform_set_drvdata(pdev, emc); tegra_emc_debugfs_init(emc); + if (IS_ENABLED(CONFIG_INTERCONNECT)) { + err = tegra_emc_interconnect_init(emc); + if (err) + dev_err(&pdev->dev, "failed to initialize ICC: %d\n", + err); + } + /* * Don't allow the kernel module to be unloaded. Unloading adds some * extra complexity which doesn't really worth the effort in a case of