mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [RFC 1/3] clk: Remove unneded private "parent" fields
@ 2013-03-15  6:35 Alexander Shiyan
  2013-03-15  6:35 ` [RFC 2/3] clk: Using the "is_enabled" to determine the clock state Alexander Shiyan
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Alexander Shiyan @ 2013-03-15  6:35 UTC (permalink / raw)
  To: barebox


Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 drivers/clk/clk-divider-table.c |    4 +---
 drivers/clk/clk-divider.c       |    4 +---
 drivers/clk/clk-fixed-factor.c  |    4 +---
 drivers/clk/clk-gate.c          |    4 +---
 4 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/clk/clk-divider-table.c b/drivers/clk/clk-divider-table.c
index 204e24d..e75fb78 100644
--- a/drivers/clk/clk-divider-table.c
+++ b/drivers/clk/clk-divider-table.c
@@ -25,7 +25,6 @@ struct clk_divider_table {
 	u8 shift;
 	u8 width;
 	void __iomem *reg;
-	const char *parent;
 	const struct clk_div_table *table;
 	int table_size;
 	int max_div_index;
@@ -94,10 +93,9 @@ struct clk *clk_divider_table(const char *name,
 	div->shift = shift;
 	div->reg = reg;
 	div->width = width;
-	div->parent = parent;
 	div->clk.ops = &clk_divider_table_ops;
 	div->clk.name = name;
-	div->clk.parent_names = &div->parent;
+	div->clk.parent_names = &parent;
 	div->clk.num_parents = 1;
 	div->table = table;
 
diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
index 58a7ea5..012b960 100644
--- a/drivers/clk/clk-divider.c
+++ b/drivers/clk/clk-divider.c
@@ -25,7 +25,6 @@ struct clk_divider {
 	u8 shift;
 	u8 width;
 	void __iomem *reg;
-	const char *parent;
 };
 
 static int clk_divider_set_rate(struct clk *clk, unsigned long rate,
@@ -82,10 +81,9 @@ struct clk *clk_divider(const char *name, const char *parent,
 	div->shift = shift;
 	div->reg = reg;
 	div->width = width;
-	div->parent = parent;
 	div->clk.ops = &clk_divider_ops;
 	div->clk.name = name;
-	div->clk.parent_names = &div->parent;
+	div->clk.parent_names = &parent;
 	div->clk.num_parents = 1;
 
 	ret = clk_register(&div->clk);
diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c
index 52e7c16..a57984d 100644
--- a/drivers/clk/clk-fixed-factor.c
+++ b/drivers/clk/clk-fixed-factor.c
@@ -24,7 +24,6 @@ struct clk_fixed_factor {
 	struct clk clk;
 	int mult;
 	int div;
-	const char *parent;
 };
 
 static unsigned long clk_fixed_factor_recalc_rate(struct clk *clk,
@@ -47,10 +46,9 @@ struct clk *clk_fixed_factor(const char *name,
 
 	f->mult = mult;
 	f->div = div;
-	f->parent = parent;
 	f->clk.ops = &clk_fixed_factor_ops;
 	f->clk.name = name;
-	f->clk.parent_names = &f->parent;
+	f->clk.parent_names = &parent;
 	f->clk.num_parents = 1;
 
 	ret = clk_register(&f->clk);
diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c
index cf1bb1a..2dca11c 100644
--- a/drivers/clk/clk-gate.c
+++ b/drivers/clk/clk-gate.c
@@ -24,7 +24,6 @@ struct clk_gate {
 	struct clk clk;
 	void __iomem *reg;
 	int shift;
-	const char *parent;
 };
 
 static int clk_gate_enable(struct clk *clk)
@@ -60,12 +59,11 @@ struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
 	struct clk_gate *g = xzalloc(sizeof(*g));
 	int ret;
 
-	g->parent = parent;
 	g->reg = reg;
 	g->shift = shift;
 	g->clk.ops = &clk_gate_ops;
 	g->clk.name = name;
-	g->clk.parent_names = &g->parent;
+	g->clk.parent_names = &parent;
 	g->clk.num_parents = 1;
 
 	ret = clk_register(&g->clk);
-- 
1.7.3.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [RFC 2/3] clk: Using the "is_enabled" to determine the clock state
  2013-03-15  6:35 [RFC 1/3] clk: Remove unneded private "parent" fields Alexander Shiyan
@ 2013-03-15  6:35 ` Alexander Shiyan
  2013-03-15  8:52   ` Sascha Hauer
  2013-03-15  6:35 ` [RFC 3/3] clk: Add "is_enabled" callback for gated clocks Alexander Shiyan
  2013-03-15  8:29 ` [RFC 1/3] clk: Remove unneded private "parent" fields Sascha Hauer
  2 siblings, 1 reply; 6+ messages in thread
From: Alexander Shiyan @ 2013-03-15  6:35 UTC (permalink / raw)
  To: barebox


Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 drivers/clk/clk.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index cb94755..d5dbbd9 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -213,6 +213,8 @@ int clk_register(struct clk *clk)
 
 	if (clk->flags & CLK_ALWAYS_ENABLED) {
 		clk->enable_count = 1;
+	} else if (clk->ops->is_enabled) {
+		clk->enable_count = clk->ops->is_enabled(clk);
 	}
 
 	return 0;
-- 
1.7.3.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [RFC 3/3] clk: Add "is_enabled" callback for gated clocks
  2013-03-15  6:35 [RFC 1/3] clk: Remove unneded private "parent" fields Alexander Shiyan
  2013-03-15  6:35 ` [RFC 2/3] clk: Using the "is_enabled" to determine the clock state Alexander Shiyan
