diff options
Diffstat (limited to 'drivers/regulator/core.c')
-rw-r--r-- | drivers/regulator/core.c | 386 |
1 files changed, 316 insertions, 70 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index f511a406fca..01f7702a805 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -28,33 +28,7 @@ | |||
28 | static DEFINE_MUTEX(regulator_list_mutex); | 28 | static DEFINE_MUTEX(regulator_list_mutex); |
29 | static LIST_HEAD(regulator_list); | 29 | static LIST_HEAD(regulator_list); |
30 | static LIST_HEAD(regulator_map_list); | 30 | static LIST_HEAD(regulator_map_list); |
31 | 31 | static int has_full_constraints; | |
32 | /* | ||
33 | * struct regulator_dev | ||
34 | * | ||
35 | * Voltage / Current regulator class device. One for each regulator. | ||
36 | */ | ||
37 | struct regulator_dev { | ||
38 | struct regulator_desc *desc; | ||
39 | int use_count; | ||
40 | |||
41 | /* lists we belong to */ | ||
42 | struct list_head list; /* list of all regulators */ | ||
43 | struct list_head slist; /* list of supplied regulators */ | ||
44 | |||
45 | /* lists we own */ | ||
46 | struct list_head consumer_list; /* consumers we supply */ | ||
47 | struct list_head supply_list; /* regulators we supply */ | ||
48 | |||
49 | struct blocking_notifier_head notifier; | ||
50 | struct mutex mutex; /* consumer lock */ | ||
51 | struct module *owner; | ||
52 | struct device dev; | ||
53 | struct regulation_constraints *constraints; | ||
54 | struct regulator_dev *supply; /* for tree */ | ||
55 | |||
56 | void *reg_data; /* regulator_dev data */ | ||
57 | }; | ||
58 | 32 | ||
59 | /* | 33 | /* |
60 | * struct regulator_map | 34 | * struct regulator_map |
@@ -79,7 +53,6 @@ struct regulator { | |||
79 | int uA_load; | 53 | int uA_load; |
80 | int min_uV; | 54 | int min_uV; |
81 | int max_uV; | 55 | int max_uV; |
82 | int enabled; /* count of client enables */ | ||
83 | char *supply_name; | 56 | char *supply_name; |
84 | struct device_attribute dev_attr; | 57 | struct device_attribute dev_attr; |
85 | struct regulator_dev *rdev; | 58 | struct regulator_dev *rdev; |
@@ -312,6 +285,47 @@ static ssize_t regulator_state_show(struct device *dev, | |||
312 | } | 285 | } |
313 | static DEVICE_ATTR(state, 0444, regulator_state_show, NULL); | 286 | static DEVICE_ATTR(state, 0444, regulator_state_show, NULL); |
314 | 287 | ||
288 | static ssize_t regulator_status_show(struct device *dev, | ||
289 | struct device_attribute *attr, char *buf) | ||
290 | { | ||
291 | struct regulator_dev *rdev = dev_get_drvdata(dev); | ||
292 | int status; | ||
293 | char *label; | ||
294 | |||
295 | status = rdev->desc->ops->get_status(rdev); | ||
296 | if (status < 0) | ||
297 | return status; | ||
298 | |||
299 | switch (status) { | ||
300 | case REGULATOR_STATUS_OFF: | ||
301 | label = "off"; | ||
302 | break; | ||
303 | case REGULATOR_STATUS_ON: | ||
304 | label = "on"; | ||
305 | break; | ||
306 | case REGULATOR_STATUS_ERROR: | ||
307 | label = "error"; | ||
308 | break; | ||
309 | case REGULATOR_STATUS_FAST: | ||
310 | label = "fast"; | ||
311 | break; | ||
312 | case REGULATOR_STATUS_NORMAL: | ||
313 | label = "normal"; | ||
314 | break; | ||
315 | case REGULATOR_STATUS_IDLE: | ||
316 | label = "idle"; | ||
317 | break; | ||
318 | case REGULATOR_STATUS_STANDBY: | ||
319 | label = "standby"; | ||
320 | break; | ||
321 | default: | ||
322 | return -ERANGE; | ||
323 | } | ||
324 | |||
325 | return sprintf(buf, "%s\n", label); | ||
326 | } | ||
327 | static DEVICE_ATTR(status, 0444, regulator_status_show, NULL); | ||
328 | |||
315 | static ssize_t regulator_min_uA_show(struct device *dev, | 329 | static ssize_t regulator_min_uA_show(struct device *dev, |
316 | struct device_attribute *attr, char *buf) | 330 | struct device_attribute *attr, char *buf) |
317 | { | 331 | { |
@@ -678,6 +692,73 @@ static int set_machine_constraints(struct regulator_dev *rdev, | |||
678 | else | 692 | else |
679 | name = "regulator"; | 693 | name = "regulator"; |
680 | 694 | ||
695 | /* constrain machine-level voltage specs to fit | ||
696 | * the actual range supported by this regulator. | ||
697 | */ | ||
698 | if (ops->list_voltage && rdev->desc->n_voltages) { | ||
699 | int count = rdev->desc->n_voltages; | ||
700 | int i; | ||
701 | int min_uV = INT_MAX; | ||
702 | int max_uV = INT_MIN; | ||
703 | int cmin = constraints->min_uV; | ||
704 | int cmax = constraints->max_uV; | ||
705 | |||
706 | /* it's safe to autoconfigure fixed-voltage supplies */ | ||
707 | if (count == 1 && !cmin) { | ||
708 | cmin = INT_MIN; | ||
709 | cmax = INT_MAX; | ||
710 | } | ||
711 | |||
712 | /* voltage constraints are optional */ | ||
713 | if ((cmin == 0) && (cmax == 0)) | ||
714 | goto out; | ||
715 | |||
716 | /* else require explicit machine-level constraints */ | ||
717 | if (cmin <= 0 || cmax <= 0 || cmax < cmin) { | ||
718 | pr_err("%s: %s '%s' voltage constraints\n", | ||
719 | __func__, "invalid", name); | ||
720 | ret = -EINVAL; | ||
721 | goto out; | ||
722 | } | ||
723 | |||
724 | /* initial: [cmin..cmax] valid, [min_uV..max_uV] not */ | ||
725 | for (i = 0; i < count; i++) { | ||
726 | int value; | ||
727 | |||
728 | value = ops->list_voltage(rdev, i); | ||
729 | if (value <= 0) | ||
730 | continue; | ||
731 | |||
732 | /* maybe adjust [min_uV..max_uV] */ | ||
733 | if (value >= cmin && value < min_uV) | ||
734 | min_uV = value; | ||
735 | if (value <= cmax && value > max_uV) | ||
736 | max_uV = value; | ||
737 | } | ||
738 | |||
739 | /* final: [min_uV..max_uV] valid iff constraints valid */ | ||
740 | if (max_uV < min_uV) { | ||
741 | pr_err("%s: %s '%s' voltage constraints\n", | ||
742 | __func__, "unsupportable", name); | ||
743 | ret = -EINVAL; | ||
744 | goto out; | ||
745 | } | ||
746 | |||
747 | /* use regulator's subset of machine constraints */ | ||
748 | if (constraints->min_uV < min_uV) { | ||
749 | pr_debug("%s: override '%s' %s, %d -> %d\n", | ||
750 | __func__, name, "min_uV", | ||
751 | constraints->min_uV, min_uV); | ||
752 | constraints->min_uV = min_uV; | ||
753 | } | ||
754 | if (constraints->max_uV > max_uV) { | ||
755 | pr_debug("%s: override '%s' %s, %d -> %d\n", | ||
756 | __func__, name, "max_uV", | ||
757 | constraints->max_uV, max_uV); | ||
758 | constraints->max_uV = max_uV; | ||
759 | } | ||
760 | } | ||
761 | |||
681 | rdev->constraints = constraints; | 762 | rdev->constraints = constraints; |
682 | 763 | ||
683 | /* do we need to apply the constraint voltage */ | 764 | /* do we need to apply the constraint voltage */ |
@@ -695,10 +776,6 @@ static int set_machine_constraints(struct regulator_dev *rdev, | |||
695 | } | 776 | } |
696 | } | 777 | } |
697 | 778 | ||
698 | /* are we enabled at boot time by firmware / bootloader */ | ||
699 | if (rdev->constraints->boot_on) | ||
700 | rdev->use_count = 1; | ||
701 | |||
702 | /* do we need to setup our suspend state */ | 779 | /* do we need to setup our suspend state */ |
703 | if (constraints->initial_state) { | 780 | if (constraints->initial_state) { |
704 | ret = suspend_prepare(rdev, constraints->initial_state); | 781 | ret = suspend_prepare(rdev, constraints->initial_state); |
@@ -710,11 +787,27 @@ static int set_machine_constraints(struct regulator_dev *rdev, | |||
710 | } | 787 | } |
711 | } | 788 | } |
712 | 789 | ||
713 | /* if always_on is set then turn the regulator on if it's not | 790 | if (constraints->initial_mode) { |
714 | * already on. */ | 791 | if (!ops->set_mode) { |
715 | if (constraints->always_on && ops->enable && | 792 | printk(KERN_ERR "%s: no set_mode operation for %s\n", |
716 | ((ops->is_enabled && !ops->is_enabled(rdev)) || | 793 | __func__, name); |
717 | (!ops->is_enabled && !constraints->boot_on))) { | 794 | ret = -EINVAL; |
795 | goto out; | ||
796 | } | ||
797 | |||
798 | ret = ops->set_mode(rdev, constraints->initial_mode); | ||
799 | if (ret < 0) { | ||
800 | printk(KERN_ERR | ||
801 | "%s: failed to set initial mode for %s: %d\n", | ||
802 | __func__, name, ret); | ||
803 | goto out; | ||
804 | } | ||
805 | } | ||
806 | |||
807 | /* If the constraints say the regulator should be on at this point | ||
808 | * and we have control then make sure it is enabled. | ||
809 | */ | ||
810 | if ((constraints->always_on || constraints->boot_on) && ops->enable) { | ||
718 | ret = ops->enable(rdev); | 811 | ret = ops->enable(rdev); |
719 | if (ret < 0) { | 812 | if (ret < 0) { |
720 | printk(KERN_ERR "%s: failed to enable %s\n", | 813 | printk(KERN_ERR "%s: failed to enable %s\n", |
@@ -817,6 +910,19 @@ static void unset_consumer_device_supply(struct regulator_dev *rdev, | |||
817 | } | 910 | } |
818 | } | 911 | } |
819 | 912 | ||
913 | static void unset_regulator_supplies(struct regulator_dev *rdev) | ||
914 | { | ||
915 | struct regulator_map *node, *n; | ||
916 | |||
917 | list_for_each_entry_safe(node, n, ®ulator_map_list, list) { | ||
918 | if (rdev == node->regulator) { | ||
919 | list_del(&node->list); | ||
920 | kfree(node); | ||
921 | return; | ||
922 | } | ||
923 | } | ||
924 | } | ||
925 | |||
820 | #define REG_STR_SIZE 32 | 926 | #define REG_STR_SIZE 32 |
821 | 927 | ||
822 | static struct regulator *create_regulator(struct regulator_dev *rdev, | 928 | static struct regulator *create_regulator(struct regulator_dev *rdev, |
@@ -898,9 +1004,12 @@ overflow_err: | |||
898 | * @id: Supply name or regulator ID. | 1004 | * @id: Supply name or regulator ID. |
899 | * | 1005 | * |
900 | * Returns a struct regulator corresponding to the regulator producer, | 1006 | * Returns a struct regulator corresponding to the regulator producer, |
901 | * or IS_ERR() condition containing errno. Use of supply names | 1007 | * or IS_ERR() condition containing errno. |
902 | * configured via regulator_set_device_supply() is strongly | 1008 | * |
903 | * encouraged. | 1009 | * Use of supply names configured via regulator_set_device_supply() is |
1010 | * strongly encouraged. It is recommended that the supply name used | ||
1011 | * should match the name used for the supply and/or the relevant | ||
1012 | * device pins in the datasheet. | ||
904 | */ | 1013 | */ |
905 | struct regulator *regulator_get(struct device *dev, const char *id) | 1014 | struct regulator *regulator_get(struct device *dev, const char *id) |
906 | { | 1015 | { |
@@ -922,8 +1031,6 @@ struct regulator *regulator_get(struct device *dev, const char *id) | |||
922 | goto found; | 1031 | goto found; |
923 | } | 1032 | } |
924 | } | 1033 | } |
925 | printk(KERN_ERR "regulator: Unable to get requested regulator: %s\n", | ||
926 | id); | ||
927 | mutex_unlock(®ulator_list_mutex); | 1034 | mutex_unlock(®ulator_list_mutex); |
928 | return regulator; | 1035 | return regulator; |
929 | 1036 | ||
@@ -961,10 +1068,6 @@ void regulator_put(struct regulator *regulator) | |||
961 | mutex_lock(®ulator_list_mutex); | 1068 | mutex_lock(®ulator_list_mutex); |
962 | rdev = regulator->rdev; | 1069 | rdev = regulator->rdev; |
963 | 1070 | ||
964 | if (WARN(regulator->enabled, "Releasing supply %s while enabled\n", | ||
965 | regulator->supply_name)) | ||
966 | _regulator_disable(rdev); | ||
967 | |||
968 | /* remove any sysfs entries */ | 1071 | /* remove any sysfs entries */ |
969 | if (regulator->dev) { | 1072 | if (regulator->dev) { |
970 | sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name); | 1073 | sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name); |
@@ -1039,12 +1142,7 @@ int regulator_enable(struct regulator *regulator) | |||
1039 | int ret = 0; | 1142 | int ret = 0; |
1040 | 1143 | ||
1041 | mutex_lock(&rdev->mutex); | 1144 | mutex_lock(&rdev->mutex); |
1042 | if (regulator->enabled == 0) | 1145 | ret = _regulator_enable(rdev); |
1043 | ret = _regulator_enable(rdev); | ||
1044 | else if (regulator->enabled < 0) | ||
1045 | ret = -EIO; | ||
1046 | if (ret == 0) | ||
1047 | regulator->enabled++; | ||
1048 | mutex_unlock(&rdev->mutex); | 1146 | mutex_unlock(&rdev->mutex); |
1049 | return ret; | 1147 | return ret; |
1050 | } | 1148 | } |
@@ -1055,6 +1153,11 @@ static int _regulator_disable(struct regulator_dev *rdev) | |||
1055 | { | 1153 | { |
1056 | int ret = 0; | 1154 | int ret = 0; |
1057 | 1155 | ||
1156 | if (WARN(rdev->use_count <= 0, | ||
1157 | "unbalanced disables for %s\n", | ||
1158 | rdev->desc->name)) | ||
1159 | return -EIO; | ||
1160 | |||
1058 | /* are we the last user and permitted to disable ? */ | 1161 | /* are we the last user and permitted to disable ? */ |
1059 | if (rdev->use_count == 1 && !rdev->constraints->always_on) { | 1162 | if (rdev->use_count == 1 && !rdev->constraints->always_on) { |
1060 | 1163 | ||
@@ -1103,16 +1206,7 @@ int regulator_disable(struct regulator *regulator) | |||
1103 | int ret = 0; | 1206 | int ret = 0; |
1104 | 1207 | ||
1105 | mutex_lock(&rdev->mutex); | 1208 | mutex_lock(&rdev->mutex); |
1106 | if (regulator->enabled == 1) { | 1209 | ret = _regulator_disable(rdev); |
1107 | ret = _regulator_disable(rdev); | ||
1108 | if (ret == 0) | ||
1109 | regulator->uA_load = 0; | ||
1110 | } else if (WARN(regulator->enabled <= 0, | ||
1111 | "unbalanced disables for supply %s\n", | ||
1112 | regulator->supply_name)) | ||
1113 | ret = -EIO; | ||
1114 | if (ret == 0) | ||
1115 | regulator->enabled--; | ||
1116 | mutex_unlock(&rdev->mutex); | 1210 | mutex_unlock(&rdev->mutex); |
1117 | return ret; | 1211 | return ret; |
1118 | } | 1212 | } |
@@ -1159,7 +1253,6 @@ int regulator_force_disable(struct regulator *regulator) | |||
1159 | int ret; | 1253 | int ret; |
1160 | 1254 | ||
1161 | mutex_lock(®ulator->rdev->mutex); | 1255 | mutex_lock(®ulator->rdev->mutex); |
1162 | regulator->enabled = 0; | ||
1163 | regulator->uA_load = 0; | 1256 | regulator->uA_load = 0; |
1164 | ret = _regulator_force_disable(regulator->rdev); | 1257 | ret = _regulator_force_disable(regulator->rdev); |
1165 | mutex_unlock(®ulator->rdev->mutex); | 1258 | mutex_unlock(®ulator->rdev->mutex); |
@@ -1204,6 +1297,56 @@ int regulator_is_enabled(struct regulator *regulator) | |||
1204 | EXPORT_SYMBOL_GPL(regulator_is_enabled); | 1297 | EXPORT_SYMBOL_GPL(regulator_is_enabled); |
1205 | 1298 | ||
1206 | /** | 1299 | /** |
1300 | * regulator_count_voltages - count regulator_list_voltage() selectors | ||
1301 | * @regulator: regulator source | ||
1302 | * | ||
1303 | * Returns number of selectors, or negative errno. Selectors are | ||
1304 | * numbered starting at zero, and typically correspond to bitfields | ||
1305 | * in hardware registers. | ||
1306 | */ | ||
1307 | int regulator_count_voltages(struct regulator *regulator) | ||
1308 | { | ||
1309 | struct regulator_dev *rdev = regulator->rdev; | ||
1310 | |||
1311 | return rdev->desc->n_voltages ? : -EINVAL; | ||
1312 | } | ||
1313 | EXPORT_SYMBOL_GPL(regulator_count_voltages); | ||
1314 | |||
1315 | /** | ||
1316 | * regulator_list_voltage - enumerate supported voltages | ||
1317 | * @regulator: regulator source | ||
1318 | * @selector: identify voltage to list | ||
1319 | * Context: can sleep | ||
1320 | * | ||
1321 | * Returns a voltage that can be passed to @regulator_set_voltage(), | ||
1322 | * zero if this selector code can't be used on this sytem, or a | ||
1323 | * negative errno. | ||
1324 | */ | ||
1325 | int regulator_list_voltage(struct regulator *regulator, unsigned selector) | ||
1326 | { | ||
1327 | struct regulator_dev *rdev = regulator->rdev; | ||
1328 | struct regulator_ops *ops = rdev->desc->ops; | ||
1329 | int ret; | ||
1330 | |||
1331 | if (!ops->list_voltage || selector >= rdev->desc->n_voltages) | ||
1332 | return -EINVAL; | ||
1333 | |||
1334 | mutex_lock(&rdev->mutex); | ||
1335 | ret = ops->list_voltage(rdev, selector); | ||
1336 | mutex_unlock(&rdev->mutex); | ||
1337 | |||
1338 | if (ret > 0) { | ||
1339 | if (ret < rdev->constraints->min_uV) | ||
1340 | ret = 0; | ||
1341 | else if (ret > rdev->constraints->max_uV) | ||
1342 | ret = 0; | ||
1343 | } | ||
1344 | |||
1345 | return ret; | ||
1346 | } | ||
1347 | EXPORT_SYMBOL_GPL(regulator_list_voltage); | ||
1348 | |||
1349 | /** | ||
1207 | * regulator_set_voltage - set regulator output voltage | 1350 | * regulator_set_voltage - set regulator output voltage |
1208 | * @regulator: regulator source | 1351 | * @regulator: regulator source |
1209 | * @min_uV: Minimum required voltage in uV | 1352 | * @min_uV: Minimum required voltage in uV |
@@ -1243,6 +1386,7 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) | |||
1243 | ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV); | 1386 | ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV); |
1244 | 1387 | ||
1245 | out: | 1388 | out: |
1389 | _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, NULL); | ||
1246 | mutex_unlock(&rdev->mutex); | 1390 | mutex_unlock(&rdev->mutex); |
1247 | return ret; | 1391 | return ret; |
1248 | } | 1392 | } |
@@ -1543,20 +1687,23 @@ int regulator_unregister_notifier(struct regulator *regulator, | |||
1543 | } | 1687 | } |
1544 | EXPORT_SYMBOL_GPL(regulator_unregister_notifier); | 1688 | EXPORT_SYMBOL_GPL(regulator_unregister_notifier); |
1545 | 1689 | ||
1546 | /* notify regulator consumers and downstream regulator consumers */ | 1690 | /* notify regulator consumers and downstream regulator consumers. |
1691 | * Note mutex must be held by caller. | ||
1692 | */ | ||
1547 | static void _notifier_call_chain(struct regulator_dev *rdev, | 1693 | static void _notifier_call_chain(struct regulator_dev *rdev, |
1548 | unsigned long event, void *data) | 1694 | unsigned long event, void *data) |
1549 | { | 1695 | { |
1550 | struct regulator_dev *_rdev; | 1696 | struct regulator_dev *_rdev; |
1551 | 1697 | ||
1552 | /* call rdev chain first */ | 1698 | /* call rdev chain first */ |
1553 | mutex_lock(&rdev->mutex); | ||
1554 | blocking_notifier_call_chain(&rdev->notifier, event, NULL); | 1699 | blocking_notifier_call_chain(&rdev->notifier, event, NULL); |
1555 | mutex_unlock(&rdev->mutex); | ||
1556 | 1700 | ||
1557 | /* now notify regulator we supply */ | 1701 | /* now notify regulator we supply */ |
1558 | list_for_each_entry(_rdev, &rdev->supply_list, slist) | 1702 | list_for_each_entry(_rdev, &rdev->supply_list, slist) { |
1559 | _notifier_call_chain(_rdev, event, data); | 1703 | mutex_lock(&_rdev->mutex); |
1704 | _notifier_call_chain(_rdev, event, data); | ||
1705 | mutex_unlock(&_rdev->mutex); | ||
1706 | } | ||
1560 | } | 1707 | } |
1561 | 1708 | ||
1562 | /** | 1709 | /** |
@@ -1703,6 +1850,7 @@ EXPORT_SYMBOL_GPL(regulator_bulk_free); | |||
1703 | * | 1850 | * |
1704 | * Called by regulator drivers to notify clients a regulator event has | 1851 | * Called by regulator drivers to notify clients a regulator event has |
1705 | * occurred. We also notify regulator clients downstream. | 1852 | * occurred. We also notify regulator clients downstream. |
1853 | * Note lock must be held by caller. | ||
1706 | */ | 1854 | */ |
1707 | int regulator_notifier_call_chain(struct regulator_dev *rdev, | 1855 | int regulator_notifier_call_chain(struct regulator_dev *rdev, |
1708 | unsigned long event, void *data) | 1856 | unsigned long event, void *data) |
@@ -1744,6 +1892,11 @@ static int add_regulator_attributes(struct regulator_dev *rdev) | |||
1744 | if (status < 0) | 1892 | if (status < 0) |
1745 | return status; | 1893 | return status; |
1746 | } | 1894 | } |
1895 | if (ops->get_status) { | ||
1896 | status = device_create_file(dev, &dev_attr_status); | ||
1897 | if (status < 0) | ||
1898 | return status; | ||
1899 | } | ||
1747 | 1900 | ||
1748 | /* some attributes are type-specific */ | 1901 | /* some attributes are type-specific */ |
1749 | if (rdev->desc->type == REGULATOR_CURRENT) { | 1902 | if (rdev->desc->type == REGULATOR_CURRENT) { |
@@ -1828,17 +1981,18 @@ static int add_regulator_attributes(struct regulator_dev *rdev) | |||
1828 | * regulator_register - register regulator | 1981 | * regulator_register - register regulator |
1829 | * @regulator_desc: regulator to register | 1982 | * @regulator_desc: regulator to register |
1830 | * @dev: struct device for the regulator | 1983 | * @dev: struct device for the regulator |
1984 | * @init_data: platform provided init data, passed through by driver | ||
1831 | * @driver_data: private regulator data | 1985 | * @driver_data: private regulator data |
1832 | * | 1986 | * |
1833 | * Called by regulator drivers to register a regulator. | 1987 | * Called by regulator drivers to register a regulator. |
1834 | * Returns 0 on success. | 1988 | * Returns 0 on success. |
1835 | */ | 1989 | */ |
1836 | struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | 1990 | struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, |
1837 | struct device *dev, void *driver_data) | 1991 | struct device *dev, struct regulator_init_data *init_data, |
1992 | void *driver_data) | ||
1838 | { | 1993 | { |
1839 | static atomic_t regulator_no = ATOMIC_INIT(0); | 1994 | static atomic_t regulator_no = ATOMIC_INIT(0); |
1840 | struct regulator_dev *rdev; | 1995 | struct regulator_dev *rdev; |
1841 | struct regulator_init_data *init_data = dev->platform_data; | ||
1842 | int ret, i; | 1996 | int ret, i; |
1843 | 1997 | ||
1844 | if (regulator_desc == NULL) | 1998 | if (regulator_desc == NULL) |
@@ -1945,6 +2099,7 @@ void regulator_unregister(struct regulator_dev *rdev) | |||
1945 | return; | 2099 | return; |
1946 | 2100 | ||
1947 | mutex_lock(®ulator_list_mutex); | 2101 | mutex_lock(®ulator_list_mutex); |
2102 | unset_regulator_supplies(rdev); | ||
1948 | list_del(&rdev->list); | 2103 | list_del(&rdev->list); |
1949 | if (rdev->supply) | 2104 | if (rdev->supply) |
1950 | sysfs_remove_link(&rdev->dev.kobj, "supply"); | 2105 | sysfs_remove_link(&rdev->dev.kobj, "supply"); |
@@ -1989,6 +2144,23 @@ out: | |||
1989 | EXPORT_SYMBOL_GPL(regulator_suspend_prepare); | 2144 | EXPORT_SYMBOL_GPL(regulator_suspend_prepare); |
1990 | 2145 | ||
1991 | /** | 2146 | /** |
2147 | * regulator_has_full_constraints - the system has fully specified constraints | ||
2148 | * | ||
2149 | * Calling this function will cause the regulator API to disable all | ||
2150 | * regulators which have a zero use count and don't have an always_on | ||
2151 | * constraint in a late_initcall. | ||
2152 | * | ||
2153 | * The intention is that this will become the default behaviour in a | ||
2154 | * future kernel release so users are encouraged to use this facility | ||
2155 | * now. | ||
2156 | */ | ||
2157 | void regulator_has_full_constraints(void) | ||
2158 | { | ||
2159 | has_full_constraints = 1; | ||
2160 | } | ||
2161 | EXPORT_SYMBOL_GPL(regulator_has_full_constraints); | ||
2162 | |||
2163 | /** | ||
1992 | * rdev_get_drvdata - get rdev regulator driver data | 2164 | * rdev_get_drvdata - get rdev regulator driver data |
1993 | * @rdev: regulator | 2165 | * @rdev: regulator |
1994 | * | 2166 | * |
@@ -2055,3 +2227,77 @@ static int __init regulator_init(void) | |||
2055 | 2227 | ||
2056 | /* init early to allow our consumers to complete system booting */ | 2228 | /* init early to allow our consumers to complete system booting */ |
2057 | core_initcall(regulator_init); | 2229 | core_initcall(regulator_init); |
2230 | |||
2231 | static int __init regulator_init_complete(void) | ||
2232 | { | ||
2233 | struct regulator_dev *rdev; | ||
2234 | struct regulator_ops *ops; | ||
2235 | struct regulation_constraints *c; | ||
2236 | int enabled, ret; | ||
2237 | const char *name; | ||
2238 | |||
2239 | mutex_lock(®ulator_list_mutex); | ||
2240 | |||
2241 | /* If we have a full configuration then disable any regulators | ||
2242 | * which are not in use or always_on. This will become the | ||
2243 | * default behaviour in the future. | ||
2244 | */ | ||
2245 | list_for_each_entry(rdev, ®ulator_list, list) { | ||
2246 | ops = rdev->desc->ops; | ||
2247 | c = rdev->constraints; | ||
2248 | |||
2249 | if (c->name) | ||
2250 | name = c->name; | ||
2251 | else if (rdev->desc->name) | ||
2252 | name = rdev->desc->name; | ||
2253 | else | ||
2254 | name = "regulator"; | ||
2255 | |||
2256 | if (!ops->disable || c->always_on) | ||
2257 | continue; | ||
2258 | |||
2259 | mutex_lock(&rdev->mutex); | ||
2260 | |||
2261 | if (rdev->use_count) | ||
2262 | goto unlock; | ||
2263 | |||
2264 | /* If we can't read the status assume it's on. */ | ||
2265 | if (ops->is_enabled) | ||
2266 | enabled = ops->is_enabled(rdev); | ||
2267 | else | ||
2268 | enabled = 1; | ||
2269 | |||
2270 | if (!enabled) | ||
2271 | goto unlock; | ||
2272 | |||
2273 | if (has_full_constraints) { | ||
2274 | /* We log since this may kill the system if it | ||
2275 | * goes wrong. */ | ||
2276 | printk(KERN_INFO "%s: disabling %s\n", | ||
2277 | __func__, name); | ||
2278 | ret = ops->disable(rdev); | ||
2279 | if (ret != 0) { | ||
2280 | printk(KERN_ERR | ||
2281 | "%s: couldn't disable %s: %d\n", | ||
2282 | __func__, name, ret); | ||
2283 | } | ||
2284 | } else { | ||
2285 | /* The intention is that in future we will | ||
2286 | * assume that full constraints are provided | ||
2287 | * so warn even if we aren't going to do | ||
2288 | * anything here. | ||
2289 | */ | ||
2290 | printk(KERN_WARNING | ||
2291 | "%s: incomplete constraints, leaving %s on\n", | ||
2292 | __func__, name); | ||
2293 | } | ||
2294 | |||
2295 | unlock: | ||
2296 | mutex_unlock(&rdev->mutex); | ||
2297 | } | ||
2298 | |||
2299 | mutex_unlock(®ulator_list_mutex); | ||
2300 | |||
2301 | return 0; | ||
2302 | } | ||
2303 | late_initcall(regulator_init_complete); | ||