@@ -82,15 +82,17 @@ struct regulator {
8282};
8383
8484static int _regulator_is_enabled (struct regulator_dev * rdev );
85- static int _regulator_disable (struct regulator_dev * rdev ,
86- struct regulator_dev * * supply_rdev_ptr );
85+ static int _regulator_disable (struct regulator_dev * rdev );
8786static int _regulator_get_voltage (struct regulator_dev * rdev );
8887static int _regulator_get_current_limit (struct regulator_dev * rdev );
8988static unsigned int _regulator_get_mode (struct regulator_dev * rdev );
9089static void _notifier_call_chain (struct regulator_dev * rdev ,
9190 unsigned long event , void * data );
9291static int _regulator_do_set_voltage (struct regulator_dev * rdev ,
9392 int min_uV , int max_uV );
93+ static struct regulator * create_regulator (struct regulator_dev * rdev ,
94+ struct device * dev ,
95+ const char * supply_name );
9496
9597static const char * rdev_get_name (struct regulator_dev * rdev )
9698{
@@ -930,21 +932,20 @@ static int set_machine_constraints(struct regulator_dev *rdev,
930932 * core if it's child is enabled.
931933 */
932934static int set_supply (struct regulator_dev * rdev ,
933- struct regulator_dev * supply_rdev )
935+ struct regulator_dev * supply_rdev )
934936{
935937 int err ;
936938
937- err = sysfs_create_link (& rdev -> dev .kobj , & supply_rdev -> dev .kobj ,
938- "supply" );
939- if (err ) {
940- rdev_err (rdev , "could not add device link %s err %d\n" ,
941- supply_rdev -> dev .kobj .name , err );
942- goto out ;
939+ rdev_info (rdev , "supplied by %s\n" , rdev_get_name (supply_rdev ));
940+
941+ rdev -> supply = create_regulator (supply_rdev , & rdev -> dev , "SUPPLY" );
942+ if (IS_ERR (rdev -> supply )) {
943+ err = PTR_ERR (rdev -> supply );
944+ rdev -> supply = NULL ;
945+ return err ;
943946 }
944- rdev -> supply = supply_rdev ;
945- list_add (& rdev -> slist , & supply_rdev -> supply_list );
946- out :
947- return err ;
947+
948+ return 0 ;
948949}
949950
950951/**
@@ -1303,19 +1304,6 @@ static int _regulator_enable(struct regulator_dev *rdev)
13031304{
13041305 int ret , delay ;
13051306
1306- if (rdev -> use_count == 0 ) {
1307- /* do we need to enable the supply regulator first */
1308- if (rdev -> supply ) {
1309- mutex_lock (& rdev -> supply -> mutex );
1310- ret = _regulator_enable (rdev -> supply );
1311- mutex_unlock (& rdev -> supply -> mutex );
1312- if (ret < 0 ) {
1313- rdev_err (rdev , "failed to enable: %d\n" , ret );
1314- return ret ;
1315- }
1316- }
1317- }
1318-
13191307 /* check voltage and requested load before enabling */
13201308 if (rdev -> constraints &&
13211309 (rdev -> constraints -> valid_ops_mask & REGULATOR_CHANGE_DRMS ))
@@ -1390,19 +1378,27 @@ int regulator_enable(struct regulator *regulator)
13901378 struct regulator_dev * rdev = regulator -> rdev ;
13911379 int ret = 0 ;
13921380
1381+ if (rdev -> supply ) {
1382+ ret = regulator_enable (rdev -> supply );
1383+ if (ret != 0 )
1384+ return ret ;
1385+ }
1386+
13931387 mutex_lock (& rdev -> mutex );
13941388 ret = _regulator_enable (rdev );
13951389 mutex_unlock (& rdev -> mutex );
1390+
1391+ if (ret != 0 )
1392+ regulator_disable (rdev -> supply );
1393+
13961394 return ret ;
13971395}
13981396EXPORT_SYMBOL_GPL (regulator_enable );
13991397
14001398/* locks held by regulator_disable() */
1401- static int _regulator_disable (struct regulator_dev * rdev ,
1402- struct regulator_dev * * supply_rdev_ptr )
1399+ static int _regulator_disable (struct regulator_dev * rdev )
14031400{
14041401 int ret = 0 ;
1405- * supply_rdev_ptr = NULL ;
14061402
14071403 if (WARN (rdev -> use_count <= 0 ,
14081404 "unbalanced disables for %s\n" , rdev_get_name (rdev )))
@@ -1429,9 +1425,6 @@ static int _regulator_disable(struct regulator_dev *rdev,
14291425 NULL );
14301426 }
14311427
1432- /* decrease our supplies ref count and disable if required */
1433- * supply_rdev_ptr = rdev -> supply ;
1434-
14351428 rdev -> use_count = 0 ;
14361429 } else if (rdev -> use_count > 1 ) {
14371430
@@ -1442,6 +1435,7 @@ static int _regulator_disable(struct regulator_dev *rdev,
14421435
14431436 rdev -> use_count -- ;
14441437 }
1438+
14451439 return ret ;
14461440}
14471441
@@ -1460,29 +1454,21 @@ static int _regulator_disable(struct regulator_dev *rdev,
14601454int regulator_disable (struct regulator * regulator )
14611455{
14621456 struct regulator_dev * rdev = regulator -> rdev ;
1463- struct regulator_dev * supply_rdev = NULL ;
14641457 int ret = 0 ;
14651458
14661459 mutex_lock (& rdev -> mutex );
1467- ret = _regulator_disable (rdev , & supply_rdev );
1460+ ret = _regulator_disable (rdev );
14681461 mutex_unlock (& rdev -> mutex );
14691462
1470- /* decrease our supplies ref count and disable if required */
1471- while (supply_rdev != NULL ) {
1472- rdev = supply_rdev ;
1473-
1474- mutex_lock (& rdev -> mutex );
1475- _regulator_disable (rdev , & supply_rdev );
1476- mutex_unlock (& rdev -> mutex );
1477- }
1463+ if (ret == 0 && rdev -> supply )
1464+ regulator_disable (rdev -> supply );
14781465
14791466 return ret ;
14801467}
14811468EXPORT_SYMBOL_GPL (regulator_disable );
14821469
14831470/* locks held by regulator_force_disable() */
1484- static int _regulator_force_disable (struct regulator_dev * rdev ,
1485- struct regulator_dev * * supply_rdev_ptr )
1471+ static int _regulator_force_disable (struct regulator_dev * rdev )
14861472{
14871473 int ret = 0 ;
14881474
@@ -1499,10 +1485,6 @@ static int _regulator_force_disable(struct regulator_dev *rdev,
14991485 REGULATOR_EVENT_DISABLE , NULL );
15001486 }
15011487
1502- /* decrease our supplies ref count and disable if required */
1503- * supply_rdev_ptr = rdev -> supply ;
1504-
1505- rdev -> use_count = 0 ;
15061488 return ret ;
15071489}
15081490
@@ -1518,16 +1500,16 @@ static int _regulator_force_disable(struct regulator_dev *rdev,
15181500int regulator_force_disable (struct regulator * regulator )
15191501{
15201502 struct regulator_dev * rdev = regulator -> rdev ;
1521- struct regulator_dev * supply_rdev = NULL ;
15221503 int ret ;
15231504
15241505 mutex_lock (& rdev -> mutex );
15251506 regulator -> uA_load = 0 ;
1526- ret = _regulator_force_disable (rdev , & supply_rdev );
1507+ ret = _regulator_force_disable (regulator -> rdev );
15271508 mutex_unlock (& rdev -> mutex );
15281509
1529- if (supply_rdev )
1530- regulator_disable (get_device_regulator (rdev_get_dev (supply_rdev )));
1510+ if (rdev -> supply )
1511+ while (rdev -> open_count -- )
1512+ regulator_disable (rdev -> supply );
15311513
15321514 return ret ;
15331515}
@@ -2138,7 +2120,7 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
21382120 /* get input voltage */
21392121 input_uV = 0 ;
21402122 if (rdev -> supply )
2141- input_uV = _regulator_get_voltage (rdev -> supply );
2123+ input_uV = regulator_get_voltage (rdev -> supply );
21422124 if (input_uV <= 0 )
21432125 input_uV = rdev -> constraints -> input_uV ;
21442126 if (input_uV <= 0 ) {
@@ -2208,17 +2190,8 @@ EXPORT_SYMBOL_GPL(regulator_unregister_notifier);
22082190static void _notifier_call_chain (struct regulator_dev * rdev ,
22092191 unsigned long event , void * data )
22102192{
2211- struct regulator_dev * _rdev ;
2212-
22132193 /* call rdev chain first */
22142194 blocking_notifier_call_chain (& rdev -> notifier , event , NULL );
2215-
2216- /* now notify regulator we supply */
2217- list_for_each_entry (_rdev , & rdev -> supply_list , slist ) {
2218- mutex_lock (& _rdev -> mutex );
2219- _notifier_call_chain (_rdev , event , data );
2220- mutex_unlock (& _rdev -> mutex );
2221- }
22222195}
22232196
22242197/**
@@ -2610,9 +2583,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
26102583 rdev -> owner = regulator_desc -> owner ;
26112584 rdev -> desc = regulator_desc ;
26122585 INIT_LIST_HEAD (& rdev -> consumer_list );
2613- INIT_LIST_HEAD (& rdev -> supply_list );
26142586 INIT_LIST_HEAD (& rdev -> list );
2615- INIT_LIST_HEAD (& rdev -> slist );
26162587 BLOCKING_INIT_NOTIFIER_HEAD (& rdev -> notifier );
26172588
26182589 /* preform any regulator specific init */
@@ -2724,7 +2695,7 @@ void regulator_unregister(struct regulator_dev *rdev)
27242695 unset_regulator_supplies (rdev );
27252696 list_del (& rdev -> list );
27262697 if (rdev -> supply )
2727- sysfs_remove_link ( & rdev -> dev . kobj , " supply" );
2698+ regulator_put ( rdev -> supply );
27282699 device_unregister (& rdev -> dev );
27292700 kfree (rdev -> constraints );
27302701 mutex_unlock (& regulator_list_mutex );
0 commit comments