From: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
To: linux-fbdev@vger.kernel.org
Subject: [PATCH/RFC 3/3] ARM: mach-shmobile: implement parent clock optimization
Date: Wed, 27 Oct 2010 16:24:26 +0000 [thread overview]
Message-ID: <Pine.LNX.4.64.1010271821580.11687@axis700.grange> (raw)
On ap4evb PLLC2 is used as a parent clock for the HDMI clock. To configure the
HDMI clock with the highest precision this patch scans all available PLLC2
frequencies and picks up the best one.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
---
arch/arm/mach-shmobile/board-ap4evb.c | 60 +++++++++++++++++++++++++++++++++
1 files changed, 60 insertions(+), 0 deletions(-)
diff --git a/arch/arm/mach-shmobile/board-ap4evb.c b/arch/arm/mach-shmobile/board-ap4evb.c
index 7d0a8c4..8676e26 100644
--- a/arch/arm/mach-shmobile/board-ap4evb.c
+++ b/arch/arm/mach-shmobile/board-ap4evb.c
@@ -637,9 +637,69 @@ static struct platform_device lcdc1_device = {
},
};
+#define MAX_DIVISOR 63
+
+static long ap4evb_clk_optimize(unsigned long target, unsigned long *best_freq,
+ unsigned long *parent_freq)
+{
+ struct cpufreq_frequency_table *freq, *best = NULL;
+ unsigned long error = ULONG_MAX, freq_high, freq_low, div;
+
+ for (freq = pllc2_clk.freq_table; freq->frequency != CPUFREQ_TABLE_END;
+ freq++) {
+ if (freq->frequency < target) {
+ if (error > target - freq->frequency) {
+ error = target - freq->frequency;
+ best = freq;
+ if (best_freq)
+ *best_freq = freq->frequency;
+ }
+ continue;
+ }
+ div = freq->frequency / target;
+ if (div > MAX_DIVISOR)
+ div = MAX_DIVISOR;
+ freq_high = freq->frequency / div;
+ freq_low = freq->frequency / (div + 1);
+ if (freq_high - target < error) {
+ error = freq_high - target;
+ best = freq;
+ if (best_freq)
+ *best_freq = freq_high;
+ }
+ if (target - freq_low < error) {
+ error = target - freq_low;
+ best = freq;
+ if (best_freq)
+ *best_freq = freq_low;
+ }
+ pr_debug("%u / %lu = %lu, / %lu = %lu, best %lu, parent %u\n",
+ freq->frequency, div, freq_high, div + 1, freq_low,
+ *best_freq, best->frequency);
+ if (!error)
+ break;
+ }
+ if (parent_freq)
+ *parent_freq = best->frequency;
+ return error;
+}
+
+static int ap4evb_clk_set_rate(struct clk *clk, unsigned long rate)
+{
+ return clk_set_rate(clk->parent, rate);
+}
+
+static unsigned long ap4evb_clk_get_rate(struct clk *clk)
+{
+ return clk_get_rate(clk->parent);
+}
+
static struct sh_mobile_hdmi_info hdmi_info = {
.lcd_chan = &sh_mobile_lcdc1_info.ch[0],
.lcd_dev = &lcdc1_device.dev,
+ .clk_optimize_parent = ap4evb_clk_optimize,
+ .clk_set_rate_parent = ap4evb_clk_set_rate,
+ .clk_get_rate_parent = ap4evb_clk_get_rate,
};
static struct resource hdmi_resources[] = {
--
1.7.1
next reply other threads:[~2010-10-27 16:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-27 16:24 Guennadi Liakhovetski [this message]
2010-10-28 0:28 ` [PATCH/RFC 3/3] ARM: mach-shmobile: implement parent clock optimization for HDMI Paul Mundt
2010-10-28 6:29 ` [PATCH/RFC 3/3] ARM: mach-shmobile: implement parent clock Guennadi Liakhovetski
2010-10-28 6:53 ` [PATCH/RFC 3/3] ARM: mach-shmobile: implement parent clock optimization for HDMI Paul Mundt
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=Pine.LNX.4.64.1010271821580.11687@axis700.grange \
--to=g.liakhovetski@gmx.de \
--cc=linux-fbdev@vger.kernel.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