ARM Sunxi Platform Development
 help / color / mirror / Atom feed
From: Samuel Holland <samuel@sholland.org>
To: MyungJoo Ham <myungjoo.ham@samsung.com>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	Chanwoo Choi <cw00.choi@samsung.com>,
	Maxime Ripard <mripard@kernel.org>, Chen-Yu Tsai <wens@csie.org>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	Rob Herring <robh+dt@kernel.org>
Cc: Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>,
	devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-pm@vger.kernel.org, linux-sunxi@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	Samuel Holland <samuel@sholland.org>
Subject: [PATCH 04/10] PM / devfreq: Add a recommended frequency helper
Date: Tue, 28 Sep 2021 23:42:48 -0500	[thread overview]
Message-ID: <20210929044254.38301-5-samuel@sholland.org> (raw)
In-Reply-To: <20210929044254.38301-1-samuel@sholland.org>

This helper peforms the same function as devfreq_recommended_opp().
However, it works on devices without OPPs by iterating over freq_table.
Since freq_table is assumed to be sorted in ascending order, the
algorithm is relatively simple.

Devices with OPPs should continue using devfreq_recommended_opp(), as
that function respects disabled OPPs.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---
 drivers/devfreq/devfreq.c | 27 +++++++++++++++++++++++++++
 include/linux/devfreq.h   |  2 ++
 2 files changed, 29 insertions(+)

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index f5d27f5285db..fd46792297ad 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -1984,6 +1984,33 @@ subsys_initcall(devfreq_init);
  * OPP framework.
  */
 
+/**
+ * devfreq_recommended_freq() - Helper function to get the proper frequency from
+ *			        freq_table for the value given to target callback.
+ * @devfreq:	The devfreq device.
+ * @freq:	The frequency given to target function.
+ * @flags:	Flags handed from devfreq framework.
+ */
+void devfreq_recommended_freq(struct devfreq *devfreq,
+			      unsigned long *freq, u32 flags)
+{
+	const unsigned long *min = devfreq->profile->freq_table;
+	const unsigned long *max = min + devfreq->profile->max_state - 1;
+	const unsigned long *f;
+
+	if (flags & DEVFREQ_FLAG_LEAST_UPPER_BOUND) {
+		/* Find the first item lower than freq, or else min. */
+		for (f = max; f > min && *f > *freq; --f)
+			;
+	} else {
+		/* Find the first item higher than freq, or else max. */
+		for (f = min; f < max && *f < *freq; ++f)
+			;
+	}
+	*freq = *f;
+}
+EXPORT_SYMBOL(devfreq_recommended_freq);
+
 /**
  * devfreq_recommended_opp() - Helper function to get proper OPP for the
  *			     freq value given to target callback.
diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
index 142474b4af96..4d324fea8a78 100644
--- a/include/linux/devfreq.h
+++ b/include/linux/devfreq.h
@@ -239,6 +239,8 @@ void devfreq_resume(void);
 int update_devfreq(struct devfreq *devfreq);
 
 /* Helper functions for devfreq user device driver with OPP. */
+void devfreq_recommended_freq(struct devfreq *devfreq,
+			      unsigned long *freq, u32 flags);
 struct dev_pm_opp *devfreq_recommended_opp(struct device *dev,
 				unsigned long *freq, u32 flags);
 int devfreq_register_opp_notifier(struct device *dev,
-- 
2.31.1


  parent reply	other threads:[~2021-09-29  4:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29  4:42 [PATCH 00/10] DRAM devfreq support for Allwinner A64/H5 Samuel Holland
2021-09-29  4:42 ` [PATCH 01/10] PM / devfreq: strengthen check for freq_table Samuel Holland
2021-09-30  3:58   ` Chanwoo Choi
2021-09-29  4:42 ` [PATCH 02/10] PM / devfreq: Do not require devices to have OPPs Samuel Holland
2021-09-30  4:19   ` Chanwoo Choi
2021-09-30 11:37     ` Samuel Holland
2021-10-01  1:59       ` Chanwoo Choi
2021-10-01  1:45         ` Samuel Holland
2021-10-01  2:14           ` Chanwoo Choi
2021-09-29  4:42 ` [PATCH 03/10] PM / devfreq: Drop code for descending freq_table Samuel Holland
2021-09-29  4:42 ` Samuel Holland [this message]
2021-09-29  4:42 ` [PATCH 05/10] dt-bindings: clock: sunxi: Export CLK_DRAM for devfreq Samuel Holland
2021-09-29  4:42 ` [PATCH 06/10] dt-bindings: arm: sunxi: Expand MBUS binding Samuel Holland
2021-09-29 13:46   ` Rob Herring
2021-09-29  4:42 ` [PATCH 07/10] dt-bindings: arm: sunxi: Add H5 MBUS compatible Samuel Holland
2021-09-29  4:42 ` [PATCH 08/10] ARM: dts: sunxi: h3/h5: Update MBUS node Samuel Holland
2021-09-29  4:42 ` [PATCH 09/10] arm64: dts: allwinner: a64: " Samuel Holland
2021-09-29  4:42 ` [PATCH 10/10] PM / devfreq: Add a driver for the sun8i/sun50i MBUS Samuel Holland
2021-09-30  4:35   ` Chanwoo Choi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210929044254.38301-5-samuel@sholland.org \
    --to=samuel@sholland.org \
    --cc=cw00.choi@samsung.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jernej.skrabec@gmail.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=mripard@kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=myungjoo.ham@samsung.com \
    --cc=robh+dt@kernel.org \
    --cc=sboyd@kernel.org \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox