linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] regulator: palmas: Slightly code change for better readability
@ 2012-06-06 12:01 Axel Lin
  2012-06-06 14:43 ` Graeme Gregory
  2012-06-07 23:37 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Axel Lin @ 2012-06-06 12:01 UTC (permalink / raw)
  To: linux-kernel; +Cc: Graeme Gregory, Mark Brown, Liam Girdwood

It's a little bit hard to read that the "else" case means id == PALMAS_REG_SMPS10.

if (id != PALMAS_REG_SMPS10){
        do something for the cases id != PALMAS_REG_SMPS10;
} else {
        do something for the case id == PALMAS_REG_SMPS10;
}

This patch changes above syntax to switch statement.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 drivers/regulator/palmas-regulator.c |   28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index b4e10b0..112436b 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -517,7 +517,15 @@ static int palmas_smps_init(struct palmas *palmas, int id,
 	if (ret)
 		return ret;
 
-	if (id != PALMAS_REG_SMPS10) {
+	switch (id) {
+	case PALMAS_REG_SMPS10:
+		if (reg_init->mode_sleep) {
+			reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK;
+			reg |= reg_init->mode_sleep <<
+					PALMAS_SMPS10_CTRL_MODE_SLEEP_SHIFT;
+		}
+		break;
+	default:
 		if (reg_init->warm_reset)
 			reg |= PALMAS_SMPS12_CTRL_WR_S;
 
@@ -529,14 +537,8 @@ static int palmas_smps_init(struct palmas *palmas, int id,
 			reg |= reg_init->mode_sleep <<
 					PALMAS_SMPS12_CTRL_MODE_SLEEP_SHIFT;
 		}
-	} else {
-		if (reg_init->mode_sleep) {
-			reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK;
-			reg |= reg_init->mode_sleep <<
-					PALMAS_SMPS10_CTRL_MODE_SLEEP_SHIFT;
-		}
-
 	}
+
 	ret = palmas_smps_write(palmas, addr, reg);
 	if (ret)
 		return ret;
@@ -660,10 +662,8 @@ static __devinit int palmas_probe(struct platform_device *pdev)
 		pmic->desc[id].name = palmas_regs_info[id].name;
 		pmic->desc[id].id = id;
 
-		if (id != PALMAS_REG_SMPS10) {
-			pmic->desc[id].ops = &palmas_ops_smps;
-			pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES;
-		} else {
+		switch (id) {
+		case PALMAS_REG_SMPS10:
 			pmic->desc[id].n_voltages = PALMAS_SMPS10_NUM_VOLTAGES;
 			pmic->desc[id].ops = &palmas_ops_smps10;
 			pmic->desc[id].vsel_reg = PALMAS_SMPS10_CTRL;
@@ -672,6 +672,10 @@ static __devinit int palmas_probe(struct platform_device *pdev)
 			pmic->desc[id].enable_mask = SMPS10_BOOST_EN;
 			pmic->desc[id].min_uV = 3750000;
 			pmic->desc[id].uV_step = 1250000;
+			break;
+		default:
+			pmic->desc[id].ops = &palmas_ops_smps;
+			pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES;
 		}
 
 		pmic->desc[id].type = REGULATOR_VOLTAGE;
-- 
1.7.9.5




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

* Re: [PATCH v2] regulator: palmas: Slightly code change for better readability
  2012-06-06 12:01 [PATCH v2] regulator: palmas: Slightly code change for better readability Axel Lin
@ 2012-06-06 14:43 ` Graeme Gregory
  2012-06-07 23:37 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Graeme Gregory @ 2012-06-06 14:43 UTC (permalink / raw)
  To: Axel Lin; +Cc: linux-kernel, Mark Brown, Liam Girdwood

Acked-by: Graeme Gregory <gg@slimlogic.co.uk>

