diff options
author | Mark Brown <broonie@kernel.org> | 2018-01-26 12:56:59 -0500 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2018-01-26 12:56:59 -0500 |
commit | 73d8003749ebfd9617076213c0033e11aacf823c (patch) | |
tree | 6a284aafe523cb456a380b3f539284989822ec86 | |
parent | 0c5b9b5d9adbad4b60491f9ba0d2af38904bb4b9 (diff) | |
parent | 00cb9f4f5ef5e98653d4726836a4482180bd2efd (diff) |
Merge remote-tracking branch 'regulator/topic/core' into regulator-next
-rw-r--r-- | Documentation/devicetree/bindings/regulator/regulator.txt | 12 | ||||
-rw-r--r-- | drivers/regulator/core.c | 383 | ||||
-rw-r--r-- | drivers/regulator/internal.h | 27 | ||||
-rw-r--r-- | drivers/regulator/of_regulator.c | 34 | ||||
-rw-r--r-- | include/linux/regulator/driver.h | 2 | ||||
-rw-r--r-- | include/linux/regulator/machine.h | 37 |
6 files changed, 340 insertions, 155 deletions
diff --git a/Documentation/devicetree/bindings/regulator/regulator.txt b/Documentation/devicetree/bindings/regulator/regulator.txt index 3cbf56ce66ea..2babe15b618d 100644 --- a/Documentation/devicetree/bindings/regulator/regulator.txt +++ b/Documentation/devicetree/bindings/regulator/regulator.txt | |||
@@ -42,8 +42,16 @@ Optional properties: | |||
42 | - regulator-state-[mem/disk] node has following common properties: | 42 | - regulator-state-[mem/disk] node has following common properties: |
43 | - regulator-on-in-suspend: regulator should be on in suspend state. | 43 | - regulator-on-in-suspend: regulator should be on in suspend state. |
44 | - regulator-off-in-suspend: regulator should be off in suspend state. | 44 | - regulator-off-in-suspend: regulator should be off in suspend state. |
45 | - regulator-suspend-microvolt: regulator should be set to this voltage | 45 | - regulator-suspend-min-microvolt: minimum voltage may be set in |
46 | in suspend. | 46 | suspend state. |
47 | - regulator-suspend-max-microvolt: maximum voltage may be set in | ||
48 | suspend state. | ||
49 | - regulator-suspend-microvolt: the default voltage which regulator | ||
50 | would be set in suspend. This property is now deprecated, instead | ||
51 | setting voltage for suspend mode via the API which regulator | ||
52 | driver provides is recommended. | ||
53 | - regulator-changeable-in-suspend: whether the default voltage and | ||
54 | the regulator on/off in suspend can be changed in runtime. | ||
47 | - regulator-mode: operating mode in the given suspend state. | 55 | - regulator-mode: operating mode in the given suspend state. |
48 | The set of possible operating modes depends on the capabilities of | 56 | The set of possible operating modes depends on the capabilities of |
49 | every hardware so the valid modes are documented on each regulator | 57 | every hardware so the valid modes are documented on each regulator |
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index b64b7916507f..42681c10cbe4 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -58,8 +58,6 @@ static bool has_full_constraints; | |||
58 | 58 | ||
59 | static struct dentry *debugfs_root; | 59 | static struct dentry *debugfs_root; |
60 | 60 | ||
61 | static struct class regulator_class; | ||
62 | |||
63 | /* | 61 | /* |
64 | * struct regulator_map | 62 | * struct regulator_map |
65 | * | 63 | * |
@@ -112,11 +110,6 @@ static struct regulator *create_regulator(struct regulator_dev *rdev, | |||
112 | const char *supply_name); | 110 | const char *supply_name); |
113 | static void _regulator_put(struct regulator *regulator); | 111 | static void _regulator_put(struct regulator *regulator); |
114 | 112 | ||
115 | static struct regulator_dev *dev_to_rdev(struct device *dev) | ||
116 | { | ||
117 | return container_of(dev, struct regulator_dev, dev); | ||
118 | } | ||
119 | |||
120 | static const char *rdev_get_name(struct regulator_dev *rdev) | 113 | static const char *rdev_get_name(struct regulator_dev *rdev) |
121 | { | 114 | { |
122 | if (rdev->constraints && rdev->constraints->name) | 115 | if (rdev->constraints && rdev->constraints->name) |
@@ -236,26 +229,35 @@ static int regulator_check_voltage(struct regulator_dev *rdev, | |||
236 | return 0; | 229 | return 0; |
237 | } | 230 | } |
238 | 231 | ||
232 | /* return 0 if the state is valid */ | ||
233 | static int regulator_check_states(suspend_state_t state) | ||
234 | { | ||
235 | return (state > PM_SUSPEND_MAX || state == PM_SUSPEND_TO_IDLE); | ||
236 | } | ||
237 | |||
239 | /* Make sure we select a voltage that suits the needs of all | 238 | /* Make sure we select a voltage that suits the needs of all |
240 | * regulator consumers | 239 | * regulator consumers |
241 | */ | 240 | */ |
242 | static int regulator_check_consumers(struct regulator_dev *rdev, | 241 | static int regulator_check_consumers(struct regulator_dev *rdev, |
243 | int *min_uV, int *max_uV) | 242 | int *min_uV, int *max_uV, |
243 | suspend_state_t state) | ||
244 | { | 244 | { |
245 | struct regulator *regulator; | 245 | struct regulator *regulator; |
246 | struct regulator_voltage *voltage; | ||
246 | 247 | ||
247 | list_for_each_entry(regulator, &rdev->consumer_list, list) { | 248 | list_for_each_entry(regulator, &rdev->consumer_list, list) { |
249 | voltage = ®ulator->voltage[state]; | ||
248 | /* | 250 | /* |
249 | * Assume consumers that didn't say anything are OK | 251 | * Assume consumers that didn't say anything are OK |
250 | * with anything in the constraint range. | 252 | * with anything in the constraint range. |
251 | */ | 253 | */ |
252 | if (!regulator->min_uV && !regulator->max_uV) | 254 | if (!voltage->min_uV && !voltage->max_uV) |
253 | continue; | 255 | continue; |
254 | 256 | ||
255 | if (*max_uV > regulator->max_uV) | 257 | if (*max_uV > voltage->max_uV) |
256 | *max_uV = regulator->max_uV; | 258 | *max_uV = voltage->max_uV; |
257 | if (*min_uV < regulator->min_uV) | 259 | if (*min_uV < voltage->min_uV) |
258 | *min_uV = regulator->min_uV; | 260 | *min_uV = voltage->min_uV; |
259 | } | 261 | } |
260 | 262 | ||
261 | if (*min_uV > *max_uV) { | 263 | if (*min_uV > *max_uV) { |
@@ -324,6 +326,24 @@ static int regulator_mode_constrain(struct regulator_dev *rdev, | |||
324 | return -EINVAL; | 326 | return -EINVAL; |
325 | } | 327 | } |
326 | 328 | ||
329 | static inline struct regulator_state * | ||
330 | regulator_get_suspend_state(struct regulator_dev *rdev, suspend_state_t state) | ||
331 | { | ||
332 | if (rdev->constraints == NULL) | ||
333 | return NULL; | ||
334 | |||
335 | switch (state) { | ||
336 | case PM_SUSPEND_STANDBY: | ||
337 | return &rdev->constraints->state_standby; | ||
338 | case PM_SUSPEND_MEM: | ||
339 | return &rdev->constraints->state_mem; | ||
340 | case PM_SUSPEND_MAX: | ||
341 | return &rdev->constraints->state_disk; | ||
342 | default: | ||
343 | return NULL; | ||
344 | } | ||
345 | } | ||
346 | |||
327 | static ssize_t regulator_uV_show(struct device *dev, | 347 | static ssize_t regulator_uV_show(struct device *dev, |
328 | struct device_attribute *attr, char *buf) | 348 | struct device_attribute *attr, char *buf) |
329 | { | 349 | { |
@@ -731,29 +751,32 @@ static int drms_uA_update(struct regulator_dev *rdev) | |||
731 | } | 751 | } |
732 | 752 | ||
733 | static int suspend_set_state(struct regulator_dev *rdev, | 753 | static int suspend_set_state(struct regulator_dev *rdev, |
734 | struct regulator_state *rstate) | 754 | suspend_state_t state) |
735 | { | 755 | { |
736 | int ret = 0; | 756 | int ret = 0; |
757 | struct regulator_state *rstate; | ||
758 | |||
759 | rstate = regulator_get_suspend_state(rdev, state); | ||
760 | if (rstate == NULL) | ||
761 | return -EINVAL; | ||
737 | 762 | ||
738 | /* If we have no suspend mode configration don't set anything; | 763 | /* If we have no suspend mode configration don't set anything; |
739 | * only warn if the driver implements set_suspend_voltage or | 764 | * only warn if the driver implements set_suspend_voltage or |
740 | * set_suspend_mode callback. | 765 | * set_suspend_mode callback. |
741 | */ | 766 | */ |
742 | if (!rstate->enabled && !rstate->disabled) { | 767 | if (rstate->enabled != ENABLE_IN_SUSPEND && |
768 | rstate->enabled != DISABLE_IN_SUSPEND) { | ||
743 | if (rdev->desc->ops->set_suspend_voltage || | 769 | if (rdev->desc->ops->set_suspend_voltage || |
744 | rdev->desc->ops->set_suspend_mode) | 770 | rdev->desc->ops->set_suspend_mode) |
745 | rdev_warn(rdev, "No configuration\n"); | 771 | rdev_warn(rdev, "No configuration\n"); |
746 | return 0; | 772 | return 0; |
747 | } | 773 | } |
748 | 774 | ||
749 | if (rstate->enabled && rstate->disabled) { | 775 | if (rstate->enabled == ENABLE_IN_SUSPEND && |
750 | rdev_err(rdev, "invalid configuration\n"); | 776 | rdev->desc->ops->set_suspend_enable) |
751 | return -EINVAL; | ||
752 | } | ||
753 | |||
754 | if (rstate->enabled && rdev->desc->ops->set_suspend_enable) | ||
755 | ret = rdev->desc->ops->set_suspend_enable(rdev); | 777 | ret = rdev->desc->ops->set_suspend_enable(rdev); |
756 | else if (rstate->disabled && rdev->desc->ops->set_suspend_disable) | 778 | else if (rstate->enabled == DISABLE_IN_SUSPEND && |
779 | rdev->desc->ops->set_suspend_disable) | ||
757 | ret = rdev->desc->ops->set_suspend_disable(rdev); | 780 | ret = rdev->desc->ops->set_suspend_disable(rdev); |
758 | else /* OK if set_suspend_enable or set_suspend_disable is NULL */ | 781 | else /* OK if set_suspend_enable or set_suspend_disable is NULL */ |
759 | ret = 0; | 782 | ret = 0; |
@@ -778,28 +801,8 @@ static int suspend_set_state(struct regulator_dev *rdev, | |||
778 | return ret; | 801 | return ret; |
779 | } | 802 | } |
780 | } | 803 | } |
781 | return ret; | ||
782 | } | ||
783 | |||
784 | /* locks held by caller */ | ||
785 | static int suspend_prepare(struct regulator_dev *rdev, suspend_state_t state) | ||
786 | { | ||
787 | if (!rdev->constraints) | ||
788 | return -EINVAL; | ||
789 | 804 | ||
790 | switch (state) { | 805 | return ret; |
791 | case PM_SUSPEND_STANDBY: | ||
792 | return suspend_set_state(rdev, | ||
793 | &rdev->constraints->state_standby); | ||
794 | case PM_SUSPEND_MEM: | ||
795 | return suspend_set_state(rdev, | ||
796 | &rdev->constraints->state_mem); | ||
797 | case PM_SUSPEND_MAX: | ||
798 | return suspend_set_state(rdev, | ||
799 | &rdev->constraints->state_disk); | ||
800 | default: | ||
801 | return -EINVAL; | ||
802 | } | ||
803 | } | 806 | } |
804 | 807 | ||
805 | static void print_constraints(struct regulator_dev *rdev) | 808 | static void print_constraints(struct regulator_dev *rdev) |
@@ -1068,7 +1071,7 @@ static int set_machine_constraints(struct regulator_dev *rdev, | |||
1068 | 1071 | ||
1069 | /* do we need to setup our suspend state */ | 1072 | /* do we need to setup our suspend state */ |
1070 | if (rdev->constraints->initial_state) { | 1073 | if (rdev->constraints->initial_state) { |
1071 | ret = suspend_prepare(rdev, rdev->constraints->initial_state); | 1074 | ret = suspend_set_state(rdev, rdev->constraints->initial_state); |
1072 | if (ret < 0) { | 1075 | if (ret < 0) { |
1073 | rdev_err(rdev, "failed to set suspend state\n"); | 1076 | rdev_err(rdev, "failed to set suspend state\n"); |
1074 | return ret; | 1077 | return ret; |
@@ -1356,9 +1359,9 @@ static struct regulator *create_regulator(struct regulator_dev *rdev, | |||
1356 | debugfs_create_u32("uA_load", 0444, regulator->debugfs, | 1359 | debugfs_create_u32("uA_load", 0444, regulator->debugfs, |
1357 | ®ulator->uA_load); | 1360 | ®ulator->uA_load); |
1358 | debugfs_create_u32("min_uV", 0444, regulator->debugfs, | 1361 | debugfs_create_u32("min_uV", 0444, regulator->debugfs, |
1359 | ®ulator->min_uV); | 1362 | ®ulator->voltage[PM_SUSPEND_ON].min_uV); |
1360 | debugfs_create_u32("max_uV", 0444, regulator->debugfs, | 1363 | debugfs_create_u32("max_uV", 0444, regulator->debugfs, |
1361 | ®ulator->max_uV); | 1364 | ®ulator->voltage[PM_SUSPEND_ON].max_uV); |
1362 | debugfs_create_file("constraint_flags", 0444, | 1365 | debugfs_create_file("constraint_flags", 0444, |
1363 | regulator->debugfs, regulator, | 1366 | regulator->debugfs, regulator, |
1364 | &constraint_flags_fops); | 1367 | &constraint_flags_fops); |
@@ -1417,20 +1420,6 @@ static void regulator_supply_alias(struct device **dev, const char **supply) | |||
1417 | } | 1420 | } |
1418 | } | 1421 | } |
1419 | 1422 | ||
1420 | static int of_node_match(struct device *dev, const void *data) | ||
1421 | { | ||
1422 | return dev->of_node == data; | ||
1423 | } | ||
1424 | |||
1425 | static struct regulator_dev *of_find_regulator_by_node(struct device_node *np) | ||
1426 | { | ||
1427 | struct device *dev; | ||
1428 | |||
1429 | dev = class_find_device(®ulator_class, NULL, np, of_node_match); | ||
1430 | |||
1431 | return dev ? dev_to_rdev(dev) : NULL; | ||
1432 | } | ||
1433 | |||
1434 | static int regulator_match(struct device *dev, const void *data) | 1423 | static int regulator_match(struct device *dev, const void *data) |
1435 | { | 1424 | { |
1436 | struct regulator_dev *r = dev_to_rdev(dev); | 1425 | struct regulator_dev *r = dev_to_rdev(dev); |
@@ -2468,10 +2457,9 @@ static int _regulator_is_enabled(struct regulator_dev *rdev) | |||
2468 | return rdev->desc->ops->is_enabled(rdev); | 2457 | return rdev->desc->ops->is_enabled(rdev); |
2469 | } | 2458 | } |
2470 | 2459 | ||
2471 | static int _regulator_list_voltage(struct regulator *regulator, | 2460 | static int _regulator_list_voltage(struct regulator_dev *rdev, |
2472 | unsigned selector, int lock) | 2461 | unsigned selector, int lock) |
2473 | { | 2462 | { |
2474 | struct regulator_dev *rdev = regulator->rdev; | ||
2475 | const struct regulator_ops *ops = rdev->desc->ops; | 2463 | const struct regulator_ops *ops = rdev->desc->ops; |
2476 | int ret; | 2464 | int ret; |
2477 | 2465 | ||
@@ -2487,7 +2475,8 @@ static int _regulator_list_voltage(struct regulator *regulator, | |||
2487 | if (lock) | 2475 | if (lock) |
2488 | mutex_unlock(&rdev->mutex); | 2476 | mutex_unlock(&rdev->mutex); |
2489 | } else if (rdev->is_switch && rdev->supply) { | 2477 | } else if (rdev->is_switch && rdev->supply) { |
2490 | ret = _regulator_list_voltage(rdev->supply, selector, lock); | 2478 | ret = _regulator_list_voltage(rdev->supply->rdev, |
2479 | selector, lock); | ||
2491 | } else { | 2480 | } else { |
2492 | return -EINVAL; | 2481 | return -EINVAL; |
2493 | } | 2482 | } |
@@ -2563,7 +2552,7 @@ EXPORT_SYMBOL_GPL(regulator_count_voltages); | |||
2563 | */ | 2552 | */ |
2564 | int regulator_list_voltage(struct regulator *regulator, unsigned selector) | 2553 | int regulator_list_voltage(struct regulator *regulator, unsigned selector) |
2565 | { | 2554 | { |
2566 | return _regulator_list_voltage(regulator, selector, 1); | 2555 | return _regulator_list_voltage(regulator->rdev, selector, 1); |
2567 | } | 2556 | } |
2568 | EXPORT_SYMBOL_GPL(regulator_list_voltage); | 2557 | EXPORT_SYMBOL_GPL(regulator_list_voltage); |
2569 | 2558 | ||
@@ -2605,8 +2594,8 @@ int regulator_get_hardware_vsel_register(struct regulator *regulator, | |||
2605 | if (ops->set_voltage_sel != regulator_set_voltage_sel_regmap) | 2594 | if (ops->set_voltage_sel != regulator_set_voltage_sel_regmap) |
2606 | return -EOPNOTSUPP; | 2595 | return -EOPNOTSUPP; |
2607 | 2596 | ||
2608 | *vsel_reg = rdev->desc->vsel_reg; | 2597 | *vsel_reg = rdev->desc->vsel_reg; |
2609 | *vsel_mask = rdev->desc->vsel_mask; | 2598 | *vsel_mask = rdev->desc->vsel_mask; |
2610 | 2599 | ||
2611 | return 0; | 2600 | return 0; |
2612 | } | 2601 | } |
@@ -2897,10 +2886,38 @@ out: | |||
2897 | return ret; | 2886 | return ret; |
2898 | } | 2887 | } |
2899 | 2888 | ||
2889 | static int _regulator_do_set_suspend_voltage(struct regulator_dev *rdev, | ||
2890 | int min_uV, int max_uV, suspend_state_t state) | ||
2891 | { | ||
2892 | struct regulator_state *rstate; | ||
2893 | int uV, sel; | ||
2894 | |||
2895 | rstate = regulator_get_suspend_state(rdev, state); | ||
2896 | if (rstate == NULL) | ||
2897 | return -EINVAL; | ||
2898 | |||
2899 | if (min_uV < rstate->min_uV) | ||
2900 | min_uV = rstate->min_uV; | ||
2901 | if (max_uV > rstate->max_uV) | ||
2902 | max_uV = rstate->max_uV; | ||
2903 | |||
2904 | sel = regulator_map_voltage(rdev, min_uV, max_uV); | ||
2905 | if (sel < 0) | ||
2906 | return sel; | ||
2907 | |||
2908 | uV = rdev->desc->ops->list_voltage(rdev, sel); | ||
2909 | if (uV >= min_uV && uV <= max_uV) | ||
2910 | rstate->uV = uV; | ||
2911 | |||
2912 | return 0; | ||
2913 | } | ||
2914 | |||
2900 | static int regulator_set_voltage_unlocked(struct regulator *regulator, | 2915 | static int regulator_set_voltage_unlocked(struct regulator *regulator, |
2901 | int min_uV, int max_uV) | 2916 | int min_uV, int max_uV, |
2917 | suspend_state_t state) | ||
2902 | { | 2918 | { |
2903 | struct regulator_dev *rdev = regulator->rdev; | 2919 | struct regulator_dev *rdev = regulator->rdev; |
2920 | struct regulator_voltage *voltage = ®ulator->voltage[state]; | ||
2904 | int ret = 0; | 2921 | int ret = 0; |
2905 | int old_min_uV, old_max_uV; | 2922 | int old_min_uV, old_max_uV; |
2906 | int current_uV; | 2923 | int current_uV; |
@@ -2911,7 +2928,7 @@ static int regulator_set_voltage_unlocked(struct regulator *regulator, | |||
2911 | * should be a noop (some cpufreq implementations use the same | 2928 | * should be a noop (some cpufreq implementations use the same |
2912 | * voltage for multiple frequencies, for example). | 2929 | * voltage for multiple frequencies, for example). |
2913 | */ | 2930 | */ |
2914 | if (regulator->min_uV == min_uV && regulator->max_uV == max_uV) | 2931 | if (voltage->min_uV == min_uV && voltage->max_uV == max_uV) |
2915 | goto out; | 2932 | goto out; |
2916 | 2933 | ||
2917 | /* If we're trying to set a range that overlaps the current voltage, | 2934 | /* If we're trying to set a range that overlaps the current voltage, |
@@ -2921,8 +2938,8 @@ static int regulator_set_voltage_unlocked(struct regulator *regulator, | |||
2921 | if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) { | 2938 | if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) { |
2922 | current_uV = _regulator_get_voltage(rdev); | 2939 | current_uV = _regulator_get_voltage(rdev); |
2923 | if (min_uV <= current_uV && current_uV <= max_uV) { | 2940 | if (min_uV <= current_uV && current_uV <= max_uV) { |
2924 | regulator->min_uV = min_uV; | 2941 | voltage->min_uV = min_uV; |
2925 | regulator->max_uV = max_uV; | 2942 | voltage->max_uV = max_uV; |
2926 | goto out; | 2943 | goto out; |
2927 | } | 2944 | } |
2928 | } | 2945 | } |
@@ -2940,12 +2957,12 @@ static int regulator_set_voltage_unlocked(struct regulator *regulator, | |||
2940 | goto out; | 2957 | goto out; |
2941 | 2958 | ||
2942 | /* restore original values in case of error */ | 2959 | /* restore original values in case of error */ |
2943 | old_min_uV = regulator->min_uV; | 2960 | old_min_uV = voltage->min_uV; |
2944 | old_max_uV = regulator->max_uV; | 2961 | old_max_uV = voltage->max_uV; |
2945 | regulator->min_uV = min_uV; | 2962 | voltage->min_uV = min_uV; |
2946 | regulator->max_uV = max_uV; | 2963 | voltage->max_uV = max_uV; |
2947 | 2964 | ||
2948 | ret = regulator_check_consumers(rdev, &min_uV, &max_uV); | 2965 | ret = regulator_check_consumers(rdev, &min_uV, &max_uV, state); |
2949 | if (ret < 0) | 2966 | if (ret < 0) |
2950 | goto out2; | 2967 | goto out2; |
2951 | 2968 | ||
@@ -2963,7 +2980,7 @@ static int regulator_set_voltage_unlocked(struct regulator *regulator, | |||
2963 | goto out2; | 2980 | goto out2; |
2964 | } | 2981 | } |
2965 | 2982 | ||
2966 | best_supply_uV = _regulator_list_voltage(regulator, selector, 0); | 2983 | best_supply_uV = _regulator_list_voltage(rdev, selector, 0); |
2967 | if (best_supply_uV < 0) { | 2984 | if (best_supply_uV < 0) { |
2968 | ret = best_supply_uV; | 2985 | ret = best_supply_uV; |
2969 | goto out2; | 2986 | goto out2; |
@@ -2982,7 +2999,7 @@ static int regulator_set_voltage_unlocked(struct regulator *regulator, | |||
2982 | 2999 | ||
2983 | if (supply_change_uV > 0) { | 3000 | if (supply_change_uV > 0) { |
2984 | ret = regulator_set_voltage_unlocked(rdev->supply, | 3001 | ret = regulator_set_voltage_unlocked(rdev->supply, |
2985 | best_supply_uV, INT_MAX); | 3002 | best_supply_uV, INT_MAX, state); |
2986 | if (ret) { | 3003 | if (ret) { |
2987 | dev_err(&rdev->dev, "Failed to increase supply voltage: %d\n", | 3004 | dev_err(&rdev->dev, "Failed to increase supply voltage: %d\n", |
2988 | ret); | 3005 | ret); |
@@ -2990,13 +3007,17 @@ static int regulator_set_voltage_unlocked(struct regulator *regulator, | |||
2990 | } | 3007 | } |
2991 | } | 3008 | } |
2992 | 3009 | ||
2993 | ret = _regulator_do_set_voltage(rdev, min_uV, max_uV); | 3010 | if (state == PM_SUSPEND_ON) |
3011 | ret = _regulator_do_set_voltage(rdev, min_uV, max_uV); | ||
3012 | else | ||
3013 | ret = _regulator_do_set_suspend_voltage(rdev, min_uV, | ||
3014 | max_uV, state); | ||
2994 | if (ret < 0) | 3015 | if (ret < 0) |
2995 | goto out2; | 3016 | goto out2; |
2996 | 3017 | ||
2997 | if (supply_change_uV < 0) { | 3018 | if (supply_change_uV < 0) { |
2998 | ret = regulator_set_voltage_unlocked(rdev->supply, | 3019 | ret = regulator_set_voltage_unlocked(rdev->supply, |
2999 | best_supply_uV, INT_MAX); | 3020 | best_supply_uV, INT_MAX, state); |
3000 | if (ret) | 3021 | if (ret) |
3001 | dev_warn(&rdev->dev, "Failed to decrease supply voltage: %d\n", | 3022 | dev_warn(&rdev->dev, "Failed to decrease supply voltage: %d\n", |
3002 | ret); | 3023 | ret); |
@@ -3007,8 +3028,8 @@ static int regulator_set_voltage_unlocked(struct regulator *regulator, | |||
3007 | out: | 3028 | out: |
3008 | return ret; | 3029 | return ret; |
3009 | out2: | 3030 | out2: |
3010 | regulator->min_uV = old_min_uV; | 3031 | voltage->min_uV = old_min_uV; |
3011 | regulator->max_uV = old_max_uV; | 3032 | voltage->max_uV = old_max_uV; |
3012 | 3033 | ||
3013 | return ret; | 3034 | return ret; |
3014 | } | 3035 | } |
@@ -3037,7 +3058,8 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) | |||
3037 | 3058 | ||
3038 | regulator_lock_supply(regulator->rdev); | 3059 | regulator_lock_supply(regulator->rdev); |
3039 | 3060 | ||
3040 | ret = regulator_set_voltage_unlocked(regulator, min_uV, max_uV); | 3061 | ret = regulator_set_voltage_unlocked(regulator, min_uV, max_uV, |
3062 | PM_SUSPEND_ON); | ||
3041 | 3063 | ||
3042 | regulator_unlock_supply(regulator->rdev); | 3064 | regulator_unlock_supply(regulator->rdev); |
3043 | 3065 | ||
@@ -3045,6 +3067,89 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) | |||
3045 | } | 3067 | } |
3046 | EXPORT_SYMBOL_GPL(regulator_set_voltage); | 3068 | EXPORT_SYMBOL_GPL(regulator_set_voltage); |
3047 | 3069 | ||
3070 | static inline int regulator_suspend_toggle(struct regulator_dev *rdev, | ||
3071 | suspend_state_t state, bool en) | ||
3072 | { | ||
3073 | struct regulator_state *rstate; | ||
3074 | |||
3075 | rstate = regulator_get_suspend_state(rdev, state); | ||
3076 | if (rstate == NULL) | ||
3077 | return -EINVAL; | ||
3078 | |||
3079 | if (!rstate->changeable) | ||
3080 | return -EPERM; | ||
3081 | |||
3082 | rstate->enabled = en; | ||
3083 | |||
3084 | return 0; | ||
3085 | } | ||
3086 | |||
3087 | int regulator_suspend_enable(struct regulator_dev *rdev, | ||
3088 | suspend_state_t state) | ||
3089 | { | ||
3090 | return regulator_suspend_toggle(rdev, state, true); | ||
3091 | } | ||
3092 | EXPORT_SYMBOL_GPL(regulator_suspend_enable); | ||
3093 | |||
3094 | int regulator_suspend_disable(struct regulator_dev *rdev, | ||
3095 | suspend_state_t state) | ||
3096 | { | ||
3097 | struct regulator *regulator; | ||
3098 | struct regulator_voltage *voltage; | ||
3099 | |||
3100 | /* | ||
3101 | * if any consumer wants this regulator device keeping on in | ||
3102 | * suspend states, don't set it as disabled. | ||
3103 | */ | ||
3104 | list_for_each_entry(regulator, &rdev->consumer_list, list) { | ||
3105 | voltage = ®ulator->voltage[state]; | ||
3106 | if (voltage->min_uV || voltage->max_uV) | ||
3107 | return 0; | ||
3108 | } | ||
3109 | |||
3110 | return regulator_suspend_toggle(rdev, state, false); | ||
3111 | } | ||
3112 | EXPORT_SYMBOL_GPL(regulator_suspend_disable); | ||
3113 | |||
3114 | static int _regulator_set_suspend_voltage(struct regulator *regulator, | ||
3115 | int min_uV, int max_uV, | ||
3116 | suspend_state_t state) | ||
3117 | { | ||
3118 | struct regulator_dev *rdev = regulator->rdev; | ||
3119 | struct regulator_state *rstate; | ||
3120 | |||
3121 | rstate = regulator_get_suspend_state(rdev, state); | ||
3122 | if (rstate == NULL) | ||
3123 | return -EINVAL; | ||
3124 | |||
3125 | if (rstate->min_uV == rstate->max_uV) { | ||
3126 | rdev_err(rdev, "The suspend voltage can't be changed!\n"); | ||
3127 | return -EPERM; | ||
3128 | } | ||
3129 | |||
3130 | return regulator_set_voltage_unlocked(regulator, min_uV, max_uV, state); | ||
3131 | } | ||
3132 | |||
3133 | int regulator_set_suspend_voltage(struct regulator *regulator, int min_uV, | ||
3134 | int max_uV, suspend_state_t state) | ||
3135 | { | ||
3136 | int ret = 0; | ||
3137 | |||
3138 | /* PM_SUSPEND_ON is handled by regulator_set_voltage() */ | ||
3139 | if (regulator_check_states(state) || state == PM_SUSPEND_ON) | ||
3140 | return -EINVAL; | ||
3141 | |||
3142 | regulator_lock_supply(regulator->rdev); | ||
3143 | |||
3144 | ret = _regulator_set_suspend_voltage(regulator, min_uV, | ||
3145 | max_uV, state); | ||
3146 | |||
3147 | regulator_unlock_supply(regulator->rdev); | ||
3148 | |||
3149 | return ret; | ||
3150 | } | ||
3151 | EXPORT_SYMBOL_GPL(regulator_set_suspend_voltage); | ||
3152 | |||
3048 | /** | 3153 | /** |
3049 | * regulator_set_voltage_time - get raise/fall time | 3154 | * regulator_set_voltage_time - get raise/fall time |
3050 | * @regulator: regulator source | 3155 | * @regulator: regulator source |
@@ -3138,6 +3243,7 @@ EXPORT_SYMBOL_GPL(regulator_set_voltage_time_sel); | |||
3138 | int regulator_sync_voltage(struct regulator *regulator) | 3243 | int regulator_sync_voltage(struct regulator *regulator) |
3139 | { | 3244 | { |
3140 | struct regulator_dev *rdev = regulator->rdev; | 3245 | struct regulator_dev *rdev = regulator->rdev; |
3246 | struct regulator_voltage *voltage = ®ulator->voltage[PM_SUSPEND_ON]; | ||
3141 | int ret, min_uV, max_uV; | 3247 | int ret, min_uV, max_uV; |
3142 | 3248 | ||
3143 | mutex_lock(&rdev->mutex); | 3249 | mutex_lock(&rdev->mutex); |
@@ -3149,20 +3255,20 @@ int regulator_sync_voltage(struct regulator *regulator) | |||
3149 | } | 3255 | } |
3150 | 3256 | ||
3151 | /* This is only going to work if we've had a voltage configured. */ | 3257 | /* This is only going to work if we've had a voltage configured. */ |
3152 | if (!regulator->min_uV && !regulator->max_uV) { | 3258 | if (!voltage->min_uV && !voltage->max_uV) { |
3153 | ret = -EINVAL; | 3259 | ret = -EINVAL; |
3154 | goto out; | 3260 | goto out; |
3155 | } | 3261 | } |
3156 | 3262 | ||
3157 | min_uV = regulator->min_uV; | 3263 | min_uV = voltage->min_uV; |
3158 | max_uV = regulator->max_uV; | 3264 | max_uV = voltage->max_uV; |
3159 | 3265 | ||
3160 | /* This should be a paranoia check... */ | 3266 | /* This should be a paranoia check... */ |
3161 | ret = regulator_check_voltage(rdev, &min_uV, &max_uV); | 3267 | ret = regulator_check_voltage(rdev, &min_uV, &max_uV); |
3162 | if (ret < 0) | 3268 | if (ret < 0) |
3163 | goto out; | 3269 | goto out; |
3164 | 3270 | ||
3165 | ret = regulator_check_consumers(rdev, &min_uV, &max_uV); | 3271 | ret = regulator_check_consumers(rdev, &min_uV, &max_uV, 0); |
3166 | if (ret < 0) | 3272 | if (ret < 0) |
3167 | goto out; | 3273 | goto out; |
3168 | 3274 | ||
@@ -3918,12 +4024,6 @@ static void regulator_dev_release(struct device *dev) | |||
3918 | kfree(rdev); | 4024 | kfree(rdev); |
3919 | } | 4025 | } |
3920 | 4026 | ||
3921 | static struct class regulator_class = { | ||
3922 | .name = "regulator", | ||
3923 | .dev_release = regulator_dev_release, | ||
3924 | .dev_groups = regulator_dev_groups, | ||
3925 | }; | ||
3926 | |||
3927 | static void rdev_init_debugfs(struct regulator_dev *rdev) | 4027 | static void rdev_init_debugfs(struct regulator_dev *rdev) |
3928 | { | 4028 | { |
3929 | struct device *parent = rdev->dev.parent; | 4029 | struct device *parent = rdev->dev.parent; |
@@ -4174,81 +4274,86 @@ void regulator_unregister(struct regulator_dev *rdev) | |||
4174 | } | 4274 | } |
4175 | EXPORT_SYMBOL_GPL(regulator_unregister); | 4275 | EXPORT_SYMBOL_GPL(regulator_unregister); |
4176 | 4276 | ||
4177 | static int _regulator_suspend_prepare(struct device *dev, void *data) | 4277 | #ifdef CONFIG_SUSPEND |
4278 | static int _regulator_suspend_late(struct device *dev, void *data) | ||
4178 | { | 4279 | { |
4179 | struct regulator_dev *rdev = dev_to_rdev(dev); | 4280 | struct regulator_dev *rdev = dev_to_rdev(dev); |
4180 | const suspend_state_t *state = data; | 4281 | suspend_state_t *state = data; |
4181 | int ret; | 4282 | int ret; |
4182 | 4283 | ||
4183 | mutex_lock(&rdev->mutex); | 4284 | mutex_lock(&rdev->mutex); |
4184 | ret = suspend_prepare(rdev, *state); | 4285 | ret = suspend_set_state(rdev, *state); |
4185 | mutex_unlock(&rdev->mutex); | 4286 | mutex_unlock(&rdev->mutex); |
4186 | 4287 | ||
4187 | return ret; | 4288 | return ret; |
4188 | } | 4289 | } |
4189 | 4290 | ||
4190 | /** | 4291 | /** |
4191 | * regulator_suspend_prepare - prepare regulators for system wide suspend | 4292 | * regulator_suspend_late - prepare regulators for system wide suspend |
4192 | * @state: system suspend state | 4293 | * @state: system suspend state |
4193 | * | 4294 | * |
4194 | * Configure each regulator with it's suspend operating parameters for state. | 4295 | * Configure each regulator with it's suspend operating parameters for state. |
4195 | * This will usually be called by machine suspend code prior to supending. | ||
4196 | */ | 4296 | */ |
4197 | int regulator_suspend_prepare(suspend_state_t state) | 4297 | static int regulator_suspend_late(struct device *dev) |
4198 | { | 4298 | { |
4199 | /* ON is handled by regulator active state */ | 4299 | suspend_state_t state = pm_suspend_target_state; |
4200 | if (state == PM_SUSPEND_ON) | ||
4201 | return -EINVAL; | ||
4202 | 4300 | ||
4203 | return class_for_each_device(®ulator_class, NULL, &state, | 4301 | return class_for_each_device(®ulator_class, NULL, &state, |
4204 | _regulator_suspend_prepare); | 4302 | _regulator_suspend_late); |
4205 | } | 4303 | } |
4206 | EXPORT_SYMBOL_GPL(regulator_suspend_prepare); | 4304 | static int _regulator_resume_early(struct device *dev, void *data) |
4207 | |||
4208 | static int _regulator_suspend_finish(struct device *dev, void *data) | ||
4209 | { | 4305 | { |
4306 | int ret = 0; | ||
4210 | struct regulator_dev *rdev = dev_to_rdev(dev); | 4307 | struct regulator_dev *rdev = dev_to_rdev(dev); |
4211 | int ret; | 4308 | suspend_state_t *state = data; |
4309 | struct regulator_state *rstate; | ||
4310 | |||
4311 | rstate = regulator_get_suspend_state(rdev, *state); | ||
4312 | if (rstate == NULL) | ||
4313 | return -EINVAL; | ||
4212 | 4314 | ||
4213 | mutex_lock(&rdev->mutex); | 4315 | mutex_lock(&rdev->mutex); |
4214 | if (rdev->use_count > 0 || rdev->constraints->always_on) { | ||
4215 | if (!_regulator_is_enabled(rdev)) { | ||
4216 | ret = _regulator_do_enable(rdev); | ||
4217 | if (ret) | ||
4218 | dev_err(dev, | ||
4219 | "Failed to resume regulator %d\n", | ||
4220 | ret); | ||
4221 | } | ||
4222 | } else { | ||
4223 | if (!have_full_constraints()) | ||
4224 | goto unlock; | ||
4225 | if (!_regulator_is_enabled(rdev)) | ||
4226 | goto unlock; | ||
4227 | 4316 | ||
4228 | ret = _regulator_do_disable(rdev); | 4317 | if (rdev->desc->ops->resume_early && |
4229 | if (ret) | 4318 | (rstate->enabled == ENABLE_IN_SUSPEND || |
4230 | dev_err(dev, "Failed to suspend regulator %d\n", ret); | 4319 | rstate->enabled == DISABLE_IN_SUSPEND)) |
4231 | } | 4320 | ret = rdev->desc->ops->resume_early(rdev); |
4232 | unlock: | 4321 | |
4233 | mutex_unlock(&rdev->mutex); | 4322 | mutex_unlock(&rdev->mutex); |
4234 | 4323 | ||
4235 | /* Keep processing regulators in spite of any errors */ | 4324 | return ret; |
4236 | return 0; | ||
4237 | } | 4325 | } |
4238 | 4326 | ||
4239 | /** | 4327 | static int regulator_resume_early(struct device *dev) |
4240 | * regulator_suspend_finish - resume regulators from system wide suspend | ||
4241 | * | ||
4242 | * Turn on regulators that might be turned off by regulator_suspend_prepare | ||
4243 | * and that should be turned on according to the regulators properties. | ||
4244 | */ | ||
4245 | int regulator_suspend_finish(void) | ||
4246 | { | 4328 | { |
4247 | return class_for_each_device(®ulator_class, NULL, NULL, | 4329 | suspend_state_t state = pm_suspend_target_state; |
4248 | _regulator_suspend_finish); | 4330 | |
4331 | return class_for_each_device(®ulator_class, NULL, &state, | ||
4332 | _regulator_resume_early); | ||
4249 | } | 4333 | } |
4250 | EXPORT_SYMBOL_GPL(regulator_suspend_finish); | ||
4251 | 4334 | ||
4335 | #else /* !CONFIG_SUSPEND */ | ||
4336 | |||
4337 | #define regulator_suspend_late NULL | ||
4338 | #define regulator_resume_early NULL | ||
4339 | |||
4340 | #endif /* !CONFIG_SUSPEND */ | ||
4341 | |||
4342 | #ifdef CONFIG_PM | ||
4343 | static const struct dev_pm_ops __maybe_unused regulator_pm_ops = { | ||
4344 | .suspend_late = regulator_suspend_late, | ||
4345 | .resume_early = regulator_resume_early, | ||
4346 | }; | ||
4347 | #endif | ||
4348 | |||
4349 | struct class regulator_class = { | ||
4350 | .name = "regulator", | ||
4351 | .dev_release = regulator_dev_release, | ||
4352 | .dev_groups = regulator_dev_groups, | ||
4353 | #ifdef CONFIG_PM | ||
4354 | .pm = ®ulator_pm_ops, | ||
4355 | #endif | ||
4356 | }; | ||
4252 | /** | 4357 | /** |
4253 | * regulator_has_full_constraints - the system has fully specified constraints | 4358 | * regulator_has_full_constraints - the system has fully specified constraints |
4254 | * | 4359 | * |
@@ -4424,8 +4529,8 @@ static void regulator_summary_show_subtree(struct seq_file *s, | |||
4424 | switch (rdev->desc->type) { | 4529 | switch (rdev->desc->type) { |
4425 | case REGULATOR_VOLTAGE: | 4530 | case REGULATOR_VOLTAGE: |
4426 | seq_printf(s, "%37dmV %5dmV", | 4531 | seq_printf(s, "%37dmV %5dmV", |
4427 | consumer->min_uV / 1000, | 4532 | consumer->voltage[PM_SUSPEND_ON].min_uV / 1000, |
4428 | consumer->max_uV / 1000); | 4533 | consumer->voltage[PM_SUSPEND_ON].max_uV / 1000); |
4429 | break; | 4534 | break; |
4430 | case REGULATOR_CURRENT: | 4535 | case REGULATOR_CURRENT: |
4431 | break; | 4536 | break; |
diff --git a/drivers/regulator/internal.h b/drivers/regulator/internal.h index 66a8ea0c8386..abfd56e8c78a 100644 --- a/drivers/regulator/internal.h +++ b/drivers/regulator/internal.h | |||
@@ -16,10 +16,25 @@ | |||
16 | #ifndef __REGULATOR_INTERNAL_H | 16 | #ifndef __REGULATOR_INTERNAL_H |
17 | #define __REGULATOR_INTERNAL_H | 17 | #define __REGULATOR_INTERNAL_H |
18 | 18 | ||
19 | #include <linux/suspend.h> | ||
20 | |||
21 | #define REGULATOR_STATES_NUM (PM_SUSPEND_MAX + 1) | ||
22 | |||
23 | struct regulator_voltage { | ||
24 | int min_uV; | ||
25 | int max_uV; | ||
26 | }; | ||
27 | |||
19 | /* | 28 | /* |
20 | * struct regulator | 29 | * struct regulator |
21 | * | 30 | * |
22 | * One for each consumer device. | 31 | * One for each consumer device. |
32 | * @voltage - a voltage array for each state of runtime, i.e.: | ||
33 | * PM_SUSPEND_ON | ||
34 | * PM_SUSPEND_TO_IDLE | ||
35 | * PM_SUSPEND_STANDBY | ||
36 | * PM_SUSPEND_MEM | ||
37 | * PM_SUSPEND_MAX | ||
23 | */ | 38 | */ |
24 | struct regulator { | 39 | struct regulator { |
25 | struct device *dev; | 40 | struct device *dev; |
@@ -27,14 +42,22 @@ struct regulator { | |||
27 | unsigned int always_on:1; | 42 | unsigned int always_on:1; |
28 | unsigned int bypass:1; | 43 | unsigned int bypass:1; |
29 | int uA_load; | 44 | int uA_load; |
30 | int min_uV; | 45 | struct regulator_voltage voltage[REGULATOR_STATES_NUM]; |
31 | int max_uV; | ||
32 | const char *supply_name; | 46 | const char *supply_name; |
33 | struct device_attribute dev_attr; | 47 | struct device_attribute dev_attr; |
34 | struct regulator_dev *rdev; | 48 | struct regulator_dev *rdev; |
35 | struct dentry *debugfs; | 49 | struct dentry *debugfs; |
36 | }; | 50 | }; |
37 | 51 | ||
52 | extern struct class regulator_class; | ||
53 | |||
54 | static inline struct regulator_dev *dev_to_rdev(struct device *dev) | ||
55 | { | ||
56 | return container_of(dev, struct regulator_dev, dev); | ||
57 | } | ||
58 | |||
59 | struct regulator_dev *of_find_regulator_by_node(struct device_node *np); | ||
60 | |||
38 | #ifdef CONFIG_OF | 61 | #ifdef CONFIG_OF |
39 | struct regulator_init_data *regulator_of_get_init_data(struct device *dev, | 62 | struct regulator_init_data *regulator_of_get_init_data(struct device *dev, |
40 | const struct regulator_desc *desc, | 63 | const struct regulator_desc *desc, |
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index 14637a01ba2d..092ed6efb3ec 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c | |||
@@ -177,14 +177,30 @@ static void of_get_regulation_constraints(struct device_node *np, | |||
177 | 177 | ||
178 | if (of_property_read_bool(suspend_np, | 178 | if (of_property_read_bool(suspend_np, |
179 | "regulator-on-in-suspend")) | 179 | "regulator-on-in-suspend")) |
180 | suspend_state->enabled = true; | 180 | suspend_state->enabled = ENABLE_IN_SUSPEND; |
181 | else if (of_property_read_bool(suspend_np, | 181 | else if (of_property_read_bool(suspend_np, |
182 | "regulator-off-in-suspend")) | 182 | "regulator-off-in-suspend")) |
183 | suspend_state->disabled = true; | 183 | suspend_state->enabled = DISABLE_IN_SUSPEND; |
184 | else | ||
185 | suspend_state->enabled = DO_NOTHING_IN_SUSPEND; | ||
186 | |||
187 | if (!of_property_read_u32(np, "regulator-suspend-min-microvolt", | ||
188 | &pval)) | ||
189 | suspend_state->min_uV = pval; | ||
190 | |||
191 | if (!of_property_read_u32(np, "regulator-suspend-max-microvolt", | ||
192 | &pval)) | ||
193 | suspend_state->max_uV = pval; | ||
184 | 194 | ||
185 | if (!of_property_read_u32(suspend_np, | 195 | if (!of_property_read_u32(suspend_np, |
186 | "regulator-suspend-microvolt", &pval)) | 196 | "regulator-suspend-microvolt", &pval)) |
187 | suspend_state->uV = pval; | 197 | suspend_state->uV = pval; |
198 | else /* otherwise use min_uV as default suspend voltage */ | ||
199 | suspend_state->uV = suspend_state->min_uV; | ||
200 | |||
201 | if (of_property_read_bool(suspend_np, | ||
202 | "regulator-changeable-in-suspend")) | ||
203 | suspend_state->changeable = true; | ||
188 | 204 | ||
189 | if (i == PM_SUSPEND_MEM) | 205 | if (i == PM_SUSPEND_MEM) |
190 | constraints->initial_state = PM_SUSPEND_MEM; | 206 | constraints->initial_state = PM_SUSPEND_MEM; |
@@ -376,3 +392,17 @@ struct regulator_init_data *regulator_of_get_init_data(struct device *dev, | |||
376 | 392 | ||
377 | return init_data; | 393 | return init_data; |
378 | } | 394 | } |
395 | |||
396 | static int of_node_match(struct device *dev, const void *data) | ||
397 | { | ||
398 | return dev->of_node == data; | ||
399 | } | ||
400 | |||
401 | struct regulator_dev *of_find_regulator_by_node(struct device_node *np) | ||
402 | { | ||
403 | struct device *dev; | ||
404 | |||
405 | dev = class_find_device(®ulator_class, NULL, np, of_node_match); | ||
406 | |||
407 | return dev ? dev_to_rdev(dev) : NULL; | ||
408 | } | ||
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 94417b4226bd..4c00486b7a78 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h | |||
@@ -214,6 +214,8 @@ struct regulator_ops { | |||
214 | /* set regulator suspend operating mode (defined in consumer.h) */ | 214 | /* set regulator suspend operating mode (defined in consumer.h) */ |
215 | int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode); | 215 | int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode); |
216 | 216 | ||
217 | int (*resume_early)(struct regulator_dev *rdev); | ||
218 | |||
217 | int (*set_pull_down) (struct regulator_dev *); | 219 | int (*set_pull_down) (struct regulator_dev *); |
218 | }; | 220 | }; |
219 | 221 | ||
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h index 9cd4fef37203..93a04893c739 100644 --- a/include/linux/regulator/machine.h +++ b/include/linux/regulator/machine.h | |||
@@ -42,6 +42,16 @@ struct regulator; | |||
42 | #define REGULATOR_CHANGE_DRMS 0x10 | 42 | #define REGULATOR_CHANGE_DRMS 0x10 |
43 | #define REGULATOR_CHANGE_BYPASS 0x20 | 43 | #define REGULATOR_CHANGE_BYPASS 0x20 |
44 | 44 | ||
45 | /* | ||
46 | * operations in suspend mode | ||
47 | * DO_NOTHING_IN_SUSPEND - the default value | ||
48 | * DISABLE_IN_SUSPEND - turn off regulator in suspend states | ||
49 | * ENABLE_IN_SUSPEND - keep regulator on in suspend states | ||
50 | */ | ||
51 | #define DO_NOTHING_IN_SUSPEND (-1) | ||
52 | #define DISABLE_IN_SUSPEND 0 | ||
53 | #define ENABLE_IN_SUSPEND 1 | ||
54 | |||
45 | /* Regulator active discharge flags */ | 55 | /* Regulator active discharge flags */ |
46 | enum regulator_active_discharge { | 56 | enum regulator_active_discharge { |
47 | REGULATOR_ACTIVE_DISCHARGE_DEFAULT, | 57 | REGULATOR_ACTIVE_DISCHARGE_DEFAULT, |
@@ -56,16 +66,24 @@ enum regulator_active_discharge { | |||
56 | * state. One of enabled or disabled must be set for the | 66 | * state. One of enabled or disabled must be set for the |
57 | * configuration to be applied. | 67 | * configuration to be applied. |
58 | * | 68 | * |
59 | * @uV: Operating voltage during suspend. | 69 | * @uV: Default operating voltage during suspend, it can be adjusted |
70 | * among <min_uV, max_uV>. | ||
71 | * @min_uV: Minimum suspend voltage may be set. | ||
72 | * @max_uV: Maximum suspend voltage may be set. | ||
60 | * @mode: Operating mode during suspend. | 73 | * @mode: Operating mode during suspend. |
61 | * @enabled: Enabled during suspend. | 74 | * @enabled: operations during suspend. |
62 | * @disabled: Disabled during suspend. | 75 | * - DO_NOTHING_IN_SUSPEND |
76 | * - DISABLE_IN_SUSPEND | ||
77 | * - ENABLE_IN_SUSPEND | ||
78 | * @changeable: Is this state can be switched between enabled/disabled, | ||
63 | */ | 79 | */ |
64 | struct regulator_state { | 80 | struct regulator_state { |
65 | int uV; /* suspend voltage */ | 81 | int uV; |
66 | unsigned int mode; /* suspend regulator operating mode */ | 82 | int min_uV; |
67 | int enabled; /* is regulator enabled in this suspend state */ | 83 | int max_uV; |
68 | int disabled; /* is the regulator disabled in this suspend state */ | 84 | unsigned int mode; |
85 | int enabled; | ||
86 | bool changeable; | ||
69 | }; | 87 | }; |
70 | 88 | ||
71 | /** | 89 | /** |
@@ -225,12 +243,12 @@ struct regulator_init_data { | |||
225 | 243 | ||
226 | #ifdef CONFIG_REGULATOR | 244 | #ifdef CONFIG_REGULATOR |
227 | void regulator_has_full_constraints(void); | 245 | void regulator_has_full_constraints(void); |
228 | int regulator_suspend_prepare(suspend_state_t state); | ||
229 | int regulator_suspend_finish(void); | ||
230 | #else | 246 | #else |
231 | static inline void regulator_has_full_constraints(void) | 247 | static inline void regulator_has_full_constraints(void) |
232 | { | 248 | { |
233 | } | 249 | } |
250 | #endif | ||
251 | |||
234 | static inline int regulator_suspend_prepare(suspend_state_t state) | 252 | static inline int regulator_suspend_prepare(suspend_state_t state) |
235 | { | 253 | { |
236 | return 0; | 254 | return 0; |
@@ -239,6 +257,5 @@ static inline int regulator_suspend_finish(void) | |||
239 | { | 257 | { |
240 | return 0; | 258 | return 0; |
241 | } | 259 | } |
242 | #endif | ||
243 | 260 | ||
244 | #endif | 261 | #endif |