linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: ti: divider: Add the table parsing to get the best divider value
@ 2016-12-02  9:05 Keerthy
  2017-01-25 10:37 ` Keerthy
  2017-01-27  0:03 ` Stephen Boyd
  0 siblings, 2 replies; 4+ messages in thread
From: Keerthy @ 2016-12-02  9:05 UTC (permalink / raw)
  To: t-kristo
  Cc: mturquette, sboyd, linux-omap, linux-clk, linux-kernel, j-keerthy

Currently the divider selection logic blindly divides the parent_rate
by the clk rate and gives the divider value for the divider clocks
which do not have the CLK_SET_RATE_PARENT flag set. Add the clk divider
table parsing to get the closest divider available in the table
provided via Device tree.

The code is pretty much taken from: drivers/clk/clk-divider.c.
and used here to fix up the best divider selection logic.

Signed-off-by: Keerthy <j-keerthy@ti.com>
Reported-by: Richard Woodruff <r-woodruff2@ti.com>
---
 drivers/clk/ti/divider.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/ti/divider.c b/drivers/clk/ti/divider.c
index b4e5de1..6bb8778 100644
--- a/drivers/clk/ti/divider.c
+++ b/drivers/clk/ti/divider.c
@@ -140,6 +140,35 @@ static bool _is_valid_div(struct clk_divider *divider, unsigned int div)
 	return true;
 }
 
