public inbox for linux-sh@vger.kernel.org
 help / color / mirror / Atom feed
From: Magnus Damm <magnus.damm@gmail.com>
To: linux-sh@vger.kernel.org
Subject: [PATCH][RFC] sh: struct clk_cpg_div
Date: Thu, 21 May 2009 06:37:53 +0000	[thread overview]
Message-ID: <20090521063753.31513.20597.sendpatchset@rx1.opensource.se> (raw)

From: Magnus Damm <damm@igel.co.jp>

This patch adds CPG divisor helper functions to clock-cpg.c.

CPG divisors (and the PLL) usually found in FRQCR can now
register multipier and divisor arrays together with callbacks
for getting and setting index values.

The value read out from the hardware is used as index in the
multiplier and divisor arrays to calculate frequency. Invalid
settings in the array should be set to zero.

Only getting rate is supported for now.

Signed-off-by: Magnus Damm <damm@igel.co.jp>
---

 arch/sh/include/asm/clock.h    |   16 ++++++++++++++++
 arch/sh/kernel/cpu/clock-cpg.c |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

--- 0001/arch/sh/include/asm/clock.h
+++ work/arch/sh/include/asm/clock.h	2009-05-21 15:25:07.000000000 +0900
@@ -100,4 +100,20 @@ enum clk_sh_algo_id {
 	IP_N1,
 };
 
+struct clk_cpg_div {
+	struct clk clk;
+	int id;
+};
+
+struct clk_cpg_div_group {
+	int *multipliers;
+	int *divisors;
+	int nr_entries;
+	int (*get_index)(struct clk_cpg_div *div);
+	void (*set_index)(struct clk_cpg_div *div, int index);
+};
+
+int clk_cpg_div_register(struct clk_cpg_div *div,
+			 struct clk_cpg_div_group *group);
+
 #endif /* __ASM_SH_CLOCK_H */
--- 0005/arch/sh/kernel/cpu/clock-cpg.c
+++ work/arch/sh/kernel/cpu/clock-cpg.c	2009-05-21 15:25:01.000000000 +0900
@@ -2,6 +2,38 @@
 #include <linux/compiler.h>
 #include <asm/clock.h>
 
+static unsigned long clk_cpg_div_recalc(struct clk *clk)
+{
+	struct clk_cpg_div_group *group = clk->priv;
+	struct clk_cpg_div *div;
+	unsigned long multiplier, divisor;
+	int index;
+
+	div = (void *)((char *)clk - offsetof(struct clk_cpg_div, clk));
+	index = group->get_index(div);
+
+	BUG_ON(index >= group->nr_entries);
+
+	multiplier = group->multipliers[index];
+	divisor = group->divisors[index];
+
+	BUG_ON(!multiplier || !divisor);
+
+	return clk->parent->rate * multiplier / divisor;
+}
+
+static struct clk_ops clk_cpg_div_ops = {
+	.recalc = clk_cpg_div_recalc,
+};
+
+int clk_cpg_div_register(struct clk_cpg_div *div,
+			 struct clk_cpg_div_group *group)
+{
+	div->clk.ops = &clk_cpg_div_ops;
+	div->clk.priv = group;
+	return clk_register(&div->clk);
+}
+
 #ifndef CONFIG_SH_CLK_DISABLE_LEGACY
 
 static struct clk master_clk = {

                 reply	other threads:[~2009-05-21  6:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20090521063753.31513.20597.sendpatchset@rx1.opensource.se \
    --to=magnus.damm@gmail.com \
    --cc=linux-sh@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