diff mbox

[2/2] clk: si5351: Powerdown output when clock rate is 0.

Message ID 1367914491-17445-2-git-send-email-marek.belisko@streamunlimited.com (mailing list archive)
State New, archived
Headers show

Commit Message

Belisko Marek May 7, 2013, 8:14 a.m. UTC
When rate is 0 powerdown clock output.

Signed-off-by: Marek Belisko <marek.belisko@streamunlimited.com>
---
 drivers/clk/clk-si5351.c |   32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

Comments

Sebastian Hesselbarth May 7, 2013, 10:07 a.m. UTC | #1
On 05/07/2013 10:14 AM, Marek Belisko wrote:
> When rate is 0 powerdown clock output.
>
> Signed-off-by: Marek Belisko<marek.belisko@streamunlimited.com>
> ---
>   drivers/clk/clk-si5351.c |   32 +++++++++++++++++++-------------
>   1 file changed, 19 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/clk/clk-si5351.c b/drivers/clk/clk-si5351.c
> index a8fc0f4..e254e76 100644
> --- a/drivers/clk/clk-si5351.c
> +++ b/drivers/clk/clk-si5351.c
> @@ -1042,20 +1042,22 @@ static int si5351_clkout_set_rate(struct clk_hw *hw, unsigned long rate,
>   	struct si5351_hw_data *hwdata =
>   		container_of(hw, struct si5351_hw_data, hw);
>   	unsigned long new_rate, new_err, err;
> -	unsigned char rdiv;
> +	unsigned char rdiv, pdn = 0;
>
>   	/* round to closed rdiv */
>   	rdiv = SI5351_OUTPUT_CLK_DIV_1;
> -	new_rate = parent_rate;
> -	err = abs(new_rate - rate);
> -	do {
> -		new_rate>>= 1;
> -		new_err = abs(new_rate - rate);
> -		if (new_err>  err || rdiv == SI5351_OUTPUT_CLK_DIV_128)
> -			break;
> -		rdiv++;
> -		err = new_err;
> -	} while (1);
> +	if (rate) {
> +		new_rate = parent_rate;

Marek,

initalizing pdn to SI5351_CLK_POWERDOWN and skip (with goto) to 
powerup/down call on zero rate will save us a level of indention here.

> +		err = abs(new_rate - rate);
> +		do {
> +			new_rate>>= 1;
> +			new_err = abs(new_rate - rate);
> +			if (new_err>  err || rdiv == SI5351_OUTPUT_CLK_DIV_128)
> +				break;
> +			rdiv++;
> +			err = new_err;
> +		} while (1);

of course, pdn should be set to 0 here.

> +	}
>
>   	/* write output divider */
>   	switch (hwdata->num) {
> @@ -1075,9 +1077,13 @@ static int si5351_clkout_set_rate(struct clk_hw *hw, unsigned long rate,
>   				rdiv<<  SI5351_OUTPUT_CLK_DIV_SHIFT);
>   	}
>
> -	/* powerup clkout */
> +	/* when rate is 0 powerdown output */
> +	if (rate == 0)
> +		pdn = SI5351_CLK_POWERDOWN;
> +
> +	/* powerup/down clkout */
>   	si5351_set_bits(hwdata->drvdata, SI5351_CLK0_CTRL + hwdata->num,
> -			SI5351_CLK_POWERDOWN, 0);
> +			SI5351_CLK_POWERDOWN, pdn);
>
>   	dev_dbg(&hwdata->drvdata->client->dev,
>   		"%s - %s: rdiv = %u, parent_rate = %lu, rate = %lu\n",
Marek Belisko May 7, 2013, 10:40 a.m. UTC | #2
On 05/07/2013 12:07 PM, Sebastian Hesselbarth wrote:
> On 05/07/2013 10:14 AM, Marek Belisko wrote:
>> When rate is 0 powerdown clock output.
>>
>> Signed-off-by: Marek Belisko<marek.belisko@streamunlimited.com>
>> ---
>>   drivers/clk/clk-si5351.c |   32 +++++++++++++++++++-------------
>>   1 file changed, 19 insertions(+), 13 deletions(-)
>>
>> diff --git a/drivers/clk/clk-si5351.c b/drivers/clk/clk-si5351.c
>> index a8fc0f4..e254e76 100644
>> --- a/drivers/clk/clk-si5351.c
>> +++ b/drivers/clk/clk-si5351.c
>> @@ -1042,20 +1042,22 @@ static int si5351_clkout_set_rate(struct
>> clk_hw *hw, unsigned long rate,
>>       struct si5351_hw_data *hwdata =
>>           container_of(hw, struct si5351_hw_data, hw);
>>       unsigned long new_rate, new_err, err;
>> -    unsigned char rdiv;
>> +    unsigned char rdiv, pdn = 0;
>>
>>       /* round to closed rdiv */
>>       rdiv = SI5351_OUTPUT_CLK_DIV_1;
>> -    new_rate = parent_rate;
>> -    err = abs(new_rate - rate);
>> -    do {
>> -        new_rate>>= 1;
>> -        new_err = abs(new_rate - rate);
>> -        if (new_err>  err || rdiv == SI5351_OUTPUT_CLK_DIV_128)
>> -            break;
>> -        rdiv++;
>> -        err = new_err;
>> -    } while (1);
>> +    if (rate) {
>> +        new_rate = parent_rate;
>
> Marek,
>
> initalizing pdn to SI5351_CLK_POWERDOWN and skip (with goto) to
> powerup/down call on zero rate will save us a level of indention here.
OK will fix and resubmit in v2. Thanks.
>
>> +        err = abs(new_rate - rate);
>> +        do {
>> +            new_rate>>= 1;
>> +            new_err = abs(new_rate - rate);
>> +            if (new_err>  err || rdiv == SI5351_OUTPUT_CLK_DIV_128)
>> +                break;
>> +            rdiv++;
>> +            err = new_err;
>> +        } while (1);
>
> of course, pdn should be set to 0 here.
>
>> +    }
>>
>>       /* write output divider */
>>       switch (hwdata->num) {
>> @@ -1075,9 +1077,13 @@ static int si5351_clkout_set_rate(struct clk_hw
>> *hw, unsigned long rate,
>>                   rdiv<<  SI5351_OUTPUT_CLK_DIV_SHIFT);
>>       }
>>
>> -    /* powerup clkout */
>> +    /* when rate is 0 powerdown output */
>> +    if (rate == 0)
>> +        pdn = SI5351_CLK_POWERDOWN;
>> +
>> +    /* powerup/down clkout */
>>       si5351_set_bits(hwdata->drvdata, SI5351_CLK0_CTRL + hwdata->num,
>> -            SI5351_CLK_POWERDOWN, 0);
>> +            SI5351_CLK_POWERDOWN, pdn);
>>
>>       dev_dbg(&hwdata->drvdata->client->dev,
>>           "%s - %s: rdiv = %u, parent_rate = %lu, rate = %lu\n",
>
>

marek
diff mbox

Patch

diff --git a/drivers/clk/clk-si5351.c b/drivers/clk/clk-si5351.c
index a8fc0f4..e254e76 100644
--- a/drivers/clk/clk-si5351.c
+++ b/drivers/clk/clk-si5351.c
@@ -1042,20 +1042,22 @@  static int si5351_clkout_set_rate(struct clk_hw *hw, unsigned long rate,
 	struct si5351_hw_data *hwdata =
 		container_of(hw, struct si5351_hw_data, hw);
 	unsigned long new_rate, new_err, err;
-	unsigned char rdiv;
+	unsigned char rdiv, pdn = 0;
 
 	/* round to closed rdiv */
 	rdiv = SI5351_OUTPUT_CLK_DIV_1;
-	new_rate = parent_rate;
-	err = abs(new_rate - rate);
-	do {
-		new_rate >>= 1;
-		new_err = abs(new_rate - rate);
-		if (new_err > err || rdiv == SI5351_OUTPUT_CLK_DIV_128)
-			break;
-		rdiv++;
-		err = new_err;
-	} while (1);
+	if (rate) {
+		new_rate = parent_rate;
+		err = abs(new_rate - rate);
+		do {
+			new_rate >>= 1;
+			new_err = abs(new_rate - rate);
+			if (new_err > err || rdiv == SI5351_OUTPUT_CLK_DIV_128)
+				break;
+			rdiv++;
+			err = new_err;
+		} while (1);
+	}
 
 	/* write output divider */
 	switch (hwdata->num) {
@@ -1075,9 +1077,13 @@  static int si5351_clkout_set_rate(struct clk_hw *hw, unsigned long rate,
 				rdiv << SI5351_OUTPUT_CLK_DIV_SHIFT);
 	}
 
-	/* powerup clkout */
+	/* when rate is 0 powerdown output */
+	if (rate == 0)
+		pdn = SI5351_CLK_POWERDOWN;
+
+	/* powerup/down clkout */
 	si5351_set_bits(hwdata->drvdata, SI5351_CLK0_CTRL + hwdata->num,
-			SI5351_CLK_POWERDOWN, 0);
+			SI5351_CLK_POWERDOWN, pdn);
 
 	dev_dbg(&hwdata->drvdata->client->dev,
 		"%s - %s: rdiv = %u, parent_rate = %lu, rate = %lu\n",