@ 2013-03-15  6:35 ` Alexander Shiyan
  2013-03-15  8:29 ` [RFC 1/3] clk: Remove unneded private "parent" fields Sascha Hauer
  2 siblings, 0 replies; 6+ messages in thread
From: Alexander Shiyan @ 2013-03-15  6:35 UTC (permalink / raw)
  To: barebox


Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 drivers/clk/clk-gate.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c
index 2dca11c..580720b 100644
--- a/drivers/clk/clk-gate.c
+++ b/drivers/clk/clk-gate.c
@@ -48,9 +48,17 @@ static void clk_gate_disable(struct clk *clk)
 	writel(val, g->reg);
 }
 
+static int clk_gate_is_enabled(struct clk *clk)
+{
+	struct clk_gate *g = container_of(clk, struct clk_gate, clk);
+
+	return !!(readl(g->reg) & (1 << g->shift));
+}
+
 struct clk_ops clk_gate_ops = {
 	.enable = clk_gate_enable,
 	.disable = clk_gate_disable,
+	.is_enabled = clk_gate_is_enabled,
 };
 
 struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
-- 
1.7.3.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [RFC 1/3] clk: Remove unneded private "parent" fields
  2013-03-15  6:35 [RFC 1/3] clk: Remove unneded private "parent" fields Alexander Shiyan
  2013-03-15  6:35 ` [RFC 2/3] clk: Using the "is_enabled" to determine the clock state Alexander Shiyan
  2013-03-15  6:35 ` [RFC 3/3] clk: Add "is_enabled" callback for gated clocks Alexander Shiyan
@ 2013-03-15  8:29 ` Sascha Hauer
  2013-03-15  8:48   ` Re[2]: " Alexander Shiyan
  2 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2013-03-15  8:29 UTC (permalink / raw)
  To: Alexander Shiyan; +Cc: barebox