+static int _div_round_up(const struct clk_div_table *table,
+			 unsigned long parent_rate, unsigned long rate)
+{
+	const struct clk_div_table *clkt;
+	int up = INT_MAX;
+	int div = DIV_ROUND_UP_ULL((u64)parent_rate, rate);
+
+	for (clkt = table; clkt->div; clkt++) {
+		if (clkt->div == div)
+			return clkt->div;
+		else if (clkt->div < div)
+			continue;
+
+		if ((clkt->div - div) < (up - div))
+			up = clkt->div;
+	}
+
+	return up;
+}
+
+static int _div_round(const struct clk_div_table *table,
+		      unsigned long parent_rate, unsigned long rate)
+{
+	if (!table)
+		return DIV_ROUND_UP(parent_rate, rate);
+
+	return _div_round_up(table, parent_rate, rate);
+}
+
 static int ti_clk_divider_bestdiv(struct clk_hw *hw, unsigned long rate,
 				  unsigned long *best_parent_rate)
 {
@@ -155,7 +184,7 @@ static int ti_clk_divider_bestdiv(struct clk_hw *hw, unsigned long rate,
 
 	if (!(clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT)) {
 		parent_rate = *best_parent_rate;
-		bestdiv = DIV_ROUND_UP(parent_rate, rate);
+		bestdiv = _div_round(divider->table, parent_rate, rate);
 		bestdiv = bestdiv == 0 ? 1 : bestdiv;
 		bestdiv = bestdiv > maxdiv ? maxdiv : bestdiv;
 		return bestdiv;
-- 
1.9.1

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

* Re: [PATCH] clk: ti: divider: Add the table parsing to get the best divider value
  2016-12-02  9:05 [PATCH] clk: ti: divider: Add the table parsing to get the best divider value Keerthy
@ 2017-01-25 10:37 ` Keerthy
  2017-01-25 13:05   ` Tero Kristo
  2017-01-27  0:03 ` Stephen Boyd
  1 sibling, 1 reply; 4+ messages in thread
From: Keerthy @ 2017-01-25 10:37 UTC (permalink / raw)
  To: t-kristo; +Cc: mturquette, sboyd, linux-omap, linux-clk, linux-kernel



On Friday 02 December 2016 02:35 PM, Keerthy wrote:
> Currently the divider selection logic blindly divides the parent_rate
> by the clk rate and gives the divider value for the divider clocks
> which do not have the CLK_SET_RATE_PARENT flag set. Add the clk divider
> table parsing to get the closest divider available in the table
> provided via Device tree.
>
> The code is pretty much taken from: drivers/clk/clk-divider.c.
> and used here to fix up the best divider selection logic.

A gentle ping on this patch. This applies cleanly on the next branch as 
on today. Let me know if this needs to be rebased.

- Keerthy

>
> Signed-off-by: Keerthy <j-keerthy@ti.com>
> Reported-by: Richard Woodruff <r-woodruff2@ti.com>
> ---
>  drivers/clk/ti/divider.c | 31 ++++++++++++++++++++++++++++++-
>  1 file changed, 30 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/clk/ti/divider.c b/drivers/clk/ti/divider.c
> index b4e5de1..6bb8778 100644
> --- a/drivers/clk/ti/divider.c
> +++ b/drivers/clk/ti/divider.c
> @@ -140,6 +140,35 @@ static bool _is_valid_div(struct clk_divider *divider, unsigned int div)
>  	return true;
>  }
>
> +static int _div_round_up(const struct clk_div_table *table,
> +			 unsigned long parent_rate, unsigned long rate)
> +{
> +	const struct clk_div_table *clkt;
> +	int up = INT_MAX;
> +	int div = DIV_ROUND_UP_ULL((u64)parent_rate, rate);
> +
> +	for (clkt = table; clkt->div; clkt++) {
> +		if (clkt->div == div)
> +			return clkt->div;
> +		else if (clkt->div < div)
> +			continue;
> +
> +		if ((clkt->div - div) < (up - div))
> +			up = clkt->div;
> +	}
> +
> +	return up;
> +}
> +
> +static int _div_round(const struct clk_div_table *table,
> +		      unsigned long parent_rate, unsigned long rate)
> +{
> +	if (!table)
> +		return DIV_ROUND_UP(parent_rate, rate);
> +
> +	return _div_round_up(table, parent_rate, rate);
> +}
> +
>  static int ti_clk_divider_bestdiv(struct clk_hw *hw, unsigned long rate,
>  				  unsigned long *best_parent_rate)
>  {
> @@ -155,7 +184,7 @@ static int ti_clk_divider_bestdiv(struct clk_hw *hw, unsigned long rate,
>
>  	if (!(clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT)) {
>  		parent_rate = *best_parent_rate;
> -		bestdiv = DIV_ROUND_UP(parent_rate, rate);
> +		bestdiv = _div_round(divider->table, parent_rate, rate);
>  		bestdiv = bestdiv == 0 ? 1 : bestdiv;
>  		bestdiv = bestdiv > maxdiv ? maxdiv : bestdiv;
>  		return bestdiv;
>

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

* Re: [PATCH] clk: ti: divider: Add the table parsing to get the best divider value
  2017-01-25 10:37 ` Keerthy
@ 2017-01-25 13:05   ` Tero Kristo
  0 siblings, 0 replies; 4+ messages in thread
From: Tero Kristo @ 2017-01-25 13:05 UTC (permalink / raw)
  To: Keerthy; +Cc: mturquette, sboyd, linux-omap, linux-clk, linux-kernel

On 25/01/17 12:37, Keerthy wrote:
>
>
> On Friday 02 December 2016 02:35 PM, Keerthy wrote:
>> Currently the divider selection logic blindly divides the parent_rate
>> by the clk rate and gives the divider value for the divider clocks
>> which do not have the CLK_SET_RATE_PARENT flag set. Add the clk divider
>> table parsing to get the closest divider available in the table
>> provided via Device tree.
>>
>> The code is pretty much taken from: drivers/clk/clk-divider.c.
>> and used here to fix up the best divider selection logic.
>
> A gentle ping on this patch. This applies cleanly on the next branch as
> on today. Let me know if this needs to be rebased.
>
> - Keerthy
>
>>
>> Signed-off-by: Keerthy <j-keerthy@ti.com>
>> Reported-by: Richard Woodruff <r-woodruff2@ti.com>

Acked-by: Tero Kristo <t-kristo@ti.com>

Stephen / Michael, can you pick this up?

-Tero

>> ---
>>  drivers/clk/ti/divider.c | 31 ++++++++++++++++++++++++++++++-
>>  1 file changed, 30 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/clk/ti/divider.c b/drivers/clk/ti/divider.c
>> index b4e5de1..6bb8778 100644
>> --- a/drivers/clk/ti/divider.c
>> +++ b/drivers/clk/ti/divider.c
>> @@ -140,6 +140,35 @@ static bool _is_valid_div(struct clk_divider
>> *divider, unsigned int div)
>>      return true;
>>  }
>>
>> +static int _div_round_up(const struct clk_div_table *table,
>> +             unsigned long parent_rate, unsigned long rate)
>> +{
>> +    const struct clk_div_table *clkt;
>> +    int up = INT_MAX;
>> +    int div = DIV_ROUND_UP_ULL((u64)parent_rate, rate);
>> +
>> +    for (clkt = table; clkt->div; clkt++) {
>> +        if (clkt->div == div)
>> +            return clkt->div;
>> +        else if (clkt->div < div)
>> +            continue;
>> +
>> +        if ((clkt->div - div) < (up - div))
>> +            up = clkt->div;
>> +    }
>> +
>> +    return up;
>> +}
>> +
>> +static int _div_round(const struct clk_div_table *table,
>> +              unsigned long parent_rate, unsigned long rate)
>> +{
>> +    if (!table)
>> +        return DIV_ROUND_UP(parent_rate, rate);
>> +
>> +    return _div_round_up(table, parent_rate, rate);
>> +}
>> +
>>  static int ti_clk_divider_bestdiv(struct clk_hw *hw, unsigned long rate,
>>                    unsigned long *best_parent_rate)
>>  {
>> @@ -155,7 +184,7 @@ static int ti_clk_divider_bestdiv(struct clk_hw
>> *hw, unsigned long rate,
>>
>>      if (!(clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT)) {
>>          parent_rate = *best_parent_rate;
>> -        bestdiv = DIV_ROUND_UP(parent_rate, rate);
>> +        bestdiv = _div_round(divider->table, parent_rate, rate);
>>          bestdiv = bestdiv == 0 ? 1 : bestdiv;
>>          bestdiv = bestdiv > maxdiv ? maxdiv : bestdiv;
>>          return bestdiv;
>>

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

* Re: [PATCH] clk: ti: divider: Add the table parsing to get the best divider value
  2016-12-02  9:05 [PATCH] clk: ti: divider: Add the table parsing to get the best divider value Keerthy
  2017-01-25 10:37 ` Keerthy
@ 2017-01-27  0:03 ` Stephen Boyd
  1 sibling, 0 replies; 4+ messages in thread
From: Stephen Boyd @ 2017-01-27  0:03 UTC (permalink / raw)
  To: Keerthy; +Cc: t-kristo, mturquette, linux-omap, linux-clk, linux-kernel

On 12/02, Keerthy wrote:
> Currently the divider selection logic blindly divides the parent_rate
> by the clk rate and gives the divider value for the divider clocks
> which do not have the CLK_SET_RATE_PARENT flag set. Add the clk divider
> table parsing to get the closest divider available in the table
> provided via Device tree.
> 
> The code is pretty much taken from: drivers/clk/clk-divider.c.
> and used here to fix up the best divider selection logic.
> 
> Signed-off-by: Keerthy <j-keerthy@ti.com>
> Reported-by: Richard Woodruff <r-woodruff2@ti.com>
> ---

Applied to clk-next

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

end of thread, other threads:[~2017-01-27  0:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-02  9:05 [PATCH] clk: ti: divider: Add the table parsing to get the best divider value Keerthy
2017-01-25 10:37 ` Keerthy
2017-01-25 13:05   ` Tero Kristo
2017-01-27  0:03 ` Stephen Boyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).