power: replace magic numbers with macros
Replace magic numbers in buckval2votl() & buckvolt2val() with macros to help with clarity and correlate what the numbers correspond to in the TPS65219 datasheet. Signed-off-by: Shree Ramamoorthy <s-ramamoorthy@ti.com> Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
This commit is contained in:

committed by
Jaehoon Chung

parent
eda65fa42b
commit
7e261a05a5
@@ -72,12 +72,12 @@ static int tps65219_buck_enable(struct udevice *dev, int op, bool *enable)
|
|||||||
|
|
||||||
static int tps65219_buck_volt2val(int uV)
|
static int tps65219_buck_volt2val(int uV)
|
||||||
{
|
{
|
||||||
if (uV > TPS65219_BUCK_VOLT_MAX)
|
if (uV > TPS65219_BUCK_3V4)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
else if (uV >= 1400000)
|
else if (uV >= TPS65219_BUCK_1V4)
|
||||||
return (uV - 1400000) / 100000 + 0x20;
|
return (uV - TPS65219_BUCK_1V4) / TPS65219_VOLT_STEP_100MV + TPS65219_BUCK_REG_1V4;
|
||||||
else if (uV >= 600000)
|
else if (uV >= TPS65219_BUCK_0V6)
|
||||||
return (uV - 600000) / 25000 + 0x00;
|
return (uV - TPS65219_BUCK_0V6) / TPS65219_VOLT_STEP_25MV + TPS65219_BUCK_REG_0V6;
|
||||||
else
|
else
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@@ -86,12 +86,12 @@ static int tps65219_buck_val2volt(int val)
|
|||||||
{
|
{
|
||||||
if (val > TPS65219_VOLT_MASK)
|
if (val > TPS65219_VOLT_MASK)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
else if (val > 0x34)
|
else if (val > TPS65219_BUCK_REG_3V4)
|
||||||
return TPS65219_BUCK_VOLT_MAX;
|
return TPS65219_BUCK_3V4;
|
||||||
else if (val > 0x20)
|
else if (val > TPS65219_BUCK_REG_1V4)
|
||||||
return 1400000 + (val - 0x20) * 100000;
|
return TPS65219_BUCK_1V4 + (val - TPS65219_BUCK_REG_1V4) * TPS65219_VOLT_STEP_100MV;
|
||||||
else if (val >= 0)
|
else if (val >= TPS65219_BUCK_REG_0V6)
|
||||||
return 600000 + val * 25000;
|
return TPS65219_BUCK_0V6 + val * TPS65219_VOLT_STEP_25MV;
|
||||||
else
|
else
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@@ -161,7 +161,7 @@ static int tps65219_ldo_volt2val(int idx, int uV)
|
|||||||
if (uV > max)
|
if (uV > max)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
else if (uV >= base)
|
else if (uV >= base)
|
||||||
return (uV - TPS65219_LDO12_VOLT_MIN) / 50000;
|
return (uV - TPS65219_LDO12_VOLT_MIN) / TPS65219_VOLT_STEP_50MV;
|
||||||
else
|
else
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@@ -187,7 +187,7 @@ static int tps65219_ldo_val2volt(int idx, int val)
|
|||||||
else if (val <= reg_base)
|
else if (val <= reg_base)
|
||||||
return base;
|
return base;
|
||||||
else if (val >= 0)
|
else if (val >= 0)
|
||||||
return TPS65219_LDO12_VOLT_MIN + (50000 * val);
|
return TPS65219_LDO12_VOLT_MIN + (TPS65219_VOLT_STEP_50MV * val);
|
||||||
else
|
else
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@@ -17,10 +17,20 @@
|
|||||||
#define TPS65219_BUCK_DRIVER "tps65219_buck"
|
#define TPS65219_BUCK_DRIVER "tps65219_buck"
|
||||||
|
|
||||||
#define TPS65219_VOLT_MASK 0x3F
|
#define TPS65219_VOLT_MASK 0x3F
|
||||||
#define TPS65219_BUCK_VOLT_MAX 3400000
|
|
||||||
|
|
||||||
#define TPS65219_ENABLE_CTRL_REG 0x2
|
#define TPS65219_ENABLE_CTRL_REG 0x2
|
||||||
|
|
||||||
|
#define TPS65219_VOLT_STEP_25MV 25000
|
||||||
|
#define TPS65219_VOLT_STEP_50MV 50000
|
||||||
|
#define TPS65219_VOLT_STEP_100MV 100000
|
||||||
|
|
||||||
|
#define TPS65219_BUCK_0V6 600000
|
||||||
|
#define TPS65219_BUCK_1V4 1400000
|
||||||
|
#define TPS65219_BUCK_3V4 3400000
|
||||||
|
|
||||||
|
#define TPS65219_BUCK_REG_0V6 0x00
|
||||||
|
#define TPS65219_BUCK_REG_1V4 0x20
|
||||||
|
#define TPS65219_BUCK_REG_3V4 0x34
|
||||||
|
|
||||||
#define TPS65219_BUCK1_VOUT_REG 0xa
|
#define TPS65219_BUCK1_VOUT_REG 0xa
|
||||||
#define TPS65219_BUCK2_VOUT_REG 0x9
|
#define TPS65219_BUCK2_VOUT_REG 0x9
|
||||||
#define TPS65219_BUCK3_VOUT_REG 0x8
|
#define TPS65219_BUCK3_VOUT_REG 0x8
|
||||||
|
Reference in New Issue
Block a user