public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] CLK: Introduce virtual clock registration
@ 2008-08-20  9:51 Hiroshi DOYU
  2008-08-20  9:51 ` [PATCH 2/2] CLK: Use virtual clock register for mcbsp clock Hiroshi DOYU
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Hiroshi DOYU @ 2008-08-20  9:51 UTC (permalink / raw)
  To: linux-omap; +Cc: paul, eduardo.valentin, Hiroshi DOYU

This patch provides the interface to register and unregister a virtual
clock which groups multiple clocks in it in order to handle this group
of clocks at once. Presently just clk_enable and clk_disable is
overwritten and other operation can be done as well.

This is just a refactor of MCBSP clock registration.

Signed-off-by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
---
 arch/arm/plat-omap/clock.c              |   73 +++++++++++++++++++++++++++++++
 arch/arm/plat-omap/include/mach/clock.h |   19 ++++++++
 2 files changed, 92 insertions(+), 0 deletions(-)

diff --git a/arch/arm/plat-omap/clock.c b/arch/arm/plat-omap/clock.c
index 23a0705..401de98 100644
--- a/arch/arm/plat-omap/clock.c
+++ b/arch/arm/plat-omap/clock.c
@@ -374,6 +374,79 @@ EXPORT_SYMBOL(clk_init_cpufreq_table);
 #endif
 
 /*-------------------------------------------------------------------------*/
+/*
+ *	Virtual clock/Clock aggregation
+ */
+int vclk_enable(struct clk *clk)
+{
+	int i;
+	struct vclk *vc = container_of(clk, struct vclk, clk);
+
+	for (i = 0; i < vc->n_childs; i++)
+		clk_enable(vc->childs[i]);
+	return 0;
+}
+
+void vclk_disable(struct clk *clk)
+{
+	int i;
+	struct vclk *vc = container_of(clk, struct vclk, clk);
+
+	for (i = 0; i < vc->n_childs; i++)
+		clk_disable(vc->childs[i]);
+}
+
+int vclk_register(struct vclk *vc, struct vclk_cci *cci, int num_child)
+{
+	int i, err;
+
+	vc->n_childs = num_child;
+	vc->childs = kzalloc(num_child * sizeof(struct clk *), GFP_KERNEL);
+	if (!vc->childs)
+		return -ENOMEM;
+
+	vc->clk.enable = vclk_enable;
+	vc->clk.disable = vclk_disable;
+
+	for (i = 0; i < num_child; i++, cci++) {
+		struct clk *c;
+		/* fake a platform device to get correct device ID */
+		struct platform_device pdev;
+
+		c = vc->childs[i];
+		pdev.dev.bus = &platform_bus_type;
+		pdev.id = cci->id;
+		c = clk_get(&pdev.dev, cci->name);
+		if (IS_ERR(c)) {
+			pr_err("Could not get clock %s (%d).\n",
+			       cci->name, cci->id);
+			err = PTR_ERR(c);
+			goto err_out;
+		}
+		vc->childs[i] = c;
+	}
+	err = clk_register(&vc->clk);
+	if (err)
+		goto err_out;
+	return 0;
+err_out:
+	while (--i >= 0)
+		clk_put(vc->childs[i]);
+	kfree(vc->childs);
+	return err;
+}
+EXPORT_SYMBOL(vclk_register);
+
+void vclk_unregister(struct vclk *vc)
+{
+	int i = vc->n_childs;
+
+	clk_unregister(&vc->clk);
+	while (--i >= 0)
+		clk_put(vc->childs[i]);
+	kfree(vc->childs);
+}
+EXPORT_SYMBOL(vclk_unregister);
 
 #ifdef CONFIG_OMAP_RESET_CLOCKS
 /*
diff --git a/arch/arm/plat-omap/include/mach/clock.h b/arch/arm/plat-omap/include/mach/clock.h
index c6762e9..45144f5 100644
--- a/arch/arm/plat-omap/include/mach/clock.h
+++ b/arch/arm/plat-omap/include/mach/clock.h
@@ -94,6 +94,25 @@ struct clk {
 #endif
 };
 
+/*
+ * Virtual Clock which holds multiple clocks in it and does some
+ * operations (enable/disable) against these child clocks at once
+ */
+struct vclk {
+	struct clk clk;
+	struct clk **childs;
+	int n_childs;
+};
+
+/* Child Clock Info for virtual clock registration */
+struct vclk_cci {
+	const char *name;
+	int id;
+};
+
+extern int vclk_register(struct vclk *vclk, struct vclk_cci *cci, int n_child);
+extern void vclk_unregister(struct vclk *vclk);
+
 struct cpufreq_frequency_table;
 
 struct clk_functions {
-- 
1.5.5.1.357.g1af8b


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] CLK: Use virtual clock register for mcbsp clock
  2008-08-20  9:51 [PATCH 1/2] CLK: Introduce virtual clock registration Hiroshi DOYU
@ 2008-08-20  9:51 ` Hiroshi DOYU
  2008-08-20 10:04 ` [PATCH 1/2] CLK: Introduce virtual clock registration Daniel Stone
  2008-08-20 10:18 ` Felipe Balbi
  2 siblings, 0 replies; 9+ messages in thread
