@@ -83,6 +83,8 @@ static int _regulator_get_current_limit(struct regulator_dev *rdev);
8383static unsigned int _regulator_get_mode (struct regulator_dev * rdev );
8484static void _notifier_call_chain (struct regulator_dev * rdev ,
8585 unsigned long event , void * data );
86+ static int _regulator_do_set_voltage (struct regulator_dev * rdev ,
87+ int min_uV , int max_uV );
8688
8789static const char * rdev_get_name (struct regulator_dev * rdev )
8890{
@@ -745,22 +747,19 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
745747{
746748 struct regulator_ops * ops = rdev -> desc -> ops ;
747749 int ret ;
748- unsigned selector ;
749750
750751 /* do we need to apply the constraint voltage */
751752 if (rdev -> constraints -> apply_uV &&
752- rdev -> constraints -> min_uV == rdev -> constraints -> max_uV &&
753- ops -> set_voltage ) {
754- ret = ops -> set_voltage (rdev ,
755- rdev -> constraints -> min_uV ,
756- rdev -> constraints -> max_uV ,
757- & selector );
758- if (ret < 0 ) {
759- rdev_err (rdev , "failed to apply %duV constraint\n" ,
760- rdev -> constraints -> min_uV );
761- rdev -> constraints = NULL ;
762- return ret ;
763- }
753+ rdev -> constraints -> min_uV == rdev -> constraints -> max_uV ) {
754+ ret = _regulator_do_set_voltage (rdev ,
755+ rdev -> constraints -> min_uV ,
756+ rdev -> constraints -> max_uV );
757+ if (ret < 0 ) {
758+ rdev_err (rdev , "failed to apply %duV constraint\n" ,
759+ rdev -> constraints -> min_uV );
760+ rdev -> constraints = NULL ;
761+ return ret ;
762+ }
764763 }
765764
766765 /* constrain machine-level voltage specs to fit
@@ -1621,6 +1620,32 @@ int regulator_is_supported_voltage(struct regulator *regulator,
16211620 return 0 ;
16221621}
16231622
1623+ static int _regulator_do_set_voltage (struct regulator_dev * rdev ,
1624+ int min_uV , int max_uV )
1625+ {
1626+ int ret ;
1627+ unsigned int selector ;
1628+
1629+ trace_regulator_set_voltage (rdev_get_name (rdev ), min_uV , max_uV );
1630+
1631+ if (rdev -> desc -> ops -> set_voltage ) {
1632+ ret = rdev -> desc -> ops -> set_voltage (rdev , min_uV , max_uV ,
1633+ & selector );
1634+
1635+ if (rdev -> desc -> ops -> list_voltage )
1636+ selector = rdev -> desc -> ops -> list_voltage (rdev ,
1637+ selector );
1638+ else
1639+ selector = -1 ;
1640+ } else {
1641+ ret = - EINVAL ;
1642+ }
1643+
1644+ trace_regulator_set_voltage_complete (rdev_get_name (rdev ), selector );
1645+
1646+ return ret ;
1647+ }
1648+
16241649/**
16251650 * regulator_set_voltage - set regulator output voltage
16261651 * @regulator: regulator source
@@ -1643,7 +1668,6 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
16431668{
16441669 struct regulator_dev * rdev = regulator -> rdev ;
16451670 int ret ;
1646- unsigned selector ;
16471671
16481672 mutex_lock (& rdev -> mutex );
16491673
@@ -1664,16 +1688,7 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
16641688 if (ret < 0 )
16651689 goto out ;
16661690
1667- trace_regulator_set_voltage (rdev_get_name (rdev ), min_uV , max_uV );
1668-
1669- ret = rdev -> desc -> ops -> set_voltage (rdev , min_uV , max_uV , & selector );
1670-
1671- if (rdev -> desc -> ops -> list_voltage )
1672- selector = rdev -> desc -> ops -> list_voltage (rdev , selector );
1673- else
1674- selector = -1 ;
1675-
1676- trace_regulator_set_voltage_complete (rdev_get_name (rdev ), selector );
1691+ ret = _regulator_do_set_voltage (rdev , min_uV , max_uV );
16771692
16781693out :
16791694 _notifier_call_chain (rdev , REGULATOR_EVENT_VOLTAGE_CHANGE , NULL );
0 commit comments