Re: [RESEND PATCH v3 5/5] power: regulator: tps65941: Add TPS65224 PMIC regulator support
On Thu, 18 Apr 2024 09:33:30 +0900, Jaehoon Chung wrote: > On 3/18/24 18:49, Bhargav Raviprakash wrote: > > Reuse TPS65941 regulator driver to adds support for > > TPS65224 PMIC's regulators. 4 BUCKs and 3 LDOs, where > > BUCK1 and BUCK2 can be configured in dual phase mode. > > > > Signed-off-by: Bhargav Raviprakash > > --- > > drivers/power/regulator/tps65941_regulator.c | 283 ++- > > 1 file changed, 270 insertions(+), 13 deletions(-) > > > > diff --git a/drivers/power/regulator/tps65941_regulator.c > > b/drivers/power/regulator/tps65941_regulator.c > > index d879c2301b..b1b9462fd3 100644 > > --- a/drivers/power/regulator/tps65941_regulator.c > > +++ b/drivers/power/regulator/tps65941_regulator.c > > @@ -37,6 +37,8 @@ > > > > #define TPS65941_BUCK_CONV_OPS_IDX 0 > > #define TPS65941_LDO_CONV_OPS_IDX 0 > > +#define TPS65224_LDO_CONV_OPS_IDX 1 > > +#define TPS65224_BUCK_CONV_OPS_IDX 1 > > > > struct tps65941_reg_conv_ops { > > int volt_mask; > > @@ -55,6 +57,11 @@ static const char tps65941_ldo_ctrl[TPS65941_BUCK_NUM] = > > {0x1D, 0x1E, 0x1F, > > static const char tps65941_ldo_vout[TPS65941_BUCK_NUM] = {0x23, 0x24, 0x25, > > 0x26}; > > > > +static inline int tps65941_get_chip_id(struct udevice *dev) > > +{ > > + return dev->parent->driver_data; > > +} > > + > > static int tps65941_buck_enable(struct udevice *dev, int op, bool *enable) > > { > > int ret; > > @@ -146,6 +153,112 @@ int tps65941_lookup_slew(int id) > > } > > } > > > > +static int tps65224_buck_volt2val(int idx, int uV) > > +{ > > + /* This functions maps a value which is in micro Volts to the VSET > > value. > > +* The mapping is as per the datasheet of TPS65224. > > +*/ > > + > > + if (uV > TPS65224_BUCK_VOLT_MAX) > > + return -EINVAL; > > + > > + if (idx > 0) { > > + /* Buck2, Buck3 and Buck4 of TPS65224 has a different schema in > > +* converting b/w micro_volt and VSET hex values > > +* > > +* VSET value starts from 0x00 for 0.5V, and for every increment > > +* in VSET value the output voltage increases by 25mV. This is > > upto > > +* 1.15V where VSET is 0x1A. > > +* > > +* For 0x1B the output voltage is 1.2V, and for every increment > > of > > +* VSET the output voltage increases by 50mV upto the max > > voltage of > > +* 3.3V > > +* > > +* | Voltage Ranges | VSET Ranges | Voltage Step | > > +* +-+--+--+ > > +* | 0.5V to 1.50V | 0x00 to 0x1A | 25mV| > > +* | 1.2V to 3.3V| 0x1B to 0x45 | 50mV| > > +*/ > > + if (uV >= 120) > > + return (uV - 120) / 5 + 0x1B; > > + else if (uV >= 50) > > + return (uV - 50) / 25000; > > + else > > + return -EINVAL; > > + } > > + > > + /* Buck1 and Buck12(dual phase) has a different mapping b/w output > > +* voltage and VSET value. > > +* > > +* | Voltage Ranges | VSET Ranges | Voltage Step | > > +* +-+--+--+ > > +* | 0.5V to 0.58V | 0xA to 0xE | 20mV| > > +* | 0.6V to 1.095V | 0xF to 0x72 | 5mV | > > +* | 1.1V to 1.65V | 0x73 to 0xAA | 10mV| > > +* | 1.6V to 3.3V| 0xAB to 0xFD | 20mV| > > +* > > +*/ > > + if (uV >= 166) > > + return (uV - 166) / 2 + 0xAB; > > + else if (uV >= 110) > > + return (uV - 110) / 1 + 0x73; > > + else if (uV >= 60) > > + return (uV - 60) / 5000 + 0x0F; > > + else if (uV >= 50) > > + return (uV - 50) / 2 + 0x0A; > > + else > > + return -EINVAL; > > +} > > + > > +static int tps65224_buck_val2volt(int idx, int val) > > +{ > > + /* This function does the opposite to the tps65224_buck_volt2val > > function > > +* described above. > > +* This maps the VSET value to micro volts. Please refer to the ranges > > +* mentioned the comments of tps65224_buck_volt2val. > > +*/ > > + > > + if (idx > 0) { > > + if (val > TPS65224_BUCK234_VOLT_MAX_HEX) > > + return -EINVAL; > > + else if (val >= 0x1B) > > + return 120 + (val - 0x1B) * 5; > > + else if (val >= 0x00) > > + return 50 + (val - 0x00) * 25000; > > + else > > + return -EINVAL; > > + } > > + > > + if (val > TPS65224_BUCK1_VOLT_MAX_HEX) > > + return -EINVAL; > > + else if (val >= 0xAB) > > + return 166 + (val - 0xAB) * 2; > > + else if (val >= 0x73) > > + return 110 + (val - 0x73) * 1; > > + else if (val >= 0xF) >
Re: [RESEND PATCH v3 5/5] power: regulator: tps65941: Add TPS65224 PMIC regulator support
On 3/18/24 18:49, Bhargav Raviprakash wrote: > Reuse TPS65941 regulator driver to adds support for > TPS65224 PMIC's regulators. 4 BUCKs and 3 LDOs, where > BUCK1 and BUCK2 can be configured in dual phase mode. > > Signed-off-by: Bhargav Raviprakash > --- > drivers/power/regulator/tps65941_regulator.c | 283 ++- > 1 file changed, 270 insertions(+), 13 deletions(-) > > diff --git a/drivers/power/regulator/tps65941_regulator.c > b/drivers/power/regulator/tps65941_regulator.c > index d879c2301b..b1b9462fd3 100644 > --- a/drivers/power/regulator/tps65941_regulator.c > +++ b/drivers/power/regulator/tps65941_regulator.c > @@ -37,6 +37,8 @@ > > #define TPS65941_BUCK_CONV_OPS_IDX 0 > #define TPS65941_LDO_CONV_OPS_IDX 0 > +#define TPS65224_LDO_CONV_OPS_IDX 1 > +#define TPS65224_BUCK_CONV_OPS_IDX 1 > > struct tps65941_reg_conv_ops { > int volt_mask; > @@ -55,6 +57,11 @@ static const char tps65941_ldo_ctrl[TPS65941_BUCK_NUM] = > {0x1D, 0x1E, 0x1F, > static const char tps65941_ldo_vout[TPS65941_BUCK_NUM] = {0x23, 0x24, 0x25, > 0x26}; > > +static inline int tps65941_get_chip_id(struct udevice *dev) > +{ > + return dev->parent->driver_data; > +} > + > static int tps65941_buck_enable(struct udevice *dev, int op, bool *enable) > { > int ret; > @@ -146,6 +153,112 @@ int tps65941_lookup_slew(int id) > } > } > > +static int tps65224_buck_volt2val(int idx, int uV) > +{ > + /* This functions maps a value which is in micro Volts to the VSET > value. > + * The mapping is as per the datasheet of TPS65224. > + */ > + > + if (uV > TPS65224_BUCK_VOLT_MAX) > + return -EINVAL; > + > + if (idx > 0) { > + /* Buck2, Buck3 and Buck4 of TPS65224 has a different schema in > + * converting b/w micro_volt and VSET hex values > + * > + * VSET value starts from 0x00 for 0.5V, and for every increment > + * in VSET value the output voltage increases by 25mV. This is > upto > + * 1.15V where VSET is 0x1A. > + * > + * For 0x1B the output voltage is 1.2V, and for every increment > of > + * VSET the output voltage increases by 50mV upto the max > voltage of > + * 3.3V > + * > + * | Voltage Ranges | VSET Ranges | Voltage Step | > + * +-+--+--+ > + * | 0.5V to 1.50V | 0x00 to 0x1A | 25mV| > + * | 1.2V to 3.3V| 0x1B to 0x45 | 50mV| > + */ > + if (uV >= 120) > + return (uV - 120) / 5 + 0x1B; > + else if (uV >= 50) > + return (uV - 50) / 25000; > + else > + return -EINVAL; > + } > + > + /* Buck1 and Buck12(dual phase) has a different mapping b/w output > + * voltage and VSET value. > + * > + * | Voltage Ranges | VSET Ranges | Voltage Step | > + * +-+--+--+ > + * | 0.5V to 0.58V | 0xA to 0xE | 20mV| > + * | 0.6V to 1.095V | 0xF to 0x72 | 5mV | > + * | 1.1V to 1.65V | 0x73 to 0xAA | 10mV| > + * | 1.6V to 3.3V| 0xAB to 0xFD | 20mV| > + * > + */ > + if (uV >= 166) > + return (uV - 166) / 2 + 0xAB; > + else if (uV >= 110) > + return (uV - 110) / 1 + 0x73; > + else if (uV >= 60) > + return (uV - 60) / 5000 + 0x0F; > + else if (uV >= 50) > + return (uV - 50) / 2 + 0x0A; > + else > + return -EINVAL; > +} > + > +static int tps65224_buck_val2volt(int idx, int val) > +{ > + /* This function does the opposite to the tps65224_buck_volt2val > function > + * described above. > + * This maps the VSET value to micro volts. Please refer to the ranges > + * mentioned the comments of tps65224_buck_volt2val. > + */ > + > + if (idx > 0) { > + if (val > TPS65224_BUCK234_VOLT_MAX_HEX) > + return -EINVAL; > + else if (val >= 0x1B) > + return 120 + (val - 0x1B) * 5; > + else if (val >= 0x00) > + return 50 + (val - 0x00) * 25000; > + else > + return -EINVAL; > + } > + > + if (val > TPS65224_BUCK1_VOLT_MAX_HEX) > + return -EINVAL; > + else if (val >= 0xAB) > + return 166 + (val - 0xAB) * 2; > + else if (val >= 0x73) > + return 110 + (val - 0x73) * 1; > + else if (val >= 0xF) > + return 60 + (val - 0xF) * 5000; > + else if (val >= 0xA) > + return 50 + (val - 0xA) * 2; > + else > +
[RESEND PATCH v3 5/5] power: regulator: tps65941: Add TPS65224 PMIC regulator support
Reuse TPS65941 regulator driver to adds support for TPS65224 PMIC's regulators. 4 BUCKs and 3 LDOs, where BUCK1 and BUCK2 can be configured in dual phase mode. Signed-off-by: Bhargav Raviprakash --- drivers/power/regulator/tps65941_regulator.c | 283 ++- 1 file changed, 270 insertions(+), 13 deletions(-) diff --git a/drivers/power/regulator/tps65941_regulator.c b/drivers/power/regulator/tps65941_regulator.c index d879c2301b..b1b9462fd3 100644 --- a/drivers/power/regulator/tps65941_regulator.c +++ b/drivers/power/regulator/tps65941_regulator.c @@ -37,6 +37,8 @@ #define TPS65941_BUCK_CONV_OPS_IDX 0 #define TPS65941_LDO_CONV_OPS_IDX 0 +#define TPS65224_LDO_CONV_OPS_IDX 1 +#define TPS65224_BUCK_CONV_OPS_IDX 1 struct tps65941_reg_conv_ops { int volt_mask; @@ -55,6 +57,11 @@ static const char tps65941_ldo_ctrl[TPS65941_BUCK_NUM] = {0x1D, 0x1E, 0x1F, static const char tps65941_ldo_vout[TPS65941_BUCK_NUM] = {0x23, 0x24, 0x25, 0x26}; +static inline int tps65941_get_chip_id(struct udevice *dev) +{ + return dev->parent->driver_data; +} + static int tps65941_buck_enable(struct udevice *dev, int op, bool *enable) { int ret; @@ -146,6 +153,112 @@ int tps65941_lookup_slew(int id) } } +static int tps65224_buck_volt2val(int idx, int uV) +{ + /* This functions maps a value which is in micro Volts to the VSET value. +* The mapping is as per the datasheet of TPS65224. +*/ + + if (uV > TPS65224_BUCK_VOLT_MAX) + return -EINVAL; + + if (idx > 0) { + /* Buck2, Buck3 and Buck4 of TPS65224 has a different schema in +* converting b/w micro_volt and VSET hex values +* +* VSET value starts from 0x00 for 0.5V, and for every increment +* in VSET value the output voltage increases by 25mV. This is upto +* 1.15V where VSET is 0x1A. +* +* For 0x1B the output voltage is 1.2V, and for every increment of +* VSET the output voltage increases by 50mV upto the max voltage of +* 3.3V +* +* | Voltage Ranges | VSET Ranges | Voltage Step | +* +-+--+--+ +* | 0.5V to 1.50V | 0x00 to 0x1A | 25mV| +* | 1.2V to 3.3V| 0x1B to 0x45 | 50mV| +*/ + if (uV >= 120) + return (uV - 120) / 5 + 0x1B; + else if (uV >= 50) + return (uV - 50) / 25000; + else + return -EINVAL; + } + + /* Buck1 and Buck12(dual phase) has a different mapping b/w output +* voltage and VSET value. +* +* | Voltage Ranges | VSET Ranges | Voltage Step | +* +-+--+--+ +* | 0.5V to 0.58V | 0xA to 0xE | 20mV| +* | 0.6V to 1.095V | 0xF to 0x72 | 5mV | +* | 1.1V to 1.65V | 0x73 to 0xAA | 10mV| +* | 1.6V to 3.3V| 0xAB to 0xFD | 20mV| +* +*/ + if (uV >= 166) + return (uV - 166) / 2 + 0xAB; + else if (uV >= 110) + return (uV - 110) / 1 + 0x73; + else if (uV >= 60) + return (uV - 60) / 5000 + 0x0F; + else if (uV >= 50) + return (uV - 50) / 2 + 0x0A; + else + return -EINVAL; +} + +static int tps65224_buck_val2volt(int idx, int val) +{ + /* This function does the opposite to the tps65224_buck_volt2val function +* described above. +* This maps the VSET value to micro volts. Please refer to the ranges +* mentioned the comments of tps65224_buck_volt2val. +*/ + + if (idx > 0) { + if (val > TPS65224_BUCK234_VOLT_MAX_HEX) + return -EINVAL; + else if (val >= 0x1B) + return 120 + (val - 0x1B) * 5; + else if (val >= 0x00) + return 50 + (val - 0x00) * 25000; + else + return -EINVAL; + } + + if (val > TPS65224_BUCK1_VOLT_MAX_HEX) + return -EINVAL; + else if (val >= 0xAB) + return 166 + (val - 0xAB) * 2; + else if (val >= 0x73) + return 110 + (val - 0x73) * 1; + else if (val >= 0xF) + return 60 + (val - 0xF) * 5000; + else if (val >= 0xA) + return 50 + (val - 0xA) * 2; + else + return -EINVAL; +} + +int tps65224_lookup_slew(int id) +{ + switch (id) { + case 0: + return 1; + case 1: +
[PATCH v3 5/5] power: regulator: tps65941: Add TPS65224 PMIC regulator support
Reuse TPS65941 regulator driver to adds support for TPS65224 PMIC's regulators. 4 BUCKs and 3 LDOs, where BUCK1 and BUCK2 can be configured in dual phase mode. Signed-off-by: Bhargav Raviprakash --- drivers/power/regulator/tps65941_regulator.c | 280 ++- 1 file changed, 267 insertions(+), 13 deletions(-) diff --git a/drivers/power/regulator/tps65941_regulator.c b/drivers/power/regulator/tps65941_regulator.c index d879c2301b..826bc0c63e 100644 --- a/drivers/power/regulator/tps65941_regulator.c +++ b/drivers/power/regulator/tps65941_regulator.c @@ -37,6 +37,8 @@ #define TPS65941_BUCK_CONV_OPS_IDX 0 #define TPS65941_LDO_CONV_OPS_IDX 0 +#define TPS65224_LDO_CONV_OPS_IDX 1 +#define TPS65224_BUCK_CONV_OPS_IDX 1 struct tps65941_reg_conv_ops { int volt_mask; @@ -55,6 +57,11 @@ static const char tps65941_ldo_ctrl[TPS65941_BUCK_NUM] = {0x1D, 0x1E, 0x1F, static const char tps65941_ldo_vout[TPS65941_BUCK_NUM] = {0x23, 0x24, 0x25, 0x26}; +static inline int tps65941_get_chip_id(struct udevice *dev) +{ + return dev->parent->driver_data; +} + static int tps65941_buck_enable(struct udevice *dev, int op, bool *enable) { int ret; @@ -146,6 +153,112 @@ int tps65941_lookup_slew(int id) } } +static int tps65224_buck_volt2val(int idx, int uV) +{ + /* This functions maps a value which is in micro Volts to the VSET value. +* The mapping is as per the datasheet of TPS65224. +*/ + + if (uV > TPS65224_BUCK_VOLT_MAX) + return -EINVAL; + + if (idx > 0) { + /* Buck2, Buck3 and Buck4 of TPS65224 has a different schema in +* converting b/w micro_volt and VSET hex values +* +* VSET value starts from 0x00 for 0.5V, and for every increment +* in VSET value the output voltage increases by 25mV. This is upto +* 1.15V where VSET is 0x1A. +* +* For 0x1B the output voltage is 1.2V, and for every increment of +* VSET the output voltage increases by 50mV upto the max voltage of +* 3.3V +* +* | Voltage Ranges | VSET Ranges | Voltage Step | +* +-+--+--+ +* | 0.5V to 1.50V | 0x00 to 0x1A | 25mV| +* | 1.2V to 3.3V| 0x1B to 0x45 | 50mV| +*/ + if (uV >= 120) + return (uV - 120) / 5 + 0x1B; + else if (uV >= 50) + return (uV - 50) / 25000; + else + return -EINVAL; + } + + /* Buck1 and Buck12(dual phase) has a different mapping b/w output +* voltage and VSET value. +* +* | Voltage Ranges | VSET Ranges | Voltage Step | +* +-+--+--+ +* | 0.5V to 0.58V | 0xA to 0xE | 20mV| +* | 0.6V to 1.095V | 0xF to 0x72 | 5mV | +* | 1.1V to 1.65V | 0x73 to 0xAA | 10mV| +* | 1.6V to 3.3V| 0xAB to 0xFD | 20mV| +* +*/ + if (uV >= 166) + return (uV - 166) / 2 + 0xAB; + else if (uV >= 110) + return (uV - 110) / 1 + 0x73; + else if (uV >= 60) + return (uV - 60) / 5000 + 0x0F; + else if (uV >= 50) + return (uV - 50) / 2 + 0x0A; + else + return -EINVAL; +} + +static int tps65224_buck_val2volt(int idx, int val) +{ + /* This function does the opposite to the tps65224_buck_volt2val function +* described above. +* This maps the VSET value to micro volts. Please refer to the ranges +* mentioned the comments of tps65224_buck_volt2val. +*/ + + if (idx > 0) { + if (val > TPS65224_BUCK234_VOLT_MAX_HEX) + return -EINVAL; + else if (val >= 0x1B) + return 120 + (val - 0x1B) * 5; + else if (val >= 0x00) + return 50 + (val - 0x00) * 25000; + else + return -EINVAL; + } + + if (val > TPS65224_BUCK1_VOLT_MAX_HEX) + return -EINVAL; + else if (val >= 0xAB) + return 166 + (val - 0xAB) * 2; + else if (val >= 0x73) + return 110 + (val - 0x73) * 1; + else if (val >= 0xF) + return 60 + (val - 0xF) * 5000; + else if (val >= 0xA) + return 50 + (val - 0xA) * 2; + else + return -EINVAL; +} + +int tps65224_lookup_slew(int id) +{ + switch (id) { + case 0: + return 1; + case 1: +