From: Hiroshi DOYU @ 2008-08-20  9:51 UTC (permalink / raw)
  To: linux-omap; +Cc: paul, eduardo.valentin, Hiroshi DOYU

Signed-off-by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
---
 arch/arm/mach-omap2/mcbsp.c |  107 ++++++++++++++----------------------------
 1 files changed, 36 insertions(+), 71 deletions(-)

diff --git a/arch/arm/mach-omap2/mcbsp.c b/arch/arm/mach-omap2/mcbsp.c
index cedb9a6..410ce8b 100644
--- a/arch/arm/mach-omap2/mcbsp.c
+++ b/arch/arm/mach-omap2/mcbsp.c
@@ -22,105 +22,72 @@
 #include <mach/cpu.h>
 #include <mach/mcbsp.h>
 
-struct mcbsp_internal_clk {
-	struct clk clk;
-	struct clk **childs;
-	int n_childs;
-};
-
 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
-static void omap_mcbsp_clk_init(struct mcbsp_internal_clk *mclk)
-{
-	const char *clk_names[] = { "mcbsp_ick", "mcbsp_fck" };
-	int i;
-
-	mclk->n_childs = ARRAY_SIZE(clk_names);
-	mclk->childs = kzalloc(mclk->n_childs * sizeof(struct clk *),
-				GFP_KERNEL);
-
-	for (i = 0; i < mclk->n_childs; i++) {
-		/* We fake a platform device to get correct device id */
-		struct platform_device pdev;
-
-		pdev.dev.bus = &platform_bus_type;
-		pdev.id = mclk->clk.id;
-		mclk->childs[i] = clk_get(&pdev.dev, clk_names[i]);
-		if (IS_ERR(mclk->childs[i]))
-			printk(KERN_ERR "Could not get clock %s (%d).\n",
-				clk_names[i], mclk->clk.id);
-	}
-}
-
-static int omap_mcbsp_clk_enable(struct clk *clk)
-{
-	struct mcbsp_internal_clk *mclk = container_of(clk,
-					struct mcbsp_internal_clk, clk);
-	int i;
-
-	for (i = 0; i < mclk->n_childs; i++)
-		clk_enable(mclk->childs[i]);
-	return 0;
-}
-
-static void omap_mcbsp_clk_disable(struct clk *clk)
-{
-	struct mcbsp_internal_clk *mclk = container_of(clk,
-					struct mcbsp_internal_clk, clk);
-	int i;
-
-	for (i = 0; i < mclk->n_childs; i++)
-		clk_disable(mclk->childs[i]);
-}
-
-static struct mcbsp_internal_clk omap_mcbsp_clks[] = {
+static struct vclk omap_mcbsp_clks[] = {
 	{
 		.clk = {
 			.name 		= "mcbsp_clk",
 			.id		= 1,
-			.enable		= omap_mcbsp_clk_enable,
-			.disable	= omap_mcbsp_clk_disable,
 		},
 	},
 	{
 		.clk = {
 			.name 		= "mcbsp_clk",
 			.id		= 2,
-			.enable		= omap_mcbsp_clk_enable,
-			.disable	= omap_mcbsp_clk_disable,
 		},
 	},
 	{
 		.clk = {
 			.name		= "mcbsp_clk",
 			.id		= 3,
-			.enable		= omap_mcbsp_clk_enable,
-			.disable	= omap_mcbsp_clk_disable,
 		},
 	},
 	{
 		.clk = {
 			.name		= "mcbsp_clk",
 			.id		= 4,
-			.enable		= omap_mcbsp_clk_enable,
-			.disable	= omap_mcbsp_clk_disable,
 		},
 	},
 	{
 		.clk = {
 			.name		= "mcbsp_clk",
 			.id		= 5,
-			.enable		= omap_mcbsp_clk_enable,
-			.disable	= omap_mcbsp_clk_disable,
 		},
 	},
 };
+#define omap_mcbsp_clks_size   ARRAY_SIZE(omap_mcbsp_clks)
+
+static int omap_mcbsp_clk_init(void)
+{
+	int i, err;
+	struct vclk *p;
+	struct vclk_cci cci[] = {
+		{
+			.name = "mcbsp_ick",
+		},
+		{
+			.name = "mcbsp_fck",
+		},
+	};
+
+	p = omap_mcbsp_clks;
+	for (i = 0; i < omap_mcbsp_clks_size; i++, p++) {
+		int j;
+		for (j = 0; j < ARRAY_SIZE(cci); j++)
+			cci[j].id = p->clk.id;
 
-#define omap_mcbsp_clks_size	ARRAY_SIZE(omap_mcbsp_clks)
+		err = vclk_register(p, cci, ARRAY_SIZE(cci));
+		if (err)
+			goto err_out;
+	}
+	return 0;
+err_out:
+	while (--i >= 0)
+		vclk_unregister(&omap_mcbsp_clks[i]);
+	return err;
+}
 #else
-#define omap_mcbsp_clks_size	0
-static struct mcbsp_internal_clk __initdata *omap_mcbsp_clks;
-static inline void omap_mcbsp_clk_init(struct clk *clk)
-{ }
+static inline int omap_mcbsp_clk_init(void) { return 0; }
 #endif
 
 static void omap2_mcbsp2_mux_setup(void)
@@ -222,13 +189,11 @@ static struct omap_mcbsp_platform_data omap34xx_mcbsp_pdata[] = {
 
 static int __init omap2_mcbsp_init(void)
 {
-	int i;
+	int err;
 
-	for (i = 0; i < omap_mcbsp_clks_size; i++) {
-		/* Once we call clk_get inside init, we do not register it */
-		omap_mcbsp_clk_init(&omap_mcbsp_clks[i]);
-		clk_register(&omap_mcbsp_clks[i].clk);
-	}
+	err = omap_mcbsp_clk_init();
+	if (err)
+		return err;
 
 	if (cpu_is_omap24xx())
 		omap_mcbsp_count = OMAP24XX_MCBSP_PDATA_SZ;
-- 
1.5.5.1.357.g1af8b


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] CLK: Introduce virtual clock registration
  2008-08-20  9:51 [PATCH 1/2] CLK: Introduce virtual clock registration Hiroshi DOYU
  2008-08-20  9:51 ` [PATCH 2/2] CLK: Use virtual clock register for mcbsp clock Hiroshi DOYU
@ 2008-08-20 10:04 ` Daniel Stone
  2008-08-20 11:15   ` Hiroshi DOYU
  2008-08-20 10:18 ` Felipe Balbi
  2 siblings, 1 reply; 9+ messages in thread
From: Daniel Stone @ 2008-08-20 10:04 UTC (permalink / raw)
  To: ext Hiroshi DOYU; +Cc: linux-omap, paul, eduardo.valentin

[-- Attachment #1: Type: text/plain, Size: 194 bytes --]

On Wed, Aug 20, 2008 at 12:51:51PM +0300, ext Hiroshi DOYU wrote:
> +	struct clk **childs;
> +	int n_childs;

This is a ridiculously pedantic nitpick, but s/childs/children/. :)

Cheers,
Daniel

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] CLK: Introduce virtual clock registration
  2008-08-20  9:51 [PATCH 1/2] CLK: Introduce virtual clock registration Hiroshi DOYU
  2008-08-20  9:51 ` [PATCH 2/2] CLK: Use virtual clock register for mcbsp clock Hiroshi DOYU
  2008-08-20 10:04 ` [PATCH 1/2] CLK: Introduce virtual clock registration Daniel Stone
@ 2008-08-20 10:18 ` Felipe Balbi
  2008-08-20 11:54   ` Tony Lindgren
  2 siblings, 1 reply; 9+ messages in thread
From: Felipe Balbi @ 2008-08-20 10:18 UTC (permalink / raw)
  To: ext Hiroshi DOYU; +Cc: linux-omap, paul, eduardo.valentin

On Wed, Aug 20, 2008 at 12:51:51PM +0300, Hiroshi DOYU wrote:
> +int vclk_enable(struct clk *clk)
> +{
> +	int i;
> +	struct vclk *vc = container_of(clk, struct vclk, clk);
> +
> +	for (i = 0; i < vc->n_childs; i++)
> +		clk_enable(vc->childs[i]);

missing an error check for clk_enable()

-- 
balbi

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] CLK: Introduce virtual clock registration
  2008-08-20 10:04 ` [PATCH 1/2] CLK: Introduce virtual clock registration Daniel Stone
@ 2008-08-20 11:15   ` Hiroshi DOYU
  0 siblings, 0 replies; 9+ messages in thread
From: Hiroshi DOYU @ 2008-08-20 11:15 UTC (permalink / raw)
  To: daniel.stone; +Cc: linux-omap, paul, eduardo.valentin

From: Daniel Stone <daniel.stone@nokia.com>
Subject: Re: [PATCH 1/2] CLK: Introduce virtual clock registration
Date: Wed, 20 Aug 2008 13:04:44 +0300

> On Wed, Aug 20, 2008 at 12:51:51PM +0300, ext Hiroshi DOYU wrote:
> > +	struct clk **childs;
> > +	int n_childs;
> 
> This is a ridiculously pedantic nitpick, but s/childs/children/. :)

