Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp506762ybg; Tue, 9 Jun 2020 06:18:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBwbkQ3clFRbgWtkS6ehtwPZI7XbGABksyw88d1YleM4SZ2Nmc8kNKJaNUtU2gIeag2rxC X-Received: by 2002:a50:9556:: with SMTP id v22mr25983681eda.291.1591708722736; Tue, 09 Jun 2020 06:18:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591708722; cv=none; d=google.com; s=arc-20160816; b=p3iBHUGc9h/ArAdbw/R2z1VCNENyQSpkay8AlfaDKOYl8RUApZA6x/B2PwH1oYnPwW 2hQcdO9MWy6Ew+qjN3qWp0EKn14iWkdSdswaxrtDGOyyB4HGRrxAyGo/olNjNycRwJY4 05WW9ozLYVttOpiOkPRqI8AevkSMf6zajAG22uB+HiLLdA9b7uFJlQp2hU5mlye4n+y5 bhHMDg2FI9IXNcEUxr6xe1dSqp7288MhlGnEG/SCl2Tgpo75iX/Ztwc3DgKvwYyrpdnP gDZZ9DUrfOrZNovTMltOBuLCcx66G0sqrom9Ot1wlSiu5KGfocEChvz/+NeFDwV6JeL6 eORg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/FsPgwrQgXLgz+zKYxM6LBzJqHkPoQTxKcmVmvdLfEc=; b=BDoKpj30U0jekaIucSi1nRzGnYvDajeYLXZriAwd+ortQ89mt2vNvr9VM/giXX/sSP QsC0/6CsbFFaLjYE8RDTr6zKwjLo4OyXbHEpqUvMMIPgO4R9SkzrpcfgGJ4yPX6xezZg CbzEtgaDtHzW0zfzsX5b5iD+RowJ/mgmW6+dMawwV+mG0GMwBseZE5PmTSrz4J7VgTkY rE5+CRScywtYNcLm2F5XwE3JER4FtTAJaA5dTZz2Xw7Svx9IkS2w04fMPk3a276rOTOF 3yVgnJlnhAX/vYo2iaywn/H8sda4FOM0Vrn4zMLPfgCnKFxD3GybfHyxkoC3OIgZBH1b W39g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ihkgEepW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a22si10575412ejr.529.2020.06.09.06.18.19; Tue, 09 Jun 2020 06:18:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ihkgEepW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729771AbgFINP7 (ORCPT + 99 others); Tue, 9 Jun 2020 09:15:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729356AbgFINPJ (ORCPT ); Tue, 9 Jun 2020 09:15:09 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23E05C05BD1E; Tue, 9 Jun 2020 06:15:08 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id x18so8497722lji.1; Tue, 09 Jun 2020 06:15:08 -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=/FsPgwrQgXLgz+zKYxM6LBzJqHkPoQTxKcmVmvdLfEc=; b=ihkgEepWZSl9YpCwencySF3e1iKp+JsvT5rWuaH7ndKQZiKuRbA6N6pxZ0kwQ3BuLQ Q50UsIeeVM1VfHMllR8NXtGU8iVoR8d98H7fvrhIbDylQUta5Dy/8Nwc+SPZ27ZFIn49 nKlKSqjvtTjxTjJGldq1qyWsOT6uVMetICMF49pLZn84Z7K91qCCjDQob41M9CKSWOFe 42CWYepRvQ1lul5W2ImkaRultYk2S+ECnZoTvs3dmOftEdzT/gNTB8fNokD9vZc66DF/ 21xv2hKlSeRRsd8XH0cxL/PJ/9j+nIHdZcDYiXb/VqryqBo98CrtSMJzd9ShmSZhcA8T wDxA== 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=/FsPgwrQgXLgz+zKYxM6LBzJqHkPoQTxKcmVmvdLfEc=; b=CmvcQAII44136YAXqOrpSh9z+1MfRK29r1NUYxujx4+gcxZlm3FA5wCM+XoSpmWcnC OYXJveKuU9+5zS/E6+dG6LpkC1udCrpmN5n/RLQ3vsDfQrfBhb92Bw/Iy3zcARFHfdJ1 Rki4n09gPhbwtLzQpUkgvO21aoNGg1XT+6oOSEmreoi0uMrDT8SP6AQJlrn3+gGleDbK IxNJIjtJeBUWeEArcCQv9pWZrkwVq2IHA2iuTQNHwVBOV/7KUG+2WAZKVDW8enh/o0lj BS6nBkYuu3byZzgFLVb7qOUz7cBBw5rQoTk+T1fqV0pALwniirzhjlYhEJJcVTSn1X4x r3Vw== X-Gm-Message-State: AOAM532exXABcBlAiUymcWIEjHaV2T5RJcFsnaEahPWTw7BYTSrEGJ6+ AGlgF6EnTEStdC/JqCuQYyY= X-Received: by 2002:a2e:9c1:: with SMTP id 184mr14669736ljj.241.1591708506549; Tue, 09 Jun 2020 06:15:06 -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 l22sm4323522lji.120.2020.06.09.06.15.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 06:15:06 -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?q?Artur=20=C5=9Awigo=C5=84?= , 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 v4 34/37] memory: tegra30-emc: Register as interconnect provider Date: Tue, 9 Jun 2020 16:14:01 +0300 Message-Id: <20200609131404.17523-35-digetx@gmail.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200609131404.17523-1-digetx@gmail.com> References: <20200609131404.17523-1-digetx@gmail.com> 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 Now external memory controller is a memory interconnection provider. This allows us to use interconnect API to change memory configuration. Signed-off-by: Dmitry Osipenko --- drivers/memory/tegra/tegra30-emc.c | 110 +++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/drivers/memory/tegra/tegra30-emc.c b/drivers/memory/tegra/tegra30-emc.c index f6c688bfe41f..37cea4435d55 100644 --- a/drivers/memory/tegra/tegra30-emc.c +++ b/drivers/memory/tegra/tegra30-emc.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -327,6 +328,7 @@ struct tegra_emc { struct device *dev; struct tegra_mc *mc; struct notifier_block clk_nb; + struct icc_provider provider; struct clk *clk; void __iomem *regs; unsigned int irq; @@ -1264,6 +1266,113 @@ 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) + goto err_msg; + + /* 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); +err_msg: + dev_err(emc->dev, "failed to initialize ICC: %d\n", err); + + return err; +} + static int tegra_emc_probe(struct platform_device *pdev) { struct platform_device *mc; @@ -1343,6 +1452,7 @@ static int tegra_emc_probe(struct platform_device *pdev) platform_set_drvdata(pdev, emc); tegra_emc_debugfs_init(emc); + tegra_emc_interconnect_init(emc); /* * Don't allow the kernel module to be unloaded. Unloading adds some -- 2.26.0