@@ -1413,6 +1413,65 @@ struct regulator *regulator_get_exclusive(struct device *dev, const char *id)
14131413}
14141414EXPORT_SYMBOL_GPL (regulator_get_exclusive );
14151415
1416+ /**
1417+ * regulator_get_optional - obtain optional access to a regulator.
1418+ * @dev: device for regulator "consumer"
1419+ * @id: Supply name or regulator ID.
1420+ *
1421+ * Returns a struct regulator corresponding to the regulator producer,
1422+ * or IS_ERR() condition containing errno. Other consumers will be
1423+ * unable to obtain this reference is held and the use count for the
1424+ * regulator will be initialised to reflect the current state of the
1425+ * regulator.
1426+ *
1427+ * This is intended for use by consumers for devices which can have
1428+ * some supplies unconnected in normal use, such as some MMC devices.
1429+ * It can allow the regulator core to provide stub supplies for other
1430+ * supplies requested using normal regulator_get() calls without
1431+ * disrupting the operation of drivers that can handle absent
1432+ * supplies.
1433+ *
1434+ * Use of supply names configured via regulator_set_device_supply() is
1435+ * strongly encouraged. It is recommended that the supply name used
1436+ * should match the name used for the supply and/or the relevant
1437+ * device pins in the datasheet.
1438+ */
1439+ struct regulator * regulator_get_optional (struct device * dev , const char * id )
1440+ {
1441+ return _regulator_get (dev , id , 0 );
1442+ }
1443+ EXPORT_SYMBOL_GPL (regulator_get_optional );
1444+
1445+ /**
1446+ * devm_regulator_get_optional - Resource managed regulator_get_optional()
1447+ * @dev: device for regulator "consumer"
1448+ * @id: Supply name or regulator ID.
1449+ *
1450+ * Managed regulator_get_optional(). Regulators returned from this
1451+ * function are automatically regulator_put() on driver detach. See
1452+ * regulator_get_optional() for more information.
1453+ */
1454+ struct regulator * devm_regulator_get_optional (struct device * dev ,
1455+ const char * id )
1456+ {
1457+ struct regulator * * ptr , * regulator ;
1458+
1459+ ptr = devres_alloc (devm_regulator_release , sizeof (* ptr ), GFP_KERNEL );
1460+ if (!ptr )
1461+ return ERR_PTR (- ENOMEM );
1462+
1463+ regulator = regulator_get_optional (dev , id );
1464+ if (!IS_ERR (regulator )) {
1465+ * ptr = regulator ;
1466+ devres_add (dev , ptr );
1467+ } else {
1468+ devres_free (ptr );
1469+ }
1470+
1471+ return regulator ;
1472+ }
1473+ EXPORT_SYMBOL_GPL (devm_regulator_get_optional );
1474+
14161475/* Locks held by regulator_put() */
14171476static void _regulator_put (struct regulator * regulator )
14181477{
@@ -1438,6 +1497,36 @@ static void _regulator_put(struct regulator *regulator)
14381497 module_put (rdev -> owner );
14391498}
14401499
1500+ /**
1501+ * devm_regulator_get_exclusive - Resource managed regulator_get_exclusive()
1502+ * @dev: device for regulator "consumer"
1503+ * @id: Supply name or regulator ID.
1504+ *
1505+ * Managed regulator_get_exclusive(). Regulators returned from this function
1506+ * are automatically regulator_put() on driver detach. See regulator_get() for
1507+ * more information.
1508+ */
1509+ struct regulator * devm_regulator_get_exclusive (struct device * dev ,
1510+ const char * id )
1511+ {
1512+ struct regulator * * ptr , * regulator ;
1513+
1514+ ptr = devres_alloc (devm_regulator_release , sizeof (* ptr ), GFP_KERNEL );
1515+ if (!ptr )
1516+ return ERR_PTR (- ENOMEM );
1517+
1518+ regulator = _regulator_get (dev , id , 1 );
1519+ if (!IS_ERR (regulator )) {
1520+ * ptr = regulator ;
1521+ devres_add (dev , ptr );
1522+ } else {
1523+ devres_free (ptr );
1524+ }
1525+
1526+ return regulator ;
1527+ }
1528+ EXPORT_SYMBOL_GPL (devm_regulator_get_exclusive );
1529+
14411530/**
14421531 * regulator_put - "free" the regulator source
14431532 * @regulator: regulator source
0 commit comments