Right. I will take an english language class again....

       Hiroshi DOYU


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] CLK: Introduce virtual clock registration
  2008-08-20 10:18 ` Felipe Balbi
@ 2008-08-20 11:54   ` Tony Lindgren
  0 siblings, 0 replies; 9+ messages in thread
From: Tony Lindgren @ 2008-08-20 11:54 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: ext Hiroshi DOYU, linux-omap, paul, eduardo.valentin

* Felipe Balbi <felipe.balbi@nokia.com> [080820 13:17]:
> On Wed, Aug 20, 2008 at 12:51:51PM +0300, Hiroshi DOYU wrote:
> > +int vclk_enable(struct clk *clk)
> > +{
> > +	int i;
> > +	struct vclk *vc = container_of(clk, struct vclk, clk);
> > +
> > +	for (i = 0; i < vc->n_childs; i++)
> > +		clk_enable(vc->childs[i]);
> 
> missing an error check for clk_enable()

And disable all virtual clocks if any of them fail?
Looks good other than that.

Tony

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/2] CLK: Introduce virtual clock registration
@ 2008-08-20 12:04 Hiroshi DOYU
  2008-08-20 19:10 ` Eduardo Valentin
  0 siblings, 1 reply; 9+ messages in thread
From: Hiroshi DOYU @ 2008-08-20 12:04 UTC (permalink / raw)
  To: linux-omap
  Cc: paul, eduardo.valentin, felipe.balbi, tony, daniel.stone,
	Hiroshi DOYU

This patch provides the interface to register and unregister a virtual
clock which groups multiple clocks in it in order to handle this group
of clocks at once. Presently just clk_enable and clk_disable is
overwritten and other operation can be done as well.

This is just a refactor of MCBSP clock registration.

Signed-off-by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
---
 arch/arm/plat-omap/clock.c              |   80 +++++++++++++++++++++++++++++++
 arch/arm/plat-omap/include/mach/clock.h |   19 +++++++
 2 files changed, 99 insertions(+), 0 deletions(-)

diff --git a/arch/arm/plat-omap/clock.c b/arch/arm/plat-omap/clock.c
index 23a0705..c35b968 100644
--- a/arch/arm/plat-omap/clock.c
+++ b/arch/arm/plat-omap/clock.c
@@ -374,6 +374,86 @@ EXPORT_SYMBOL(clk_init_cpufreq_table);
 #endif
 
 /*-------------------------------------------------------------------------*/
+/*
+ *	Virtual clock/Clock aggregation
+ */
+static int vclk_enable(struct clk *clk)
+{
+	int i, err;
+	struct vclk *vc = container_of(clk, struct vclk, clk);
+
+	for (i = 0; i < vc->n_child; i++) {
+		err = clk_enable(vc->child[i]);
+		if (err)
+			goto err_out;
+	}
+	return 0;
+err_out:
+	while (--i >= 0)
+		clk_disable(vc->child[i]);
+	return err;
+}
+
+static void vclk_disable(struct clk *clk)
+{
+	int i;
+	struct vclk *vc = container_of(clk, struct vclk, clk);
+
+	for (i = 0; i < vc->n_child; i++)
+		clk_disable(vc->child[i]);
+}
+
+int vclk_register(struct vclk *vc, struct vclk_cci *cci, int num_child)
+{
+	int i, err;
+
+	vc->n_child = num_child;
+	vc->child = kzalloc(num_child * sizeof(struct clk *), GFP_KERNEL);
+	if (!vc->child)
+		return -ENOMEM;
+
+	vc->clk.enable = vclk_enable;
+	vc->clk.disable = vclk_disable;
+
+	for (i = 0; i < num_child; i++, cci++) {
+		struct clk *c;
+		/* fake a platform device to get correct device ID */
+		struct platform_device pdev;
+
+		c = vc->child[i];
+		pdev.dev.bus = &platform_bus_type;
+		pdev.id = cci->id;
+		c = clk_get(&pdev.dev, cci->name);
+		if (IS_ERR(c)) {
+			pr_err("Could not get clock %s (%d).\n",
+			       cci->name, cci->id);
+			err = PTR_ERR(c);
+			goto err_out;
+		}
+		vc->child[i] = c;
+	}
+	err = clk_register(&vc->clk);
+	if (err)
+		goto err_out;
+	return 0;
+err_out:
+	while (--i >= 0)
+		clk_put(vc->child[i]);
+	kfree(vc->child);
+	return err;
+}
+EXPORT_SYMBOL(vclk_register);
+
+void vclk_unregister(struct vclk *vc)
+{
+	int i = vc->n_child;
+
+	clk_unregister(&vc->clk);
+	while (--i >= 0)
+		clk_put(vc->child[i]);
+	kfree(vc->child);
+}
+EXPORT_SYMBOL(vclk_unregister);
 
 #ifdef CONFIG_OMAP_RESET_CLOCKS
 /*
diff --git a/arch/arm/plat-omap/include/mach/clock.h b/arch/arm/plat-omap/include/mach/clock.h
index c6762e9..5483027 100644
--- a/arch/arm/plat-omap/include/mach/clock.h
+++ b/arch/arm/plat-omap/include/mach/clock.h
@@ -94,6 +94,25 @@ struct clk {
 #endif
 };
 
+/*
+ * Virtual Clock which holds multiple clocks in it and does some
+ * operations (enable/disable) against these child clocks at once
+ */
+struct vclk {
+	struct clk clk;
+	struct clk **child;
+	int n_child;
+};
+
+/* Child Clock Info for virtual clock registration */
+struct vclk_cci {
+	const char *name;
+	int id;
+};
+
+extern int vclk_register(struct vclk *vclk, struct vclk_cci *cci, int n_child);
+extern void vclk_unregister(struct vclk *vclk);
+
 struct cpufreq_frequency_table;
 
 struct clk_functions {
-- 
1.5.5.1.357.g1af8b


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] CLK: Introduce virtual clock registration
  2008-08-20 12:04 Hiroshi DOYU
@ 2008-08-20 19:10 ` Eduardo Valentin
  2008-08-21  9:57   ` Hiroshi DOYU
  0 siblings, 1 reply; 9+ messages in thread
From: Eduardo Valentin @ 2008-08-20 19:10 UTC (permalink / raw)
  To: Hiroshi DOYU
  Cc: linux-omap, paul, eduardo.valentin, felipe.balbi, tony,
	daniel.stone

Hi Hiroshi,

On Wed, Aug 20, 2008 at 03:04:38PM +0300, Hiroshi DOYU wrote:
> This patch provides the interface to register and unregister a virtual
> clock which groups multiple clocks in it in order to handle this group
> of clocks at once. Presently just clk_enable and clk_disable is
> overwritten and other operation can be done as well.
> 
> This is just a refactor of MCBSP clock registration.

These two patches seams ok to me. I didn't expose it as
a virtual clock API 'cause I didn't find any other place
to use it other than mcbsp code.

Anyway, the code looks more manageble now. I'd just suggest
a refactor of mach-omap1 files to be included into this series as well.

> 
> Signed-off-by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
Acked-by: Eduardo Valentin <eduardo.valentin@indt.org.br>
> ---
>  arch/arm/plat-omap/clock.c              |   80 +++++++++++++++++++++++++++++++
>  arch/arm/plat-omap/include/mach/clock.h |   19 +++++++
>  2 files changed, 99 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/arm/plat-omap/clock.c b/arch/arm/plat-omap/clock.c
> index 23a0705..c35b968 100644
> --- a/arch/arm/plat-omap/clock.c
> +++ b/arch/arm/plat-omap/clock.c
> @@ -374,6 +374,86 @@ EXPORT_SYMBOL(clk_init_cpufreq_table);
>  #endif
>  
>  /*-------------------------------------------------------------------------*/
> +/*
> + *	Virtual clock/Clock aggregation
> + */
> +static int vclk_enable(struct clk *clk)
> +{
> +	int i, err;
> +	struct vclk *vc = container_of(clk, struct vclk, clk);
> +
> +	for (i = 0; i < vc->n_child; i++) {
> +		err = clk_enable(vc->child[i]);
> +		if (err)
> +			goto err_out;
> +	}
> +	return 0;
> +err_out:
> +	while (--i >= 0)
> +		clk_disable(vc->child[i]);
> +	return err;
> +}
> +
> +static void vclk_disable(struct clk *clk)
> +{
> +	int i;
> +	struct vclk *vc = container_of(clk, struct vclk, clk);
> +
> +	for (i = 0; i < vc->n_child; i++)
> +		clk_disable(vc->child[i]);
> +}
> +
> +int vclk_register(struct vclk *vc, struct vclk_cci *cci, int num_child)
> +{
> +	int i, err;
> +
> +	vc->n_child = num_child;
> +	vc->child = kzalloc(num_child * sizeof(struct clk *), GFP_KERNEL);
> +	if (!vc->child)
> +		return -ENOMEM;
> +
> +	vc->clk.enable = vclk_enable;
> +	vc->clk.disable = vclk_disable;
> +
> +	for (i = 0; i < num_child; i++, cci++) {
> +		struct clk *c;
> +		/* fake a platform device to get correct device ID */
> +		struct platform_device pdev;
> +
> +		c = vc->child[i];
> +		pdev.dev.bus = &platform_bus_type;
> +		pdev.id = cci->id;
> +		c = clk_get(&pdev.dev, cci->name);
> +		if (IS_ERR(c)) {
> +			pr_err("Could not get clock %s (%d).\n",
> +			       cci->name, cci->id);
> +			err = PTR_ERR(c);
> +			goto err_out;
> +		}
> +		vc->child[i] = c;
> +	}
> +	err = clk_register(&vc->clk);
> +	if (err)
> +		goto err_out;
> +	return 0;
> +err_out:
> +	while (--i >= 0)
> +		clk_put(vc->child[i]);
> +	kfree(vc->child);
> +	return err;
> +}
> +EXPORT_SYMBOL(vclk_register);
> +
> +void vclk_unregister(struct vclk *vc)
> +{
> +	int i = vc->n_child;
> +
> +	clk_unregister(&vc->clk);
> +	while (--i >= 0)
> +		clk_put(vc->child[i]);
> +	kfree(vc->child);
> +}
> +EXPORT_SYMBOL(vclk_unregister);
>  
>  #ifdef CONFIG_OMAP_RESET_CLOCKS
>  /*
> diff --git a/arch/arm/plat-omap/include/mach/clock.h b/arch/arm/plat-omap/include/mach/clock.h
> index c6762e9..5483027 100644
> --- a/arch/arm/plat-omap/include/mach/clock.h
> +++ b/arch/arm/plat-omap/include/mach/clock.h
> @@ -94,6 +94,25 @@ struct clk {
>  #endif
>  };
>  
> +/*
> + * Virtual Clock which holds multiple clocks in it and does some
> + * operations (enable/disable) against these child clocks at once
> + */
> +struct vclk {
> +	struct clk clk;
> +	struct clk **child;
> +	int n_child;
> +};
> +
> +/* Child Clock Info for virtual clock registration */
> +struct vclk_cci {
> +	const char *name;
> +	int id;
> +};
> +
> +extern int vclk_register(struct vclk *vclk, struct vclk_cci *cci, int n_child);
> +extern void vclk_unregister(struct vclk *vclk);
> +
>  struct cpufreq_frequency_table;
>  
>  struct clk_functions {
> -- 
> 1.5.5.1.357.g1af8b

-- 

BR,

---
Eduardo Bezerra Valentin
+55 92 21261118

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] CLK: Introduce virtual clock registration
  2008-08-20 19:10 ` Eduardo Valentin
