Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp751261ybg; Tue, 9 Jun 2020 11:53:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyvnwjsX6o59QoqGcU7L+OmcMR/J/TVrik/j0H7js8DXiSts/Hv+F7yUoYbdEZNIL7qc22 X-Received: by 2002:a17:906:fa03:: with SMTP id lo3mr27550294ejb.196.1591728790197; Tue, 09 Jun 2020 11:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591728790; cv=none; d=google.com; s=arc-20160816; b=Sqc0000OB6nc6qfgkzIaOmzGERLK6Xx1OqPK8p3KPaAKy0RNqcIGrR9Jh2wQOcUwSZ b4JTPRo9WAb3C0Hq/G4GUc+lRSJdEZiI1FXxb+yzEnWVTcHc5ANdM+/QdPfDJw1TSXee mQcWb1fjrXrF0bYR250jnzjcVV9EJI89Jcp8vH4sCiIU2SRupRu+IHcwPub7Wfcs0ZnE HjSgiil6ffn8wp9i1yY9xxlb+V2N1T87rjIA4Pl9kJr6RLC088aavaEBMLGIs5txC9DU CnF8nDefz1GkHeH5jSEcnXcm51cRnfj8SDrkrJbva+UW+zCJtRaRsR2P7TkLFlNWiwtR ymCw== 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=qWLmy17GC8FK7PHSQ8U9gnOM1EaYpHMCshqC+sIXbKQ=; b=O/N7uXWvu6c0sTvUdRhiQgLbwlKaFUXDOnQtsYqpH/k9XgKkmZzLuJppbGQyT/91kn gHhBaOJiPRuOHDIa8F3qeIq4T3CeuijUdg77QuTkFRwv/eu1RRUrYQ1TK7WaLxrrIOV5 fKmhLpNk2lWzSbXK5ehGfzltRwoQpx7Xsax5fq6xP0dSeYLLvTnDWtsH9anODtFoMS+W APKdM+LJ5zrqYZ9r/xPZAIsKoXwhmdJWc7XNxx2Mull2EbMW/5TYIMw+zFGqgXSP45xT HaEKEhBS2AaA3J7r0QUOD0tvQAodt5t8h+M11juvh4oM+oQ7qe3969GtlUImWxsk3X82 +7cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PtZ3FafD; 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 y24si10649631ejw.713.2020.06.09.11.52.47; Tue, 09 Jun 2020 11:53:10 -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=PtZ3FafD; 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 S1730098AbgFINR7 (ORCPT + 99 others); Tue, 9 Jun 2020 09:17:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729085AbgFINOn (ORCPT ); Tue, 9 Jun 2020 09:14:43 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40E06C05BD1E; Tue, 9 Jun 2020 06:14:43 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id a25so24978098ljp.3; Tue, 09 Jun 2020 06:14:43 -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=PtZ3FafDGDMkjdGGg6qUN0OnJf60f+Oe1vAYv0QO8j+XNPvxdaM+EF1M1nmS3kUY34 PzCcKoUALCwrQ9YAgAWxt1h153jj2rB9JUt3VwbSI42wowAlMvQsDICNmiCN3OmMmhlz CY1E8DYP5EpdGVDvulxqFCerF8gZqK+9S0R9kBF4vRQ+WcPMs+/9kUGzzZaEgQmvypjE cktPp97gljvUmgpnCARjetviUy1gBQzaB8Hwu6Bv9qQSn4LRzoPL+Va51fcCKRWmUJdX srgHviY8YRp+3xExR9wU8LjU6Kwb6279+fhVfw6UrWq/JJ4sKg+yyHYv2HWGiZkerWL0 VpNg== 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=MOX+EtDiC1myP7Dgm4Ec0CrYIeQH/m292fuA53i2d/o419KssFr8DaMFuyhfmvKoC4 9tvRsGlqDhTjVpFpNq6yAK1FVCHnOiugHitfCe1VoO6v86ijCCL97F8Xt3SuovspACKq B+dZ+YhQ9ImB3851HhUZ31ivhjRp+ZzFxHIpxymvowcvbux8JpKEIMjoXDtBXm8W3GLX jC2wwTBU8NF71T3MReG7LNsOzySfV6wfBVRFv1uJY9apiTu+3dQkF6V+55teY5YdRWw3 cJgk54WD4VYDcMgg5k+NdR93jz/cCmjPxvwzndeXFHSh+GkhQIvJO6tvoW1ivTSI4Rhd 88QQ== X-Gm-Message-State: AOAM532D6eXQbcWfel1XZ6k3nbweh7GS4F0q1veqwkINuobpFBUYRFRg 4G1EryFouvAw//ZH/IYCcFk= X-Received: by 2002:a2e:97ce:: with SMTP id m14mr13675149ljj.216.1591708481170; Tue, 09 Jun 2020 06:14:41 -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.14.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 06:14:40 -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 13/37] PM / devfreq: tegra30: Use MC timings for building OPP table Date: Tue, 9 Jun 2020 16:13:40 +0300 Message-Id: <20200609131404.17523-14-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 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