@@ -33,6 +33,7 @@ static DEFINE_MUTEX(regulator_list_mutex);
33
33
static LIST_HEAD (regulator_list );
34
34
static LIST_HEAD (regulator_map_list );
35
35
static int has_full_constraints ;
36
+ static bool board_wants_dummy_regulator ;
36
37
37
38
/*
38
39
* struct regulator_map
@@ -63,7 +64,8 @@ struct regulator {
63
64
};
64
65
65
66
static int _regulator_is_enabled (struct regulator_dev * rdev );
66
- static int _regulator_disable (struct regulator_dev * rdev );
67
+ static int _regulator_disable (struct regulator_dev * rdev ,
68
+ struct regulator_dev * * supply_rdev_ptr );
67
69
static int _regulator_get_voltage (struct regulator_dev * rdev );
68
70
static int _regulator_get_current_limit (struct regulator_dev * rdev );
69
71
static unsigned int _regulator_get_mode (struct regulator_dev * rdev );
@@ -1108,6 +1110,11 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
1108
1110
}
1109
1111
}
1110
1112
1113
+ if (board_wants_dummy_regulator ) {
1114
+ rdev = dummy_regulator_rdev ;
1115
+ goto found ;
1116
+ }
1117
+
1111
1118
#ifdef CONFIG_REGULATOR_DUMMY
1112
1119
if (!devname )
1113
1120
devname = "deviceless" ;
@@ -1348,7 +1355,8 @@ int regulator_enable(struct regulator *regulator)
1348
1355
EXPORT_SYMBOL_GPL (regulator_enable );
1349
1356
1350
1357
/* locks held by regulator_disable() */
1351
- static int _regulator_disable (struct regulator_dev * rdev )
1358
+ static int _regulator_disable (struct regulator_dev * rdev ,
1359
+ struct regulator_dev * * supply_rdev_ptr )
1352
1360
{
1353
1361
int ret = 0 ;
1354
1362
@@ -1376,8 +1384,7 @@ static int _regulator_disable(struct regulator_dev *rdev)
1376
1384
}
1377
1385
1378
1386
/* decrease our supplies ref count and disable if required */
1379
- if (rdev -> supply )
1380
- _regulator_disable (rdev -> supply );
1387
+ * supply_rdev_ptr = rdev -> supply ;
1381
1388
1382
1389
rdev -> use_count = 0 ;
1383
1390
} else if (rdev -> use_count > 1 ) {
@@ -1407,17 +1414,29 @@ static int _regulator_disable(struct regulator_dev *rdev)
1407
1414
int regulator_disable (struct regulator * regulator )
1408
1415
{
1409
1416
struct regulator_dev * rdev = regulator -> rdev ;
1417
+ struct regulator_dev * supply_rdev = NULL ;
1410
1418
int ret = 0 ;
1411
1419
1412
1420
mutex_lock (& rdev -> mutex );
1413
- ret = _regulator_disable (rdev );
1421
+ ret = _regulator_disable (rdev , & supply_rdev );
1414
1422
mutex_unlock (& rdev -> mutex );
1423
+
1424
+ /* decrease our supplies ref count and disable if required */
1425
+ while (supply_rdev != NULL ) {
1426
+ rdev = supply_rdev ;
1427
+
1428
+ mutex_lock (& rdev -> mutex );
1429
+ _regulator_disable (rdev , & supply_rdev );
1430
+ mutex_unlock (& rdev -> mutex );
1431
+ }
1432
+
1415
1433
return ret ;
1416
1434
}
1417
1435
EXPORT_SYMBOL_GPL (regulator_disable );
1418
1436
1419
1437
/* locks held by regulator_force_disable() */
1420
- static int _regulator_force_disable (struct regulator_dev * rdev )
1438
+ static int _regulator_force_disable (struct regulator_dev * rdev ,
1439
+ struct regulator_dev * * supply_rdev_ptr )
1421
1440
{
1422
1441
int ret = 0 ;
1423
1442
@@ -1436,8 +1455,7 @@ static int _regulator_force_disable(struct regulator_dev *rdev)
1436
1455
}
1437
1456
1438
1457
/* decrease our supplies ref count and disable if required */
1439
- if (rdev -> supply )
1440
- _regulator_disable (rdev -> supply );
1458
+ * supply_rdev_ptr = rdev -> supply ;
1441
1459
1442
1460
rdev -> use_count = 0 ;
1443
1461
return ret ;
@@ -1454,12 +1472,17 @@ static int _regulator_force_disable(struct regulator_dev *rdev)
1454
1472
*/
1455
1473
int regulator_force_disable (struct regulator * regulator )
1456
1474
{
1475
+ struct regulator_dev * supply_rdev = NULL ;
1457
1476
int ret ;
1458
1477
1459
1478
mutex_lock (& regulator -> rdev -> mutex );
1460
1479
regulator -> uA_load = 0 ;
1461
- ret = _regulator_force_disable (regulator -> rdev );
1480
+ ret = _regulator_force_disable (regulator -> rdev , & supply_rdev );
1462
1481
mutex_unlock (& regulator -> rdev -> mutex );
1482
+
1483
+ if (supply_rdev )
1484
+ regulator_disable (get_device_regulator (rdev_get_dev (supply_rdev )));
1485
+
1463
1486
return ret ;
1464
1487
}
1465
1488
EXPORT_SYMBOL_GPL (regulator_force_disable );
@@ -2462,6 +2485,22 @@ void regulator_has_full_constraints(void)
2462
2485
}
2463
2486
EXPORT_SYMBOL_GPL (regulator_has_full_constraints );
2464
2487
2488
+ /**
2489
+ * regulator_use_dummy_regulator - Provide a dummy regulator when none is found
2490
+ *
2491
+ * Calling this function will cause the regulator API to provide a
2492
+ * dummy regulator to consumers if no physical regulator is found,
2493
+ * allowing most consumers to proceed as though a regulator were
2494
+ * configured. This allows systems such as those with software
2495
+ * controllable regulators for the CPU core only to be brought up more
2496
+ * readily.
2497
+ */
2498
+ void regulator_use_dummy_regulator (void )
2499
+ {
2500
+ board_wants_dummy_regulator = true;
2501
+ }
2502
+ EXPORT_SYMBOL_GPL (regulator_use_dummy_regulator );
2503
+
2465
2504
/**
2466
2505
* rdev_get_drvdata - get rdev regulator driver data
2467
2506
* @rdev: regulator
0 commit comments