@ 2008-08-21  9:57   ` Hiroshi DOYU
  0 siblings, 0 replies; 9+ messages in thread
From: Hiroshi DOYU @ 2008-08-21  9:57 UTC (permalink / raw)
  To: eduardo.valentin; +Cc: linux-omap, paul, felipe.balbi, tony, daniel.stone

Hi Eduardo,

From: Eduardo Valentin <eduardo.valentin@indt.org.br>
Subject: Re: [PATCH 1/2] CLK: Introduce virtual clock registration
Date: Wed, 20 Aug 2008 15:10:08 -0400

> Hi Hiroshi,
> 
> On Wed, Aug 20, 2008 at 03:04:38PM +0300, Hiroshi DOYU wrote:
> > This patch provides the interface to register and unregister a virtual
> > clock which groups multiple clocks in it in order to handle this group
> > of clocks at once. Presently just clk_enable and clk_disable is
> > overwritten and other operation can be done as well.
> > 
> > This is just a refactor of MCBSP clock registration.
> 
> These two patches seams ok to me. I didn't expose it as
> a virtual clock API 'cause I didn't find any other place
> to use it other than mcbsp code.
> 
> Anyway, the code looks more manageble now. I'd just suggest
> a refactor of mach-omap1 files to be included into this series as well.

Right. I've updated the 2nd one as below:

>From 3f42b6463d840cdc0e832e84e96381d102f124f8 Mon Sep 17 00:00:00 2001
From: ext Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
Date: Wed, 20 Aug 2008 15:04:39 +0300
Subject: [PATCH 2/2] CLK: Use virtual clock register for mcbsp

Signed-off-by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
Acked-by: Eduardo Valentin <eduardo.valentin@indt.org.br>
---
 arch/arm/mach-omap1/mcbsp.c             |   74 +++--------------------------
 arch/arm/mach-omap2/mcbsp.c             |   79 +++----------------------------
 arch/arm/plat-omap/devices.c            |   34 +++++++++++++
 arch/arm/plat-omap/include/mach/mcbsp.h |    2 +
 4 files changed, 50 insertions(+), 139 deletions(-)

diff --git a/arch/arm/mach-omap1/mcbsp.c b/arch/arm/mach-omap1/mcbsp.c
index 265cfc2..39107e0 100644
--- a/arch/arm/mach-omap1/mcbsp.c
+++ b/arch/arm/mach-omap1/mcbsp.c
@@ -26,81 +26,23 @@
 #define DPS_RSTCT2_PER_EN	(1 << 0)
 #define DSP_RSTCT2_WD_PER_EN	(1 << 1)
 
-struct mcbsp_internal_clk {
-	struct clk clk;
-	struct clk **childs;
-	int n_childs;
-};
-
 #if defined(CONFIG_ARCH_OMAP15XX) || defined(CONFIG_ARCH_OMAP16XX)
-static void omap_mcbsp_clk_init(struct mcbsp_internal_clk *mclk)
-{
-	const char *clk_names[] = { "dsp_ck", "api_ck", "dspxor_ck" };
-	int i;
-
-	mclk->n_childs = ARRAY_SIZE(clk_names);
-	mclk->childs = kzalloc(mclk->n_childs * sizeof(struct clk *),
-				GFP_KERNEL);
-
-	for (i = 0; i < mclk->n_childs; i++) {
-		/* We fake a platform device to get correct device id */
-		struct platform_device pdev;
-
-		pdev.dev.bus = &platform_bus_type;
-		pdev.id = mclk->clk.id;
-		mclk->childs[i] = clk_get(&pdev.dev, clk_names[i]);
-		if (IS_ERR(mclk->childs[i]))
-			printk(KERN_ERR "Could not get clock %s (%d).\n",
-				clk_names[i], mclk->clk.id);
-	}
-}
-
-static int omap_mcbsp_clk_enable(struct clk *clk)
-{
-	struct mcbsp_internal_clk *mclk = container_of(clk,
-					struct mcbsp_internal_clk, clk);
-	int i;
-
-	for (i = 0; i < mclk->n_childs; i++)
-		clk_enable(mclk->childs[i]);
-	return 0;
-}
-
-static void omap_mcbsp_clk_disable(struct clk *clk)
-{
-	struct mcbsp_internal_clk *mclk = container_of(clk,
-					struct mcbsp_internal_clk, clk);
-	int i;
-
-	for (i = 0; i < mclk->n_childs; i++)
-		clk_disable(mclk->childs[i]);
-}
-
-static struct mcbsp_internal_clk omap_mcbsp_clks[] = {
+static struct vclk omap_mcbsp_clks[] = {
 	{
 		.clk = {
 			.name 		= "mcbsp_clk",
 			.id		= 1,
-			.enable		= omap_mcbsp_clk_enable,
-			.disable	= omap_mcbsp_clk_disable,
 		},
 	},
 	{
 		.clk = {
 			.name 		= "mcbsp_clk",
 			.id		= 3,
-			.enable		= omap_mcbsp_clk_enable,
-			.disable	= omap_mcbsp_clk_disable,
 		},
 	},
 };
-
-#define omap_mcbsp_clks_size	ARRAY_SIZE(omap_mcbsp_clks)
 #else
-#define omap_mcbsp_clks_size	0
-static struct mcbsp_internal_clk __initdata *omap_mcbsp_clks;
-static inline void omap_mcbsp_clk_init(struct mcbsp_internal_clk *mclk)
-{ }
+static struct vclk __initdata *omap_mcbsp_clks;
 #endif
 
 static void omap1_mcbsp_request(unsigned int id)
@@ -228,14 +170,12 @@ static struct omap_mcbsp_platform_data omap16xx_mcbsp_pdata[] = {
 
 int __init omap1_mcbsp_init(void)
 {
-	int i;
+	int err;
 
-	for (i = 0; i < omap_mcbsp_clks_size; i++) {
-		if (cpu_is_omap15xx() || cpu_is_omap16xx()) {
-			omap_mcbsp_clk_init(&omap_mcbsp_clks[i]);
-			clk_register(&omap_mcbsp_clks[i].clk);
-		}
-	}
+	err = omap_mcbsp_register_clk(omap_mcbsp_clks,
+				      ARRAY_SIZE(omap_mcbsp_clks));
+	if (err)
+		return err;
 
 	if (cpu_is_omap730())
 		omap_mcbsp_count = OMAP730_MCBSP_PDATA_SZ;
diff --git a/arch/arm/mach-omap2/mcbsp.c b/arch/arm/mach-omap2/mcbsp.c
index cedb9a6..80704ac 100644
--- a/arch/arm/mach-omap2/mcbsp.c
+++ b/arch/arm/mach-omap2/mcbsp.c
@@ -22,105 +22,41 @@
 #include <mach/cpu.h>
 #include <mach/mcbsp.h>
 
-struct mcbsp_internal_clk {
-	struct clk clk;
-	struct clk **childs;
-	int n_childs;
-};
-
 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
-static void omap_mcbsp_clk_init(struct mcbsp_internal_clk *mclk)
-{
-	const char *clk_names[] = { "mcbsp_ick", "mcbsp_fck" };
-	int i;
-
-	mclk->n_childs = ARRAY_SIZE(clk_names);
-	mclk->childs = kzalloc(mclk->n_childs * sizeof(struct clk *),
-				GFP_KERNEL);
-
-	for (i = 0; i < mclk->n_childs; i++) {
-		/* We fake a platform device to get correct device id */
-		struct platform_device pdev;
-
-		pdev.dev.bus = &platform_bus_type;
-		pdev.id = mclk->clk.id;
-		mclk->childs[i] = clk_get(&pdev.dev, clk_names[i]);
-		if (IS_ERR(mclk->childs[i]))
-			printk(KERN_ERR "Could not get clock %s (%d).\n",
-				clk_names[i], mclk->clk.id);
-	}
-}
-
-static int omap_mcbsp_clk_enable(struct clk *clk)
-{
-	struct mcbsp_internal_clk *mclk = container_of(clk,
-					struct mcbsp_internal_clk, clk);
-	int i;
-
-	for (i = 0; i < mclk->n_childs; i++)
-		clk_enable(mclk->childs[i]);
-	return 0;
-}
-
-static void omap_mcbsp_clk_disable(struct clk *clk)
-{
-	struct mcbsp_internal_clk *mclk = container_of(clk,
-					struct mcbsp_internal_clk, clk);
-	int i;
-
-	for (i = 0; i < mclk->n_childs; i++)
-		clk_disable(mclk->childs[i]);
-}
-
-static struct mcbsp_internal_clk omap_mcbsp_clks[] = {
+static struct vclk omap_mcbsp_clks[] = {
 	{
 		.clk = {
 			.name 		= "mcbsp_clk",
 			.id		= 1,
-			.enable		= omap_mcbsp_clk_enable,
-			.disable	= omap_mcbsp_clk_disable,
 		},
 	},
 	{
 		.clk = {
 			.name 		= "mcbsp_clk",
 			.id		= 2,
-			.enable		= omap_mcbsp_clk_enable,
-			.disable	= omap_mcbsp_clk_disable,
 		},
 	},
 	{
 		.clk = {
 			.name		= "mcbsp_clk",
 			.id		= 3,
-			.enable		= omap_mcbsp_clk_enable,
-			.disable	= omap_mcbsp_clk_disable,
 		},
 	},
 	{
 		.clk = {
 			.name		= "mcbsp_clk",
 			.id		= 4,
-			.enable		= omap_mcbsp_clk_enable,
-			.disable	= omap_mcbsp_clk_disable,
 		},
 	},
 	{
 		.clk = {
 			.name		= "mcbsp_clk",
 			.id		= 5,
-			.enable		= omap_mcbsp_clk_enable,
-			.disable	= omap_mcbsp_clk_disable,
 		},
 	},
 };
-
-#define omap_mcbsp_clks_size	ARRAY_SIZE(omap_mcbsp_clks)
 #else
-#define omap_mcbsp_clks_size	0
-static struct mcbsp_internal_clk __initdata *omap_mcbsp_clks;
-static inline void omap_mcbsp_clk_init(struct clk *clk)
-{ }
+static struct vclk __initdata *omap_mcbsp_clks;
 #endif
 
 static void omap2_mcbsp2_mux_setup(void)
@@ -222,13 +158,12 @@ static struct omap_mcbsp_platform_data omap34xx_mcbsp_pdata[] = {
 
 static int __init omap2_mcbsp_init(void)
 {
-	int i;
+	int err;
 
-	for (i = 0; i < omap_mcbsp_clks_size; i++) {
-		/* Once we call clk_get inside init, we do not register it */
-		omap_mcbsp_clk_init(&omap_mcbsp_clks[i]);
-		clk_register(&omap_mcbsp_clks[i].clk);
-	}
+	err = omap_mcbsp_register_clk(omap_mcbsp_clks,
+				      ARRAY_SIZE(omap_mcbsp_clks));
+	if (err)
+		return err;
 
 	if (cpu_is_omap24xx())
 		omap_mcbsp_count = OMAP24XX_MCBSP_PDATA_SZ;
diff --git a/arch/arm/plat-omap/devices.c b/arch/arm/plat-omap/devices.c
index f22ccbb..f194e2d 100644
--- a/arch/arm/plat-omap/devices.c
+++ b/arch/arm/plat-omap/devices.c
@@ -155,6 +155,40 @@ static inline void omap_init_kp(void) {}
 
 static struct platform_device **omap_mcbsp_devices;
 
+/* Machine dependent virtual clock registration */
+int omap_mcbsp_register_clk(struct vclk *vclks, int n)
+{
+	int i, err;
+	struct vclk *p;
+	struct vclk_cci cci[] = {
+		{
+			.name = "mcbsp_ick",
+		},
+		{
+			.name = "mcbsp_fck",
+		},
+	};
+
+	if (!vclks)
+		return 0;
+
+	p = vclks;
+	for (i = 0; i < n; i++, p++) {
+		int j;
+		for (j = 0; j < ARRAY_SIZE(cci); j++)
+			cci[j].id = p->clk.id;
+		err = vclk_register(p, cci, ARRAY_SIZE(cci));
+		if (err)
+			goto err_out;
+	}
+	return 0;
+err_out:
+	while (--i >= 0)
+		vclk_unregister(&vclks[i]);
+	return err;
+}
+EXPORT_SYMBOL(omap_mcbsp_register_clk);
+
 void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
 					int size)
 {
diff --git a/arch/arm/plat-omap/include/mach/mcbsp.h b/arch/arm/plat-omap/include/mach/mcbsp.h
index c04bcd5..20128cb 100644
--- a/arch/arm/plat-omap/include/mach/mcbsp.h
+++ b/arch/arm/plat-omap/include/mach/mcbsp.h
@@ -369,6 +369,8 @@ extern int omap_mcbsp_count;
 int omap_mcbsp_init(void);
 void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
 					int size);
+int omap_mcbsp_register_clk(struct vclk *vclks, int n);
+
 void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg * config);
 int omap_mcbsp_request(unsigned int id);
 void omap_mcbsp_free(unsigned int id);
-- 
1.5.5.1.357.g1af8b


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-08-21  9:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-20  9:51 [PATCH 1/2] CLK: Introduce virtual clock registration Hiroshi DOYU
2008-08-20  9:51 ` [PATCH 2/2] CLK: Use virtual clock register for mcbsp clock Hiroshi DOYU
2008-08-20 10:04 ` [PATCH 1/2] CLK: Introduce virtual clock registration Daniel Stone
2008-08-20 11:15   ` Hiroshi DOYU
2008-08-20 10:18 ` Felipe Balbi
2008-08-20 11:54   ` Tony Lindgren
  -- strict thread matches above, loose matches on Subject: below --
2008-08-20 12:04 Hiroshi DOYU
2008-08-20 19:10 ` Eduardo Valentin
2008-08-21  9:57   ` Hiroshi DOYU

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox