[U-Boot] [PATCH v5 3/6] power: as3722: fix ldo_get/set_enable for ldo index bigger than 7

Jaehoon Chung jh80.chung at samsung.com
Thu Apr 26 12:02:50 UTC 2018


On 04/26/2018 08:04 PM, Marcel Ziswiler wrote:
> From: Marcel Ziswiler <marcel.ziswiler at toradex.com>
> 
> Fix ldo_get_enable() and ldo_set_enable() functions for LDOs with an
> index > 7. Turns out there are actually two separate AS3722_LDO_CONTROL
> registers AS3722_LDO_CONTROL0 and AS3722_LDO_CONTROL1. Actually make use
> of both. While at it also actually use the enable parameter of the
> ldo_set_enable() function which now truly allows disabling as opposed to
> only enabling LDOs.
> 
> Signed-off-by: Marcel Ziswiler <marcel.ziswiler at toradex.com>
> 
> ---
> 
> Changes in v5: None
> Changes in v4: None
> Changes in v3: None
> Changes in v2:
> - New bug fix.
> 
>  drivers/power/regulator/as3722_regulator.c | 16 ++++++++++++++--
>  include/power/as3722.h                     |  3 ++-
>  2 files changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/power/regulator/as3722_regulator.c b/drivers/power/regulator/as3722_regulator.c
> index 3e1e6f1178..eb4c4651d7 100644
> --- a/drivers/power/regulator/as3722_regulator.c
> +++ b/drivers/power/regulator/as3722_regulator.c
> @@ -69,10 +69,16 @@ static int ldo_set_value(struct udevice *dev, int uvolt)
>  static int ldo_set_enable(struct udevice *dev, bool enable)
>  {
>  	struct udevice *pmic = dev_get_parent(dev);
> +	u8 ctrl_reg = AS3722_LDO_CONTROL0;
>  	int ldo = dev->driver_data;
>  	int ret;
>  
> -	ret = pmic_clrsetbits(pmic, AS3722_LDO_CONTROL, 0, 1 << ldo);
> +	if (ldo > 7) {

If you use the macro, it's more easier to maintain in future.
#define MAX_LDO_INDEX 7 ?

I don't know what means 7. So you can choose the meaningful name.

If you need to change from 7 to some value, you only need to change the MAX_LDO_INDEX value.

> +		ctrl_reg = AS3722_LDO_CONTROL1;
> +		ldo -= 8;
> +	}
> +
> +	ret = pmic_clrsetbits(pmic, ctrl_reg, !enable << ldo, enable << ldo);
>  	if (ret < 0) {
>  		debug("%s: failed to write LDO control register: %d", __func__,
>  		      ret);
> @@ -85,10 +91,16 @@ static int ldo_set_enable(struct udevice *dev, bool enable)
>  static int ldo_get_enable(struct udevice *dev)
>  {
>  	struct udevice *pmic = dev_get_parent(dev);
> +	u8 ctrl_reg = AS3722_LDO_CONTROL0;
>  	int ldo = dev->driver_data;
>  	int ret;
>  
> -	ret = pmic_reg_read(pmic, AS3722_LDO_CONTROL);
> +	if (ldo > 7) {
> +		ctrl_reg = AS3722_LDO_CONTROL1;
> +		ldo -= 8;
> +	}
> +
> +	ret = pmic_reg_read(pmic, ctrl_reg);
>  	if (ret < 0) {
>  		debug("%s: failed to read SD control register: %d", __func__,
>  		      ret);
> diff --git a/include/power/as3722.h b/include/power/as3722.h
> index cb4b188bcf..b3dc7b657a 100644
> --- a/include/power/as3722.h
> +++ b/include/power/as3722.h
> @@ -14,7 +14,8 @@
>  #define AS3722_SD_VOLTAGE(n) (0x00 + (n))
>  #define AS3722_LDO_VOLTAGE(n) (0x10 + (n))
>  #define AS3722_SD_CONTROL 0x4d
> -#define AS3722_LDO_CONTROL 0x4e
> +#define AS3722_LDO_CONTROL0 0x4e
> +#define AS3722_LDO_CONTROL1 0x4f
>  #define AS3722_ASIC_ID1 0x90
>  #define AS3722_ASIC_ID2 0x91
>  
> 



More information about the U-Boot mailing list