On 06/06/12 13:01, Axel Lin wrote:
> It's a little bit hard to read that the "else" case means id == PALMAS_REG_SMPS10.
>
> if (id != PALMAS_REG_SMPS10){
>         do something for the cases id != PALMAS_REG_SMPS10;
> } else {
>         do something for the case id == PALMAS_REG_SMPS10;
> }
>
> This patch changes above syntax to switch statement.
>
> Signed-off-by: Axel Lin <axel.lin@gmail.com>
> ---
>  drivers/regulator/palmas-regulator.c |   28 ++++++++++++++++------------
>  1 file changed, 16 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
> index b4e10b0..112436b 100644
> --- a/drivers/regulator/palmas-regulator.c
> +++ b/drivers/regulator/palmas-regulator.c
> @@ -517,7 +517,15 @@ static int palmas_smps_init(struct palmas *palmas, int id,
>  	if (ret)
>  		return ret;
>  
> -	if (id != PALMAS_REG_SMPS10) {
> +	switch (id) {
> +	case PALMAS_REG_SMPS10:
> +		if (reg_init->mode_sleep) {
> +			reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK;
> +			reg |= reg_init->mode_sleep <<
> +					PALMAS_SMPS10_CTRL_MODE_SLEEP_SHIFT;
> +		}
> +		break;
> +	default:
>  		if (reg_init->warm_reset)
>  			reg |= PALMAS_SMPS12_CTRL_WR_S;
>  
> @@ -529,14 +537,8 @@ static int palmas_smps_init(struct palmas *palmas, int id,
>  			reg |= reg_init->mode_sleep <<
>  					PALMAS_SMPS12_CTRL_MODE_SLEEP_SHIFT;
>  		}
> -	} else {
> -		if (reg_init->mode_sleep) {
> -			reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK;
> -			reg |= reg_init->mode_sleep <<
> -					PALMAS_SMPS10_CTRL_MODE_SLEEP_SHIFT;
> -		}
> -
>  	}
> +
>  	ret = palmas_smps_write(palmas, addr, reg);
>  	if (ret)
>  		return ret;
> @@ -660,10 +662,8 @@ static __devinit int palmas_probe(struct platform_device *pdev)
>  		pmic->desc[id].name = palmas_regs_info[id].name;
>  		pmic->desc[id].id = id;
>  
> -		if (id != PALMAS_REG_SMPS10) {
> -			pmic->desc[id].ops = &palmas_ops_smps;
> -			pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES;
> -		} else {
> +		switch (id) {
> +		case PALMAS_REG_SMPS10:
>  			pmic->desc[id].n_voltages = PALMAS_SMPS10_NUM_VOLTAGES;
>  			pmic->desc[id].ops = &palmas_ops_smps10;
>  			pmic->desc[id].vsel_reg = PALMAS_SMPS10_CTRL;
> @@ -672,6 +672,10 @@ static __devinit int palmas_probe(struct platform_device *pdev)
>  			pmic->desc[id].enable_mask = SMPS10_BOOST_EN;
>  			pmic->desc[id].min_uV = 3750000;
>  			pmic->desc[id].uV_step = 1250000;
> +			break;
> +		default:
> +			pmic->desc[id].ops = &palmas_ops_smps;
> +			pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES;
>  		}
>  
>  		pmic->desc[id].type = REGULATOR_VOLTAGE;


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

* Re: [PATCH v2] regulator: palmas: Slightly code change for better readability
  2012-06-06 12:01 [PATCH v2] regulator: palmas: Slightly code change for better readability Axel Lin
  2012-06-06 14:43 ` Graeme Gregory
@ 2012-06-07 23:37 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2012-06-07 23:37 UTC (permalink / raw)
  To: Axel Lin; +Cc: linux-kernel, Graeme Gregory, Liam Girdwood

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

On Wed, Jun 06, 2012 at 08:01:38PM +0800, Axel Lin wrote:
> It's a little bit hard to read that the "else" case means id == PALMAS_REG_SMPS10.

Applied, thanks.

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

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

end of thread, other threads:[~2012-06-08  0:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-06 12:01 [PATCH v2] regulator: palmas: Slightly code change for better readability Axel Lin
2012-06-06 14:43 ` Graeme Gregory
2012-06-07 23:37 ` Mark Brown

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).