From mboxrd@z Thu Jan 1 00:00:00 1970 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.3 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,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 B27B3C433DF for ; Sun, 7 Jun 2020 19:14:19 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 868C4206F6 for ; Sun, 7 Jun 2020 19:14:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NzIgNQKU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 868C4206F6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CC9356E3D6; Sun, 7 Jun 2020 19:13:19 +0000 (UTC) Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id B6A4B6E397 for ; Sun, 7 Jun 2020 18:57:28 +0000 (UTC) Received: by mail-lj1-x242.google.com with SMTP id x18so1288343lji.1 for ; Sun, 07 Jun 2020 11:57:28 -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=qWLmy17GC8FK7PHSQ8U9gnOM1EaYpHMCshqC+sIXbKQ=; b=NzIgNQKUOvSmdiStp+r13m7kYNJlX1EmKxR4cZmq4oNGkqloMlbFKVFpDLgfP82fUV IhiyVO5OD1OovrqeCa6sDsfRtqgJbzr+b6A1eOqRxF0AyEkX6KCr1I6xswHAYru0mgXX 1/i+SzrSuIZTOQiZhV7d7AVHBVfmi2/+V0BULy8JuRjo+LlxBdr5xaOPVsiyeyxkS/VJ MvHmTGYhQ179yNwdI+hBdfO+Fu/JYplHKRjR3kl9W3HC8A5++P+cb3cJfWQLnAhTwMUt ZLNNyE0OGq76kY0dt+nnxUhi5rkhfiY1hffSAKrRs3wPAlPB1c6WjxuGrsIL2Fu2yBT1 PGvQ== 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=qWLmy17GC8FK7PHSQ8U9gnOM1EaYpHMCshqC+sIXbKQ=; b=MVVQ3iLkOb53cJxmeaxE4u2UtFDn+MnQdKUL4aT+JP4LIYdM4kZXb6FX3P7N/ZoB3X bJK3r2SEGVJJ8calETEcK2tHnbjOXAJXViB6+K1/qnZYbvKfLzKcGnhyJakCuyc17xfV X309AZh194kyba9PuEEhcLyq7hST+J74NOd12qSxjNgf0P0lQVIUykq1KS3Yyvy+HSYi mSVTcMisTFbVwrESyCorla4qnhCQxSZx0L8KYR+HzhVeGPfgicNdi5uA351ppqi7wGJf HMncRgAy4K+krwGOk5RcMYSVvcSPRRPSSvi82puHe1LtOz7FmXgSIgsdqAlrl3WRYFl7 rwMw== X-Gm-Message-State: AOAM532t6euM7h23TpF6cDxB1o46bIvMciJbvvwvBdayDF8k19Yla30v NG5Scw5DfiU0szlGhIvLZJE= X-Google-Smtp-Source: ABdhPJyk0rp2rmqT73OdLJlnWEpSNMMKaseG7J5aRmaZI7drexJ4GbV3PH0/DQWpuVTXz3D5k+jv5A== X-Received: by 2002:a05:651c:1207:: with SMTP id i7mr9321217lja.86.1591556247059; Sun, 07 Jun 2020 11:57:27 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jun 2020 11:57:26 -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 Subject: [PATCH v3 13/39] PM / devfreq: tegra30: Use MC timings for building OPP table Date: Sun, 7 Jun 2020 21:55:04 +0300 Message-Id: <20200607185530.18113-14-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 X-Mailman-Approved-At: Sun, 07 Jun 2020 19:13:00 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, =?UTF-8?q?Artur=20=C5=9Awigo=C5=84?= , linux-tegra@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The clk_round_rate() won't be usable for building OPP table once interconnect support will be added to the EMC driver because that CLK API function limits the rounded rate based on the clk rate that is imposed by active clk-users, and thus, the rounding won't work as expected if interconnect will set the minimum EMC clock rate before devfreq driver is loaded. The struct tegra_mc contains memory timings which could be used by the devfreq driver for building up OPP table instead of rounding clock rate, this patch implements this idea. Signed-off-by: Dmitry Osipenko --- drivers/devfreq/tegra30-devfreq.c | 98 ++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 28 deletions(-) diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c index 423dd35c95b3..13f93c6038ab 100644 --- a/drivers/devfreq/tegra30-devfreq.c +++ b/drivers/devfreq/tegra30-devfreq.c @@ -19,6 +19,8 @@ #include #include +#include + #include "governor.h" #define ACTMON_GLB_STATUS 0x0 @@ -153,6 +155,18 @@ struct tegra_devfreq_device { unsigned long target_freq; }; +struct tegra_devfreq_soc_data { + const char *mc_compatible; +}; + +static const struct tegra_devfreq_soc_data tegra30_soc = { + .mc_compatible = "nvidia,tegra30-mc", +}; + +static const struct tegra_devfreq_soc_data tegra124_soc = { + .mc_compatible = "nvidia,tegra124-mc", +}; + struct tegra_devfreq { struct devfreq *devfreq; @@ -771,15 +785,44 @@ static struct devfreq_governor tegra_devfreq_governor = { .interrupt_driven = true, }; +static struct tegra_mc *tegra_get_memory_controller(const char *compatible) +{ + struct platform_device *pdev; + struct device_node *np; + struct tegra_mc *mc; + + np = of_find_compatible_node(NULL, NULL, compatible); + if (!np) + return ERR_PTR(-ENOENT); + + pdev = of_find_device_by_node(np); + of_node_put(np); + if (!pdev) + return ERR_PTR(-ENODEV); + + mc = platform_get_drvdata(pdev); + if (!mc) + return ERR_PTR(-EPROBE_DEFER); + + return mc; +} + static int tegra_devfreq_probe(struct platform_device *pdev) { + const struct tegra_devfreq_soc_data *soc_data; struct tegra_devfreq_device *dev; struct tegra_devfreq *tegra; struct devfreq *devfreq; + struct tegra_mc *mc; unsigned int i; - long rate; int err; + soc_data = of_device_get_match_data(&pdev->dev); + + mc = tegra_get_memory_controller(soc_data->mc_compatible); + if (IS_ERR(mc)) + return PTR_ERR(mc); + tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL); if (!tegra) return -ENOMEM; @@ -825,6 +868,30 @@ static int tegra_devfreq_probe(struct platform_device *pdev) return err; } + if (!mc->num_timings) { + tegra->max_freq = clk_get_rate(tegra->clock) / KHZ; + + err = dev_pm_opp_add(&pdev->dev, tegra->max_freq, 0); + if (err) { + dev_err(&pdev->dev, "Failed to add OPP: %d\n", err); + return err; + } + } + + for (i = 0; i < mc->num_timings; i++) { + /* + * Memory Controller timings are sorted in ascending clock + * rate order, so the last timing will be the max freq. + */ + tegra->max_freq = mc->timings[i].rate / KHZ; + + err = dev_pm_opp_add(&pdev->dev, tegra->max_freq, 0); + if (err) { + dev_err(&pdev->dev, "Failed to add OPP: %d\n", err); + goto remove_opps; + } + } + reset_control_assert(tegra->reset); err = clk_prepare_enable(tegra->clock); @@ -836,37 +903,12 @@ static int tegra_devfreq_probe(struct platform_device *pdev) reset_control_deassert(tegra->reset); - rate = clk_round_rate(tegra->emc_clock, ULONG_MAX); - if (rate < 0) { - dev_err(&pdev->dev, "Failed to round clock rate: %ld\n", rate); - return rate; - } - - tegra->max_freq = rate / KHZ; - for (i = 0; i < ARRAY_SIZE(actmon_device_configs); i++) { dev = tegra->devices + i; dev->config = actmon_device_configs + i; dev->regs = tegra->regs + dev->config->offset; } - for (rate = 0; rate <= tegra->max_freq * KHZ; rate++) { - rate = clk_round_rate(tegra->emc_clock, rate); - - if (rate < 0) { - dev_err(&pdev->dev, - "Failed to round clock rate: %ld\n", rate); - err = rate; - goto remove_opps; - } - - err = dev_pm_opp_add(&pdev->dev, rate / KHZ, 0); - if (err) { - dev_err(&pdev->dev, "Failed to add OPP: %d\n", err); - goto remove_opps; - } - } - platform_set_drvdata(pdev, tegra); tegra->clk_rate_change_nb.notifier_call = tegra_actmon_clk_notify_cb; @@ -921,8 +963,8 @@ static int tegra_devfreq_remove(struct platform_device *pdev) } static const struct of_device_id tegra_devfreq_of_match[] = { - { .compatible = "nvidia,tegra30-actmon" }, - { .compatible = "nvidia,tegra124-actmon" }, + { .compatible = "nvidia,tegra30-actmon", .data = &tegra30_soc, }, + { .compatible = "nvidia,tegra124-actmon", .data = &tegra124_soc, }, { }, }; -- 2.26.0 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel