linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] regulator: qcom_spmi: Improve readability for setting up enable/mode pin control
@ 2020-08-01  5:48 Axel Lin
  2020-08-01  6:12 ` Bjorn Andersson
  2020-08-18 16:56 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Axel Lin @ 2020-08-01  5:48 UTC (permalink / raw)
  To: Mark Brown
  Cc: Andy Gross, Bjorn Andersson, Angelo G . Del Regno, Liam Girdwood,
	linux-kernel, Axel Lin

By checking data->pin_ctrl_enable / data->pin_ctrl_hpm flags first, then
use switch-case to improve readability.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/regulator/qcom_spmi-regulator.c | 70 ++++++++++++-------------
 1 file changed, 34 insertions(+), 36 deletions(-)

diff --git a/drivers/regulator/qcom_spmi-regulator.c b/drivers/regulator/qcom_spmi-regulator.c
index 5ee7c5305d95..05080483fe1b 100644
--- a/drivers/regulator/qcom_spmi-regulator.c
+++ b/drivers/regulator/qcom_spmi-regulator.c
@@ -1633,45 +1633,43 @@ static int spmi_regulator_init_registers(struct spmi_regulator *vreg,
 		return ret;
 
 	/* Set up enable pin control. */
-	if ((type == SPMI_REGULATOR_LOGICAL_TYPE_SMPS
-	     || type == SPMI_REGULATOR_LOGICAL_TYPE_LDO
-	     || type == SPMI_REGULATOR_LOGICAL_TYPE_VS)
-	    && !(data->pin_ctrl_enable
-			& SPMI_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT)) {
-		ctrl_reg[SPMI_COMMON_IDX_ENABLE] &=
-			~SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK;
-		ctrl_reg[SPMI_COMMON_IDX_ENABLE] |=
-		    data->pin_ctrl_enable & SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK;
+	if (!(data->pin_ctrl_enable & SPMI_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT)) {
+		switch (type) {
+		case SPMI_REGULATOR_LOGICAL_TYPE_SMPS:
+		case SPMI_REGULATOR_LOGICAL_TYPE_LDO:
+		case SPMI_REGULATOR_LOGICAL_TYPE_VS:
+			ctrl_reg[SPMI_COMMON_IDX_ENABLE] &=
+				~SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK;
+			ctrl_reg[SPMI_COMMON_IDX_ENABLE] |=
+				data->pin_ctrl_enable & SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK;
+			break;
+		default:
+			break;
+		}
 	}
 
 	/* Set up mode pin control. */
-	if ((type == SPMI_REGULATOR_LOGICAL_TYPE_SMPS
-	    || type == SPMI_REGULATOR_LOGICAL_TYPE_LDO)
-		&& !(data->pin_ctrl_hpm
-			& SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT)) {
-		ctrl_reg[SPMI_COMMON_IDX_MODE] &=
-			~SPMI_COMMON_MODE_FOLLOW_ALL_MASK;
-		ctrl_reg[SPMI_COMMON_IDX_MODE] |=
-			data->pin_ctrl_hpm & SPMI_COMMON_MODE_FOLLOW_ALL_MASK;
-	}
-
-	if (type == SPMI_REGULATOR_LOGICAL_TYPE_VS
-	   && !(data->pin_ctrl_hpm & SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT)) {
-		ctrl_reg[SPMI_COMMON_IDX_MODE] &=
-			~SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK;
-		ctrl_reg[SPMI_COMMON_IDX_MODE] |=
-		       data->pin_ctrl_hpm & SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK;
-	}
-
-	if ((type == SPMI_REGULATOR_LOGICAL_TYPE_ULT_LO_SMPS
-		|| type == SPMI_REGULATOR_LOGICAL_TYPE_ULT_HO_SMPS
-		|| type == SPMI_REGULATOR_LOGICAL_TYPE_ULT_LDO)
-		&& !(data->pin_ctrl_hpm
-			& SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT)) {
-		ctrl_reg[SPMI_COMMON_IDX_MODE] &=
-			~SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK;
-		ctrl_reg[SPMI_COMMON_IDX_MODE] |=
-		       data->pin_ctrl_hpm & SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK;
+	if (!(data->pin_ctrl_hpm & SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT)) {
+		switch (type) {
+		case SPMI_REGULATOR_LOGICAL_TYPE_SMPS:
+		case SPMI_REGULATOR_LOGICAL_TYPE_LDO:
+			ctrl_reg[SPMI_COMMON_IDX_MODE] &=
+				~SPMI_COMMON_MODE_FOLLOW_ALL_MASK;
+			ctrl_reg[SPMI_COMMON_IDX_MODE] |=
+				data->pin_ctrl_hpm & SPMI_COMMON_MODE_FOLLOW_ALL_MASK;
+			break;
+		case SPMI_REGULATOR_LOGICAL_TYPE_VS:
+		case SPMI_REGULATOR_LOGICAL_TYPE_ULT_LO_SMPS:
+		case SPMI_REGULATOR_LOGICAL_TYPE_ULT_HO_SMPS:
+		case SPMI_REGULATOR_LOGICAL_TYPE_ULT_LDO:
+			ctrl_reg[SPMI_COMMON_IDX_MODE] &=
+				~SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK;
+			ctrl_reg[SPMI_COMMON_IDX_MODE] |=
+				data->pin_ctrl_hpm & SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK;
+			break;
+		default:
+			break;
+		}
 	}
 
 	/* Write back any control register values that were modified. */
-- 
2.25.1


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

* Re: [PATCH] regulator: qcom_spmi: Improve readability for setting up enable/mode pin control
  2020-08-01  5:48 [PATCH] regulator: qcom_spmi: Improve readability for setting up enable/mode pin control Axel Lin
@ 2020-08-01  6:12 ` Bjorn Andersson
  2020-08-18 16:56 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Andersson @ 2020-08-01  6:12 UTC (permalink / raw)
  To: Axel Lin
  Cc: Mark Brown, Andy Gross, Angelo G . Del Regno, Liam Girdwood,
	linux-kernel

On Fri 31 Jul 22:48 PDT 2020, Axel Lin wrote:

> By checking data->pin_ctrl_enable / data->pin_ctrl_hpm flags first, then
> use switch-case to improve readability.
> 

Nice!

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---
>  drivers/regulator/qcom_spmi-regulator.c | 70 ++++++++++++-------------
>  1 file changed, 34 insertions(+), 36 deletions(-)
> 
> diff --git a/drivers/regulator/qcom_spmi-regulator.c b/drivers/regulator/qcom_spmi-regulator.c
> index 5ee7c5305d95..05080483fe1b 100644
> --- a/drivers/regulator/qcom_spmi-regulator.c
> +++ b/drivers/regulator/qcom_spmi-regulator.c
> @@ -1633,45 +1633,43 @@ static int spmi_regulator_init_registers(struct spmi_regulator *vreg,
>  		return ret;
>  
>  	/* Set up enable pin control. */
> -	if ((type == SPMI_REGULATOR_LOGICAL_TYPE_SMPS
> -	     || type == SPMI_REGULATOR_LOGICAL_TYPE_LDO
> -	     || type == SPMI_REGULATOR_LOGICAL_TYPE_VS)
> -	    && !(data->pin_ctrl_enable
> -			& SPMI_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT)) {
> -		ctrl_reg[SPMI_COMMON_IDX_ENABLE] &=
> -			~SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK;
> -		ctrl_reg[SPMI_COMMON_IDX_ENABLE] |=
> -		    data->pin_ctrl_enable & SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK;
> +	if (!(data->pin_ctrl_enable & SPMI_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT)) {
> +		switch (type) {
> +		case SPMI_REGULATOR_LOGICAL_TYPE_SMPS:
> +		case SPMI_REGULATOR_LOGICAL_TYPE_LDO:
> +		case SPMI_REGULATOR_LOGICAL_TYPE_VS:
> +			ctrl_reg[SPMI_COMMON_IDX_ENABLE] &=
> +				~SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK;
> +			ctrl_reg[SPMI_COMMON_IDX_ENABLE] |=
> +				data->pin_ctrl_enable & SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK;
> +			break;
> +		default:
> +			break;
> +		}
>  	}
>  
>  	/* Set up mode pin control. */
> -	if ((type == SPMI_REGULATOR_LOGICAL_TYPE_SMPS
> -	    || type == SPMI_REGULATOR_LOGICAL_TYPE_LDO)
> -		&& !(data->pin_ctrl_hpm
> -			& SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT)) {
> -		ctrl_reg[SPMI_COMMON_IDX_MODE] &=
> -			~SPMI_COMMON_MODE_FOLLOW_ALL_MASK;
> -		ctrl_reg[SPMI_COMMON_IDX_MODE] |=
> -			data->pin_ctrl_hpm & SPMI_COMMON_MODE_FOLLOW_ALL_MASK;
> -	}
> -
> -	if (type == SPMI_REGULATOR_LOGICAL_TYPE_VS
> -	   && !(data->pin_ctrl_hpm & SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT)) {
> -		ctrl_reg[SPMI_COMMON_IDX_MODE] &=
> -			~SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK;
> -		ctrl_reg[SPMI_COMMON_IDX_MODE] |=
> -		       data->pin_ctrl_hpm & SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK;
> -	}
> -
> -	if ((type == SPMI_REGULATOR_LOGICAL_TYPE_ULT_LO_SMPS
> -		|| type == SPMI_REGULATOR_LOGICAL_TYPE_ULT_HO_SMPS
> -		|| type == SPMI_REGULATOR_LOGICAL_TYPE_ULT_LDO)
> -		&& !(data->pin_ctrl_hpm
> -			& SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT)) {
> -		ctrl_reg[SPMI_COMMON_IDX_MODE] &=
> -			~SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK;
> -		ctrl_reg[SPMI_COMMON_IDX_MODE] |=
> -		       data->pin_ctrl_hpm & SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK;
> +	if (!(data->pin_ctrl_hpm & SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT)) {
> +		switch (type) {
> +		case SPMI_REGULATOR_LOGICAL_TYPE_SMPS:
> +		case SPMI_REGULATOR_LOGICAL_TYPE_LDO:
> +			ctrl_reg[SPMI_COMMON_IDX_MODE] &=
> +				~SPMI_COMMON_MODE_FOLLOW_ALL_MASK;
> +			ctrl_reg[SPMI_COMMON_IDX_MODE] |=
> +				data->pin_ctrl_hpm & SPMI_COMMON_MODE_FOLLOW_ALL_MASK;
> +			break;
> +		case SPMI_REGULATOR_LOGICAL_TYPE_VS:
> +		case SPMI_REGULATOR_LOGICAL_TYPE_ULT_LO_SMPS:
> +		case SPMI_REGULATOR_LOGICAL_TYPE_ULT_HO_SMPS:
> +		case SPMI_REGULATOR_LOGICAL_TYPE_ULT_LDO:
> +			ctrl_reg[SPMI_COMMON_IDX_MODE] &=
> +				~SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK;
> +			ctrl_reg[SPMI_COMMON_IDX_MODE] |=
> +				data->pin_ctrl_hpm & SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK;
> +			break;
> +		default:
> +			break;
> +		}
>  	}
>  
>  	/* Write back any control register values that were modified. */
> -- 
> 2.25.1
> 

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

* Re: [PATCH] regulator: qcom_spmi: Improve readability for setting up enable/mode pin control
  2020-08-01  5:48 [PATCH] regulator: qcom_spmi: Improve readability for setting up enable/mode pin control Axel Lin
  2020-08-01  6:12 ` Bjorn Andersson
@ 2020-08-18 16:56 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2020-08-18 16:56 UTC (permalink / raw)
  To: Axel Lin
  Cc: Angelo G . Del Regno, Bjorn Andersson, Liam Girdwood,
	linux-kernel, Andy Gross

On Sat, 1 Aug 2020 13:48:20 +0800, Axel Lin wrote:
> By checking data->pin_ctrl_enable / data->pin_ctrl_hpm flags first, then
> use switch-case to improve readability.

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next

Thanks!

[1/1] regulator: qcom_spmi: Improve readability for setting up enable/mode pin control
      commit: 6a1fe83bf14b87fd8b02f391ea629f69624d9c34

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

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

end of thread, other threads:[~2020-08-18 16:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-01  5:48 [PATCH] regulator: qcom_spmi: Improve readability for setting up enable/mode pin control Axel Lin
2020-08-01  6:12 ` Bjorn Andersson
2020-08-18 16:56 ` 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).