On Fri, Mar 15, 2013 at 10:35:38AM +0400, Alexander Shiyan wrote:
> 
> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
> ---
>  drivers/clk/clk-divider-table.c |    4 +---
>  drivers/clk/clk-divider.c       |    4 +---
>  drivers/clk/clk-fixed-factor.c  |    4 +---
>  drivers/clk/clk-gate.c          |    4 +---
>  4 files changed, 4 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/clk/clk-divider-table.c b/drivers/clk/clk-divider-table.c
> index 204e24d..e75fb78 100644
> --- a/drivers/clk/clk-divider-table.c
> +++ b/drivers/clk/clk-divider-table.c
> @@ -25,7 +25,6 @@ struct clk_divider_table {
>  	u8 shift;
>  	u8 width;
>  	void __iomem *reg;
> -	const char *parent;
>  	const struct clk_div_table *table;
>  	int table_size;
>  	int max_div_index;
> @@ -94,10 +93,9 @@ struct clk *clk_divider_table(const char *name,
>  	div->shift = shift;
>  	div->reg = reg;
>  	div->width = width;
> -	div->parent = parent;
>  	div->clk.ops = &clk_divider_table_ops;
>  	div->clk.name = name;
> -	div->clk.parent_names = &div->parent;
> +	div->clk.parent_names = &parent;

You can't do that. You can assume that the string *name points to stays
valid, but the pointer itself might not stay valid when leaving this
function. parent_names is an array of pointers, with the divider it only
has one entry, but still you need to keep a pointer for it. This is what
div->parent is for.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re[2]: [RFC 1/3] clk: Remove unneded private "parent" fields
  2013-03-15  8:29 ` [RFC 1/3] clk: Remove unneded private "parent" fields Sascha Hauer
@ 2013-03-15  8:48   ` Alexander Shiyan
  0 siblings, 0 replies; 6+ messages in thread
From: Alexander Shiyan @ 2013-03-15  8:48 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

> On Fri, Mar 15, 2013 at 10:35:38AM +0400, Alexander Shiyan wrote:
> > 
> > Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
> > ---
> >  drivers/clk/clk-divider-table.c |    4 +---
> >  drivers/clk/clk-divider.c       |    4 +---
> >  drivers/clk/clk-fixed-factor.c  |    4 +---
> >  drivers/clk/clk-gate.c          |    4 +---
> >  4 files changed, 4 insertions(+), 12 deletions(-)
> > 
> > diff --git a/drivers/clk/clk-divider-table.c b/drivers/clk/clk-divider-table.c
> > index 204e24d..e75fb78 100644
> > --- a/drivers/clk/clk-divider-table.c
> > +++ b/drivers/clk/clk-divider-table.c
> > @@ -25,7 +25,6 @@ struct clk_divider_table {
> >  	u8 shift;
> >  	u8 width;
> >  	void __iomem *reg;
> > -	const char *parent;
> >  	const struct clk_div_table *table;
> >  	int table_size;
> >  	int max_div_index;
> > @@ -94,10 +93,9 @@ struct clk *clk_divider_table(const char *name,
> >  	div->shift = shift;
> >  	div->reg = reg;
> >  	div->width = width;
> > -	div->parent = parent;
> >  	div->clk.ops = &clk_divider_table_ops;
> >  	div->clk.name = name;
> > -	div->clk.parent_names = &div->parent;
> > +	div->clk.parent_names = &parent;
> 
> You can't do that. You can assume that the string *name points to stays
> valid, but the pointer itself might not stay valid when leaving this
> function. parent_names is an array of pointers, with the divider it only
> has one entry, but still you need to keep a pointer for it. This is what
> div->parent is for.

You are right. Thanks.

---
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [RFC 2/3] clk: Using the "is_enabled" to determine the clock state
  2013-03-15  6:35 ` [RFC 2/3] clk: Using the "is_enabled" to determine the clock state Alexander Shiyan
@ 2013-03-15  8:52   ` Sascha Hauer
  0 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2013-03-15  8:52 UTC (permalink / raw)
  To: Alexander Shiyan; +Cc: barebox

On Fri, Mar 15, 2013 at 10:35:39AM +0400, Alexander Shiyan wrote:
> 
> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
> ---
>  drivers/clk/clk.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index cb94755..d5dbbd9 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -213,6 +213,8 @@ int clk_register(struct clk *clk)
>  
>  	if (clk->flags & CLK_ALWAYS_ENABLED) {
>  		clk->enable_count = 1;
> +	} else if (clk->ops->is_enabled) {
> +		clk->enable_count = clk->ops->is_enabled(clk);
>  	}

No. The enable_count should be a pure software counter only which helps
us to keep track whether we can disable a clk on the next clk_disable or
whether there are still users left.

This reminds me that I created a similar patch for this a few days ago.
I'll send in a minute.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2013-03-15  8:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-15  6:35 [RFC 1/3] clk: Remove unneded private "parent" fields Alexander Shiyan
2013-03-15  6:35 ` [RFC 2/3] clk: Using the "is_enabled" to determine the clock state Alexander Shiyan
2013-03-15  8:52   ` Sascha Hauer
2013-03-15  6:35 ` [RFC 3/3] clk: Add "is_enabled" callback for gated clocks Alexander Shiyan
2013-03-15  8:29 ` [RFC 1/3] clk: Remove unneded private "parent" fields Sascha Hauer
2013-03-15  8:48   ` Re[2]: " Alexander Shiyan

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