regulator: mc13xxx: Fix voltage checking for mc13xxx_fixed_regulator_set_voltage
PATCH 1/2 regulator: mc13xxx: Fix voltage checking for mc13xxx_fixed_regulator_set_voltage
The voltage range checking should be to ensure mc13xxx_regulators[id].voltages[0] falls with min_uV and max_uV.
Signed-off-by Axel Lin <[email protected]>
--- drivers/regulator/mc13xxx-regulator-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/regulator/mc13xxx-regulator-core.c +2 -2
@@ -158,8 +158,8 @@ int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, int min_uV,dev_dbg (rdev_get_dev (rdev),"%s id: %d min_uV: %d max_uV: %d\n" , __func__, id, min_uV, max_uV); -if (min_uV >= mc13xxx_regulators[id].voltages[0 ] && - max_uV <= mc13xxx_regulators[id].voltages[0 ]) +if (min_uV <= mc13xxx_regulators[id].voltages[0 ] && + mc13xxx_regulators[id].voltages[0 ] <= max_uV)return 0 ;else return -EINVAL ;
Signature · 1 line
1.7.9.5
PATCH 2/2 regulator: mc13xxx: Convert to regulator_list_voltage_table
Signed-off-by Axel Lin <[email protected]>
--- drivers/regulator/mc13783-regulator.c | 38 ++++++++++++------------- drivers/regulator/mc13892-regulator.c | 42 ++++++++++++++-------------- drivers/regulator/mc13xxx-regulator-core.c | 30 ++++---------------- drivers/regulator/mc13xxx.h | 9 ++---- 4 files changed, 49 insertions(+), 70 deletions(-)
drivers/regulator/mc13783-regulator.c +19 -19
@@ -93,78 +93,78 @@/* Voltage Values */ -static const int mc13783_sw3_val[] = { +static const unsigned int mc13783_sw3_val[] = {5000000 ,5000000 ,5000000 ,5500000 , }; -static const int mc13783_vaudio_val[] = { +static const unsigned int mc13783_vaudio_val[] = {2775000 , }; -static const int mc13783_viohi_val[] = { +static const unsigned int mc13783_viohi_val[] = {2775000 , }; -static const int mc13783_violo_val[] = { +static const unsigned int mc13783_violo_val[] = {1200000 ,1300000 ,1500000 ,1800000 , }; -static const int mc13783_vdig_val[] = { +static const unsigned int mc13783_vdig_val[] = {1200000 ,1300000 ,1500000 ,1800000 , }; -static const int mc13783_vgen_val[] = { +static const unsigned int mc13783_vgen_val[] = {1200000 ,1300000 ,1500000 ,1800000 ,1100000 ,2000000 ,2775000 ,2400000 , }; -static const int mc13783_vrfdig_val[] = { +static const unsigned int mc13783_vrfdig_val[] = {1200000 ,1500000 ,1800000 ,1875000 , }; -static const int mc13783_vrfref_val[] = { +static const unsigned int mc13783_vrfref_val[] = {2475000 ,2600000 ,2700000 ,2775000 , }; -static const int mc13783_vrfcp_val[] = { +static const unsigned int mc13783_vrfcp_val[] = {2700000 ,2775000 , }; -static const int mc13783_vsim_val[] = { +static const unsigned int mc13783_vsim_val[] = {1800000 ,2900000 ,3000000 , }; -static const int mc13783_vesim_val[] = { +static const unsigned int mc13783_vesim_val[] = {1800000 ,2900000 , }; -static const int mc13783_vcam_val[] = { +static const unsigned int mc13783_vcam_val[] = {1500000 ,1800000 ,2500000 ,2550000 ,2600000 ,2750000 ,2800000 ,3000000 , }; -static const int mc13783_vrfbg_val[] = { +static const unsigned int mc13783_vrfbg_val[] = {1250000 , }; -static const int mc13783_vvib_val[] = { +static const unsigned int mc13783_vvib_val[] = {1300000 ,1800000 ,2000000 ,3000000 , }; -static const int mc13783_vmmc_val[] = { +static const unsigned int mc13783_vmmc_val[] = {1600000 ,1800000 ,2000000 ,2600000 ,2700000 ,2800000 ,2900000 ,3000000 , }; -static const int mc13783_vrf_val[] = { +static const unsigned int mc13783_vrf_val[] = {1500000 ,1875000 ,2700000 ,2775000 , }; -static const int mc13783_gpo_val[] = { +static const unsigned int mc13783_gpo_val[] = {3100000 , }; -static const int mc13783_pwgtdrv_val[] = { +static const unsigned int mc13783_pwgtdrv_val[] = {5500000 , };
@@ -328,7 +328,7 @@ static struct regulator_ops mc13783_gpo_regulator_ops = { .enable = mc13783_gpo_regulator_enable, .disable = mc13783_gpo_regulator_disable, .is_enabled = mc13783_gpo_regulator_is_enabled, - .list_voltage = mc13xxx_regulator_list_voltage, + .list_voltage = regulator_list_voltage_table, .set_voltage = mc13xxx_fixed_regulator_set_voltage, .get_voltage = mc13xxx_fixed_regulator_get_voltage, };
drivers/regulator/mc13892-regulator.c +21 -21
126 lines not on this page · raw message
drivers/regulator/mc13xxx-regulator-core.c +6 -24
@@ -80,20 +80,6 @@ static int mc13xxx_regulator_is_enabled(struct regulator_dev *rdev)return (val & mc13xxx_regulators[id].enable_bit) !=0 ; } -int mc13xxx_regulator_list_voltage (struct regulator_dev *rdev, -unsigned selector) -{ -int id =rdev_get_id (rdev); -struct mc13xxx_regulator_priv *priv =rdev_get_drvdata (rdev); -struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators; - -if (selector >= mc13xxx_regulators[id].desc.n_voltages) -return -EINVAL ; - -return mc13xxx_regulators[id].voltages[selector]; -} -EXPORT_SYMBOL_GPL (mc13xxx_regulator_list_voltage); -static int mc13xxx_regulator_set_voltage_sel (struct regulator_dev *rdev,unsigned selector) {
@@ -135,14 +121,14 @@ static int mc13xxx_regulator_get_voltage(struct regulator_dev *rdev)BUG_ON (val >= mc13xxx_regulators[id].desc.n_voltages); -return mc13xxx_regulators[id].voltages[val]; +return rdev->desc->volt_table[val]; }struct regulator_ops mc13xxx_regulator_ops = { .enable = mc13xxx_regulator_enable, .disable = mc13xxx_regulator_disable, .is_enabled = mc13xxx_regulator_is_enabled, - .list_voltage = mc13xxx_regulator_list_voltage, + .list_voltage = regulator_list_voltage_table, .set_voltage_sel = mc13xxx_regulator_set_voltage_sel, .get_voltage = mc13xxx_regulator_get_voltage, };
@@ -151,15 +137,13 @@ EXPORT_SYMBOL_GPL(mc13xxx_regulator_ops);int mc13xxx_fixed_regulator_set_voltage (struct regulator_dev *rdev,int min_uV,int max_uV,unsigned *selector) { -struct mc13xxx_regulator_priv *priv =rdev_get_drvdata (rdev); -struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;int id =rdev_get_id (rdev);dev_dbg (rdev_get_dev (rdev),"%s id: %d min_uV: %d max_uV: %d\n" , __func__, id, min_uV, max_uV); -if (min_uV <= mc13xxx_regulators[id].voltages[0 ] && - mc13xxx_regulators[id].voltages[0 ] <= max_uV) +if (min_uV <= rdev->desc->volt_table[0 ] && + rdev->desc->volt_table[0 ] <= max_uV)return 0 ;else return -EINVAL ;
@@ -168,13 +152,11 @@ EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_set_voltage);int mc13xxx_fixed_regulator_get_voltage (struct regulator_dev *rdev) { -struct mc13xxx_regulator_priv *priv =rdev_get_drvdata (rdev); -struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;int id =rdev_get_id (rdev);dev_dbg (rdev_get_dev (rdev),"%s id: %d\n" , __func__, id); -return mc13xxx_regulators[id].voltages[0 ]; +return rdev->desc->volt_table[0 ]; }EXPORT_SYMBOL_GPL (mc13xxx_fixed_regulator_get_voltage);
@@ -182,7 +164,7 @@ struct regulator_ops mc13xxx_fixed_regulator_ops = { .enable = mc13xxx_regulator_enable, .disable = mc13xxx_regulator_disable, .is_enabled = mc13xxx_regulator_is_enabled, - .list_voltage = mc13xxx_regulator_list_voltage, + .list_voltage = regulator_list_voltage_table, .set_voltage = mc13xxx_fixed_regulator_set_voltage, .get_voltage = mc13xxx_fixed_regulator_get_voltage, };
drivers/regulator/mc13xxx.h +3 -6
@@ -22,7 +22,6 @@ struct mc13xxx_regulator {int vsel_shift;int vsel_mask;int hi_bit; -int const *voltages; };struct mc13xxx_regulator_priv {
@@ -35,8 +34,6 @@ struct mc13xxx_regulator_priv {extern int mc13xxx_sw_regulator (struct regulator_dev *rdev);extern int mc13xxx_sw_regulator_is_enabled (struct regulator_dev *rdev); -extern int mc13xxx_regulator_list_voltage (struct regulator_dev *rdev, -unsigned selector);extern int mc13xxx_fixed_regulator_set_voltage (struct regulator_dev *rdev,int min_uV,int max_uV,unsigned *selector);extern int mc13xxx_fixed_regulator_get_voltage (struct regulator_dev *rdev);
@@ -68,6 +65,7 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops; .desc = { \ .name = #_name, \ .n_voltages = ARRAY_SIZE(_voltages), \ + .volt_table = _voltages, \ .ops = &_ops, \ .type = REGULATOR_VOLTAGE, \ .id = prefix ## _name, \
@@ -78,7 +76,6 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops; .vsel_reg = prefix ## _vsel_reg, \ .vsel_shift = prefix ## _vsel_reg ## _ ## _name ## VSEL,\ .vsel_mask = prefix ## _vsel_reg ## _ ## _name ## VSEL_M,\ - .voltages = _voltages, \ }#define MC13xxx_FIXED_DEFINE (prefix, _name, _reg, _voltages, _ops) \
@@ -86,6 +83,7 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops; .desc = { \ .name = #_name, \ .n_voltages = ARRAY_SIZE(_voltages), \ + .volt_table = _voltages, \ .ops = &_ops, \ .type = REGULATOR_VOLTAGE, \ .id = prefix ## _name, \
@@ -93,7 +91,6 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops; }, \ .reg = prefix ## _reg, \ .enable_bit = prefix ## _reg ## _ ## _name ## EN, \ - .voltages = _voltages, \ }#define MC13xxx_GPO_DEFINE (prefix, _name, _reg, _voltages, _ops) \
@@ -101,6 +98,7 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops; .desc = { \ .name = #_name, \ .n_voltages = ARRAY_SIZE(_voltages), \ + .volt_table = _voltages, \ .ops = &_ops, \ .type = REGULATOR_VOLTAGE, \ .id = prefix ## _name, \
@@ -108,7 +106,6 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops; }, \ .reg = prefix ## _reg, \ .enable_bit = prefix ## _reg ## _ ## _name ## EN, \ - .voltages = _voltages, \ }#define MC13xxx_DEFINE_SW (_name, _reg, _vsel_reg, _voltages, ops) \
Signature · 1 line
1.7.9.5
Mark Brown
AppliedQuoted 2 lines · Axel Lin
The voltage range checking should be to ensure mc13xxx_regulators[id].voltages[0] falls with
min_uVandmax_uV.
Applied both, thanks.