16 #include <linux/kernel.h>
19 #include <linux/device.h>
20 #include <linux/slab.h>
33 #include <linux/module.h>
35 #define CREATE_TRACE_POINTS
40 #define rdev_crit(rdev, fmt, ...) \
41 pr_crit("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
42 #define rdev_err(rdev, fmt, ...) \
43 pr_err("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
44 #define rdev_warn(rdev, fmt, ...) \
45 pr_warn("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
46 #define rdev_info(rdev, fmt, ...) \
47 pr_info("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
48 #define rdev_dbg(rdev, fmt, ...) \
49 pr_debug("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
54 static bool has_full_constraints;
55 static bool board_wants_dummy_regulator;
57 static struct dentry *debugfs_root;
98 int min_uV,
int max_uV);
107 else if (rdev->
desc->name)
108 return rdev->
desc->name;
127 dev_dbg(dev,
"Looking up %s-supply from device tree\n", supply);
129 snprintf(prop_name, 32,
"%s-supply", supply);
133 dev_dbg(dev,
"Looking up %s property in node %s failed",
134 prop_name, dev->
of_node->full_name);
140 static int _regulator_can_change_status(
struct regulator_dev *rdev)
152 static int regulator_check_voltage(
struct regulator_dev *rdev,
153 int *min_uV,
int *max_uV)
155 BUG_ON(*min_uV > *max_uV);
162 rdev_err(rdev,
"operation not allowed\n");
168 if (*min_uV < rdev->constraints->min_uV)
171 if (*min_uV > *max_uV) {
172 rdev_err(rdev,
"unsupportable voltage range: %d-%duV\n",
183 static int regulator_check_consumers(
struct regulator_dev *rdev,
184 int *min_uV,
int *max_uV)
196 if (*max_uV > regulator->
max_uV)
197 *max_uV = regulator->
max_uV;
198 if (*min_uV < regulator->min_uV)
199 *min_uV = regulator->
min_uV;
202 if (*min_uV > *max_uV)
209 static int regulator_check_current_limit(
struct regulator_dev *rdev,
210 int *min_uA,
int *max_uA)
212 BUG_ON(*min_uA > *max_uA);
219 rdev_err(rdev,
"operation not allowed\n");
225 if (*min_uA < rdev->constraints->min_uA)
228 if (*min_uA > *max_uA) {
229 rdev_err(rdev,
"unsupportable current range: %d-%duA\n",
247 rdev_err(rdev,
"invalid mode %x specified\n", *mode);
256 rdev_err(rdev,
"operation not allowed\n");
280 rdev_err(rdev,
"operation not allowed\n");
293 ret =
sprintf(buf,
"%d\n", _regulator_get_voltage(rdev));
305 return sprintf(buf,
"%d\n", _regulator_get_current_limit(rdev));
314 return sprintf(buf,
"%s\n", rdev_get_name(rdev));
317 static ssize_t regulator_print_opmode(
char *buf,
int mode)
323 return sprintf(buf,
"normal\n");
327 return sprintf(buf,
"standby\n");
329 return sprintf(buf,
"unknown\n");
337 return regulator_print_opmode(buf, _regulator_get_mode(rdev));
341 static ssize_t regulator_print_state(
char *buf,
int state)
344 return sprintf(buf,
"enabled\n");
346 return sprintf(buf,
"disabled\n");
348 return sprintf(buf,
"unknown\n");
358 ret = regulator_print_state(buf, _regulator_is_enabled(rdev));
372 status = rdev->
desc->ops->get_status(rdev);
408 return sprintf(buf,
"%s\n", label);
418 return sprintf(buf,
"constraint not defined\n");
430 return sprintf(buf,
"constraint not defined\n");
442 return sprintf(buf,
"constraint not defined\n");
454 return sprintf(buf,
"constraint not defined\n");
464 struct regulator *regulator;
473 static
DEVICE_ATTR(requested_microamps, 0444, regulator_total_uA_show,
NULL);
487 switch (rdev->
desc->type) {
489 return sprintf(buf,
"voltage\n");
491 return sprintf(buf,
"current\n");
493 return sprintf(buf,
"unknown\n");
496 static ssize_t regulator_suspend_mem_uV_show(
struct device *dev,
504 regulator_suspend_mem_uV_show,
NULL);
506 static ssize_t regulator_suspend_disk_uV_show(
struct device *dev,
514 regulator_suspend_disk_uV_show,
NULL);
516 static ssize_t regulator_suspend_standby_uV_show(
struct device *dev,
523 static DEVICE_ATTR(suspend_standby_microvolts, 0444,
524 regulator_suspend_standby_uV_show,
NULL);
526 static ssize_t regulator_suspend_mem_mode_show(
struct device *dev,
531 return regulator_print_opmode(buf,
535 regulator_suspend_mem_mode_show,
NULL);
537 static ssize_t regulator_suspend_disk_mode_show(
struct device *dev,
542 return regulator_print_opmode(buf,
546 regulator_suspend_disk_mode_show,
NULL);
548 static ssize_t regulator_suspend_standby_mode_show(
struct device *dev,
553 return regulator_print_opmode(buf,
557 regulator_suspend_standby_mode_show,
NULL);
559 static ssize_t regulator_suspend_mem_state_show(
struct device *dev,
564 return regulator_print_state(buf,
568 regulator_suspend_mem_state_show,
NULL);
570 static ssize_t regulator_suspend_disk_state_show(
struct device *dev,
575 return regulator_print_state(buf,
579 regulator_suspend_disk_state_show,
NULL);
581 static ssize_t regulator_suspend_standby_state_show(
struct device *dev,
586 return regulator_print_state(buf,
590 regulator_suspend_standby_state_show,
NULL);
600 ret = rdev->
desc->ops->get_bypass(rdev, &bypass);
609 return sprintf(buf,
"%s\n", report);
612 regulator_bypass_show,
NULL);
620 __ATTR(num_users, 0444, regulator_num_users_show,
NULL),
625 static void regulator_dev_release(
struct device *dev)
631 static struct class regulator_class = {
633 .dev_release = regulator_dev_release,
634 .dev_attrs = regulator_dev_attrs,
641 struct regulator *sibling;
642 int current_uA = 0, output_uV, input_uV,
err;
645 err = regulator_check_drms(rdev);
646 if (err < 0 || !rdev->
desc->ops->get_optimum_mode ||
647 (!rdev->
desc->ops->get_voltage &&
648 !rdev->
desc->ops->get_voltage_sel) ||
649 !rdev->
desc->ops->set_mode)
653 output_uV = _regulator_get_voltage(rdev);
668 current_uA += sibling->
uA_load;
671 mode = rdev->
desc->ops->get_optimum_mode(rdev, input_uV,
672 output_uV, current_uA);
675 err = regulator_mode_constrain(rdev, &mode);
677 rdev->
desc->ops->set_mode(rdev, mode);
689 if (!rstate->enabled && !rstate->disabled) {
690 if (rdev->desc->ops->set_suspend_voltage ||
691 rdev->desc->ops->set_suspend_mode)
696 if (rstate->enabled && rstate->disabled) {
697 rdev_err(rdev,
"invalid configuration\n");
701 if (rstate->enabled && rdev->desc->ops->set_suspend_enable)
702 ret = rdev->desc->ops->set_suspend_enable(rdev);
703 else if (rstate->disabled && rdev->desc->ops->set_suspend_disable)
704 ret = rdev->desc->ops->set_suspend_disable(rdev);
709 rdev_err(rdev,
"failed to enabled/disable\n");
713 if (rdev->desc->ops->set_suspend_voltage && rstate->uV > 0) {
714 ret = rdev->desc->ops->set_suspend_voltage(rdev, rstate->uV);
716 rdev_err(rdev,
"failed to set voltage\n");
721 if (rdev->desc->ops->set_suspend_mode && rstate->mode > 0) {
722 ret = rdev->desc->ops->set_suspend_mode(rdev, rstate->mode);
724 rdev_err(rdev,
"failed to set mode\n");
739 return suspend_set_state(rdev,
742 return suspend_set_state(rdev,
745 return suspend_set_state(rdev,
761 count +=
sprintf(buf + count,
"%d mV ",
762 constraints->
min_uV / 1000);
764 count +=
sprintf(buf + count,
"%d <--> %d mV ",
765 constraints->
min_uV / 1000,
766 constraints->
max_uV / 1000);
769 if (!constraints->
min_uV ||
771 ret = _regulator_get_voltage(rdev);
773 count +=
sprintf(buf + count,
"at %d mV ", ret / 1000);
777 count +=
sprintf(buf,
"%dmV offset ",
782 count +=
sprintf(buf + count,
"%d mA ",
783 constraints->
min_uA / 1000);
785 count +=
sprintf(buf + count,
"%d <--> %d mA ",
786 constraints->
min_uA / 1000,
787 constraints->
max_uA / 1000);
790 if (!constraints->
min_uA ||
792 ret = _regulator_get_current_limit(rdev);
794 count +=
sprintf(buf + count,
"at %d mA ", ret / 1000);
798 count +=
sprintf(buf + count,
"fast ");
800 count +=
sprintf(buf + count,
"normal ");
802 count +=
sprintf(buf + count,
"idle ");
804 count +=
sprintf(buf + count,
"standby");
814 "Voltage range but no REGULATOR_CHANGE_VOLTAGE\n");
817 static int machine_constraints_voltage(
struct regulator_dev *rdev,
826 ret = _regulator_do_set_voltage(rdev,
830 rdev_err(rdev,
"failed to apply %duV constraint\n",
840 int count = rdev->
desc->n_voltages;
844 int cmin = constraints->
min_uV;
845 int cmax = constraints->
max_uV;
849 if (count == 1 && !cmin) {
852 constraints->
min_uV = cmin;
853 constraints->
max_uV = cmax;
857 if ((cmin == 0) && (cmax == 0))
861 if (cmin <= 0 || cmax <= 0 || cmax < cmin) {
862 rdev_err(rdev,
"invalid voltage constraints\n");
867 for (i = 0; i <
count; i++) {
875 if (value >= cmin && value < min_uV)
877 if (value <= cmax && value > max_uV)
882 if (max_uV < min_uV) {
883 rdev_err(rdev,
"unsupportable voltage constraints\n");
888 if (constraints->
min_uV < min_uV) {
889 rdev_dbg(rdev,
"override min_uV, %d -> %d\n",
890 constraints->
min_uV, min_uV);
891 constraints->
min_uV = min_uV;
893 if (constraints->
max_uV > max_uV) {
894 rdev_dbg(rdev,
"override max_uV, %d -> %d\n",
895 constraints->
max_uV, max_uV);
896 constraints->
max_uV = max_uV;
914 static int set_machine_constraints(
struct regulator_dev *rdev,
929 ret = machine_constraints_voltage(rdev, rdev->
constraints);
935 ret = suspend_prepare(rdev, rdev->
constraints->initial_state);
937 rdev_err(rdev,
"failed to set suspend state\n");
944 rdev_err(rdev,
"no set_mode operation\n");
951 rdev_err(rdev,
"failed to set initial mode: %d\n", ret);
963 rdev_err(rdev,
"failed to enable\n");
971 rdev_err(rdev,
"failed to set ramp_delay\n");
976 print_constraints(rdev);
998 rdev_info(rdev,
"supplied by %s\n", rdev_get_name(supply_rdev));
1000 rdev->
supply = create_regulator(supply_rdev, &rdev->
dev,
"SUPPLY");
1021 static int set_consumer_device_supply(
struct regulator_dev *rdev,
1022 const char *consumer_dev_name,
1031 if (consumer_dev_name !=
NULL)
1037 if (node->
dev_name && consumer_dev_name) {
1040 }
else if (node->
dev_name || consumer_dev_name) {
1047 pr_debug(
"%s: %s/%s is '%s' supply; fail %s/%s\n",
1071 list_add(&node->
list, ®ulator_map_list);
1075 static void unset_regulator_supplies(
struct regulator_dev *rdev)
1088 #define REG_STR_SIZE 64
1090 static struct regulator *create_regulator(
struct regulator_dev *rdev,
1094 struct regulator *regulator;
1098 regulator = kzalloc(
sizeof(*regulator),
GFP_KERNEL);
1099 if (regulator ==
NULL)
1111 dev->
kobj.name, supply_name);
1122 rdev_warn(rdev,
"could not add device link %s err %d\n",
1123 dev->
kobj.name, err);
1135 rdev_warn(rdev,
"Failed to create debugfs directory\n");
1150 if (!_regulator_can_change_status(rdev) &&
1151 _regulator_is_enabled(rdev))
1163 static int _regulator_get_enable_time(
struct regulator_dev *rdev)
1165 if (!rdev->
desc->ops->enable_time)
1166 return rdev->
desc->enable_time;
1167 return rdev->
desc->ops->enable_time(rdev);
1177 const char *devname =
NULL;
1181 node = of_get_regulator(dev, supply);
1184 if (r->dev.parent &&
1185 node == r->dev.of_node)
1203 if (
strcmp(rdev_get_name(r), supply) == 0)
1208 if (map->dev_name &&
1209 (!devname ||
strcmp(map->dev_name, devname)))
1212 if (
strcmp(map->supply, supply) == 0)
1213 return map->regulator;
1221 static struct regulator *_regulator_get(
struct device *dev,
const char *
id,
1226 const char *devname =
NULL;
1230 pr_err(
"get() with no identifier\n");
1235 devname = dev_name(dev);
1239 rdev = regulator_dev_lookup(dev,
id, &ret);
1243 if (board_wants_dummy_regulator) {
1248 #ifdef CONFIG_REGULATOR_DUMMY
1250 devname =
"deviceless";
1255 if (!has_full_constraints) {
1256 pr_warn(
"%s supply %s not found, using dummy regulator\n",
1268 regulator = ERR_PTR(-
EPERM);
1273 regulator = ERR_PTR(-
EBUSY);
1277 if (!try_module_get(rdev->
owner))
1280 regulator = create_regulator(rdev, dev,
id);
1281 if (regulator ==
NULL) {
1282 regulator = ERR_PTR(-
ENOMEM);
1283 module_put(rdev->
owner);
1291 ret = _regulator_is_enabled(rdev);
1319 return _regulator_get(dev,
id, 0);
1323 static void devm_regulator_release(
struct device *dev,
void *
res)
1339 struct regulator **
ptr, *regulator;
1346 if (!IS_ERR(regulator)) {
1380 return _regulator_get(dev,
id, 1);
1385 static void _regulator_put(
struct regulator *regulator)
1389 if (regulator ==
NULL || IS_ERR(regulator))
1392 rdev = regulator->
rdev;
1406 module_put(rdev->
owner);
1420 _regulator_put(regulator);
1425 static int devm_regulator_match(
struct device *dev,
void *res,
void *
data)
1427 struct regulator **r =
res;
1448 devm_regulator_match, regulator);
1459 ret = _regulator_get_enable_time(rdev);
1463 rdev_warn(rdev,
"enable_time() failed: %d\n", ret);
1467 trace_regulator_enable(rdev_get_name(rdev));
1473 }
else if (rdev->
desc->ops->enable) {
1474 ret = rdev->
desc->ops->enable(rdev);
1484 trace_regulator_enable_delay(rdev_get_name(rdev));
1486 if (delay >= 1000) {
1493 trace_regulator_enable_complete(rdev_get_name(rdev));
1506 drms_uA_update(rdev);
1510 ret = _regulator_is_enabled(rdev);
1511 if (ret == -
EINVAL || ret == 0) {
1512 if (!_regulator_can_change_status(rdev))
1515 ret = _regulator_do_enable(rdev);
1519 }
else if (ret < 0) {
1520 rdev_err(rdev,
"is_enabled() failed: %d\n", ret);
1557 ret = _regulator_enable(rdev);
1560 if (ret != 0 && rdev->
supply)
1567 static int _regulator_do_disable(
struct regulator_dev *rdev)
1571 trace_regulator_disable(rdev_get_name(rdev));
1578 }
else if (rdev->
desc->ops->disable) {
1579 ret = rdev->
desc->ops->disable(rdev);
1584 trace_regulator_disable_complete(rdev_get_name(rdev));
1597 "unbalanced disables for %s\n", rdev_get_name(rdev)))
1605 if (_regulator_can_change_status(rdev)) {
1606 ret = _regulator_do_disable(rdev);
1608 rdev_err(rdev,
"failed to disable\n");
1619 drms_uA_update(rdev);
1648 ret = _regulator_disable(rdev);
1651 if (ret == 0 && rdev->
supply)
1659 static int _regulator_force_disable(
struct regulator_dev *rdev)
1664 if (rdev->
desc->ops->disable) {
1666 ret = rdev->
desc->ops->disable(rdev);
1668 rdev_err(rdev,
"failed to force disable\n");
1695 ret = _regulator_force_disable(regulator->
rdev);
1719 for (i = 0; i <
count; i++) {
1720 ret = _regulator_disable(rdev);
1722 rdev_err(rdev,
"Deferred disable failed: %d\n", ret);
1728 for (i = 0; i <
count; i++) {
1732 "Supply disable failed: %d\n", ret);
1792 return (val & rdev->
desc->enable_mask) != 0;
1808 rdev->
desc->enable_mask,
1809 rdev->
desc->enable_mask);
1825 rdev->
desc->enable_mask, 0);
1829 static int _regulator_is_enabled(
struct regulator_dev *rdev)
1836 if (!rdev->
desc->ops->is_enabled)
1839 return rdev->
desc->ops->is_enabled(rdev);
1862 ret = _regulator_is_enabled(regulator->
rdev);
1898 if (selector >= rdev->
desc->n_voltages)
1901 return rdev->
desc->min_uV + (rdev->
desc->uV_step * selector);
1918 if (!rdev->
desc->volt_table) {
1923 if (selector >= rdev->
desc->n_voltages)
1926 return rdev->
desc->volt_table[selector];
1954 if (ret < rdev->constraints->
min_uV)
1974 int min_uV,
int max_uV)
1977 int i, voltages,
ret;
1983 return (min_uV <= ret && ret <= max_uV);
1993 for (i = 0; i < voltages; i++) {
1996 if (ret >= min_uV && ret <= max_uV)
2022 val &= rdev->
desc->vsel_mask;
2023 val >>=
ffs(rdev->
desc->vsel_mask) - 1;
2041 sel <<=
ffs(rdev->
desc->vsel_mask) - 1;
2044 rdev->
desc->vsel_mask, sel);
2061 int min_uV,
int max_uV)
2070 for (i = 0; i < rdev->
desc->n_voltages; i++) {
2071 ret = rdev->
desc->ops->list_voltage(rdev, i);
2075 if (ret < best_val && ret >= min_uV && ret <= max_uV) {
2099 int min_uV,
int max_uV)
2104 if (rdev->
desc->n_voltages == 1 && rdev->
desc->uV_step == 0) {
2105 if (min_uV <= rdev->
desc->min_uV && rdev->
desc->min_uV <= max_uV)
2111 if (!rdev->
desc->uV_step) {
2116 if (min_uV < rdev->
desc->min_uV)
2117 min_uV = rdev->
desc->min_uV;
2124 voltage = rdev->
desc->ops->list_voltage(rdev, ret);
2125 if (voltage < min_uV || voltage > max_uV)
2132 static int _regulator_do_set_voltage(
struct regulator_dev *rdev,
2133 int min_uV,
int max_uV)
2139 int old_selector = -1;
2141 trace_regulator_set_voltage(rdev_get_name(rdev), min_uV, max_uV);
2150 if (_regulator_is_enabled(rdev) &&
2151 rdev->
desc->ops->set_voltage_time_sel &&
2152 rdev->
desc->ops->get_voltage_sel) {
2153 old_selector = rdev->
desc->ops->get_voltage_sel(rdev);
2154 if (old_selector < 0)
2155 return old_selector;
2158 if (rdev->
desc->ops->set_voltage) {
2159 ret = rdev->
desc->ops->set_voltage(rdev, min_uV, max_uV,
2163 if (rdev->
desc->ops->list_voltage)
2164 best_val = rdev->
desc->ops->list_voltage(rdev,
2167 best_val = _regulator_get_voltage(rdev);
2170 }
else if (rdev->
desc->ops->set_voltage_sel) {
2171 if (rdev->
desc->ops->map_voltage) {
2172 ret = rdev->
desc->ops->map_voltage(rdev, min_uV,
2175 if (rdev->
desc->ops->list_voltage ==
2185 best_val = rdev->
desc->ops->list_voltage(rdev, ret);
2186 if (min_uV <= best_val && max_uV >= best_val) {
2188 ret = rdev->
desc->ops->set_voltage_sel(rdev,
2199 if (ret == 0 && _regulator_is_enabled(rdev) && old_selector >= 0 &&
2200 rdev->
desc->ops->set_voltage_time_sel) {
2202 delay = rdev->
desc->ops->set_voltage_time_sel(rdev,
2203 old_selector, selector);
2205 rdev_warn(rdev,
"set_voltage_time_sel() failed: %d\n",
2211 if (delay >= 1000) {
2219 if (ret == 0 && best_val >= 0) {
2220 unsigned long data = best_val;
2226 trace_regulator_set_voltage_complete(rdev_get_name(rdev), best_val);
2260 if (regulator->
min_uV == min_uV && regulator->
max_uV == max_uV)
2264 if (!rdev->
desc->ops->set_voltage &&
2265 !rdev->
desc->ops->set_voltage_sel) {
2271 ret = regulator_check_voltage(rdev, &min_uV, &max_uV);
2274 regulator->
min_uV = min_uV;
2275 regulator->
max_uV = max_uV;
2277 ret = regulator_check_consumers(rdev, &min_uV, &max_uV);
2281 ret = _regulator_do_set_voltage(rdev, min_uV, max_uV);
2300 int old_uV,
int new_uV)
2311 || !rdev->
desc->n_voltages)
2314 for (i = 0; i < rdev->
desc->n_voltages; i++) {
2321 if (voltage == old_uV)
2323 if (voltage == new_uV)
2327 if (old_sel < 0 || new_sel < 0)
2347 unsigned int old_selector,
2348 unsigned int new_selector)
2350 unsigned int ramp_delay = 0;
2351 int old_volt, new_volt;
2355 else if (rdev->
desc->ramp_delay)
2356 ramp_delay = rdev->
desc->ramp_delay;
2358 if (ramp_delay == 0) {
2359 rdev_warn(rdev,
"ramp_delay not set\n");
2364 if (!rdev->
desc->ops->list_voltage)
2367 old_volt = rdev->
desc->ops->list_voltage(rdev, old_selector);
2368 new_volt = rdev->
desc->ops->list_voltage(rdev, new_selector);
2385 int ret, min_uV, max_uV;
2389 if (!rdev->
desc->ops->set_voltage &&
2390 !rdev->
desc->ops->set_voltage_sel) {
2401 min_uV = regulator->
min_uV;
2402 max_uV = regulator->
max_uV;
2405 ret = regulator_check_voltage(rdev, &min_uV, &max_uV);
2409 ret = regulator_check_consumers(rdev, &min_uV, &max_uV);
2413 ret = _regulator_do_set_voltage(rdev, min_uV, max_uV);
2421 static int _regulator_get_voltage(
struct regulator_dev *rdev)
2425 if (rdev->
desc->ops->get_voltage_sel) {
2426 sel = rdev->
desc->ops->get_voltage_sel(rdev);
2429 ret = rdev->
desc->ops->list_voltage(rdev, sel);
2430 }
else if (rdev->
desc->ops->get_voltage) {
2431 ret = rdev->
desc->ops->get_voltage(rdev);
2432 }
else if (rdev->
desc->ops->list_voltage) {
2433 ret = rdev->
desc->ops->list_voltage(rdev, 0);
2458 ret = _regulator_get_voltage(regulator->
rdev);
2483 int min_uA,
int max_uA)
2491 if (!rdev->
desc->ops->set_current_limit) {
2497 ret = regulator_check_current_limit(rdev, &min_uA, &max_uA);
2501 ret = rdev->
desc->ops->set_current_limit(rdev, min_uA, max_uA);
2508 static int _regulator_get_current_limit(
struct regulator_dev *rdev)
2515 if (!rdev->
desc->ops->get_current_limit) {
2520 ret = rdev->
desc->ops->get_current_limit(rdev);
2537 return _regulator_get_current_limit(regulator->
rdev);
2556 int regulator_curr_mode;
2561 if (!rdev->
desc->ops->set_mode) {
2567 if (rdev->
desc->ops->get_mode) {
2568 regulator_curr_mode = rdev->
desc->ops->get_mode(rdev);
2569 if (regulator_curr_mode == mode) {
2576 ret = regulator_mode_constrain(rdev, &mode);
2580 ret = rdev->
desc->ops->set_mode(rdev, mode);
2587 static unsigned int _regulator_get_mode(
struct regulator_dev *rdev)
2594 if (!rdev->
desc->ops->get_mode) {
2599 ret = rdev->
desc->ops->get_mode(rdev);
2613 return _regulator_get_mode(regulator->
rdev);
2646 struct regulator *consumer;
2647 int ret, output_uV, input_uV = 0, total_uA_load = 0;
2660 ret = regulator_check_drms(rdev);
2666 if (!rdev->
desc->ops->get_optimum_mode)
2675 if (!rdev->
desc->ops->set_mode)
2679 output_uV = _regulator_get_voltage(rdev);
2680 if (output_uV <= 0) {
2681 rdev_err(rdev,
"invalid output voltage found\n");
2688 if (input_uV <= 0) {
2689 rdev_err(rdev,
"invalid input voltage found\n");
2695 total_uA_load += consumer->
uA_load;
2697 mode = rdev->
desc->ops->get_optimum_mode(rdev,
2698 input_uV, output_uV,
2700 ret = regulator_mode_constrain(rdev, &mode);
2702 rdev_err(rdev,
"failed to get optimum mode @ %d uA %d -> %d uV\n",
2703 total_uA_load, input_uV, output_uV);
2707 ret = rdev->
desc->ops->set_mode(rdev, mode);
2709 rdev_err(rdev,
"failed to set optimum mode %x\n", mode);
2730 val = rdev->
desc->bypass_mask;
2735 rdev->
desc->bypass_mask, val);
2754 *enable = val & rdev->
desc->bypass_mask;
2776 if (!rdev->
desc->ops->set_bypass)
2785 if (enable && !regulator->
bypass) {
2789 ret = rdev->
desc->ops->set_bypass(rdev, enable);
2794 }
else if (!enable && regulator->
bypass) {
2798 ret = rdev->
desc->ops->set_bypass(rdev, enable);
2846 static void _notifier_call_chain(
struct regulator_dev *rdev,
2847 unsigned long event,
void *data)
2873 for (i = 0; i < num_consumers; i++)
2874 consumers[i].consumer =
NULL;
2876 for (i = 0; i < num_consumers; i++) {
2878 consumers[i].supply);
2879 if (IS_ERR(consumers[i].consumer)) {
2880 ret = PTR_ERR(consumers[i].consumer);
2881 dev_err(dev,
"Failed to get supply '%s': %d\n",
2882 consumers[i].supply, ret);
2919 for (i = 0; i < num_consumers; i++)
2920 consumers[i].consumer =
NULL;
2922 for (i = 0; i < num_consumers; i++) {
2924 consumers[i].supply);
2925 if (IS_ERR(consumers[i].consumer)) {
2926 ret = PTR_ERR(consumers[i].consumer);
2927 dev_err(dev,
"Failed to get supply '%s': %d\n",
2928 consumers[i].supply, ret);
2937 for (i = 0; i < num_consumers && consumers[
i].
consumer; i++)
2970 for (i = 0; i < num_consumers; i++) {
2971 if (consumers[i].
consumer->always_on)
2972 consumers[
i].
ret = 0;
2981 for (i = 0; i < num_consumers; i++) {
2982 if (consumers[i].ret != 0) {
2983 ret = consumers[
i].
ret;
2991 pr_err(
"Failed to enable %s: %d\n", consumers[i].supply, ret);
3017 for (i = num_consumers - 1; i >= 0; --
i) {
3026 pr_err(
"Failed to disable %s: %d\n", consumers[i].supply, ret);
3027 for (++i; i < num_consumers; ++
i) {
3030 pr_err(
"Failed to reename %s: %d\n",
3031 consumers[i].supply, r);
3058 for (i = 0; i < num_consumers; i++)
3062 for (i = 0; i < num_consumers; i++) {
3063 if (consumers[i].ret != 0) {
3064 ret = consumers[
i].
ret;
3089 for (i = 0; i < num_consumers; i++) {
3107 unsigned long event,
void *data)
3109 _notifier_call_chain(rdev, event, data);
3143 static int add_regulator_attributes(
struct regulator_dev *rdev)
3227 &dev_attr_suspend_standby_microvolts);
3231 &dev_attr_suspend_mem_microvolts);
3235 &dev_attr_suspend_disk_microvolts);
3242 &dev_attr_suspend_standby_mode);
3246 &dev_attr_suspend_mem_mode);
3250 &dev_attr_suspend_disk_mode);
3262 rdev_warn(rdev,
"Failed to create debugfs directory\n");
3292 const char *supply =
NULL;
3294 if (regulator_desc ==
NULL || config ==
NULL)
3309 regulator_desc->
ops->get_voltage_sel);
3311 regulator_desc->
ops->set_voltage_sel);
3314 if (regulator_desc->
ops->get_voltage_sel &&
3315 !regulator_desc->
ops->list_voltage) {
3318 if (regulator_desc->
ops->set_voltage_sel &&
3319 !regulator_desc->
ops->list_voltage) {
3334 rdev->
desc = regulator_desc;
3342 INIT_LIST_HEAD(&rdev->
list);
3354 rdev->
dev.class = ®ulator_class;
3370 rdev_get_name(rdev));
3372 rdev_err(rdev,
"Failed to request enable GPIO%d: %d\n",
3391 ret = set_machine_constraints(rdev, constraints);
3396 ret = add_regulator_attributes(rdev);
3408 r = regulator_dev_lookup(dev, supply, &ret);
3411 dev_err(dev,
"Failed to find supply %s\n", supply);
3416 ret = set_supply(rdev, r);
3421 if (_regulator_is_enabled(rdev)) {
3431 ret = set_consumer_device_supply(rdev,
3435 dev_err(dev,
"Failed to set supply %s\n",
3437 goto unset_supplies;
3442 list_add(&rdev->
list, ®ulator_list);
3444 rdev_init_debugfs(rdev);
3450 unset_regulator_supplies(rdev);
3454 _regulator_put(rdev->
supply);
3461 rdev = ERR_PTR(ret);
3466 rdev = ERR_PTR(ret);
3488 unset_regulator_supplies(rdev);
3518 ret = suspend_prepare(rdev, state);
3522 rdev_err(rdev,
"failed to prepare\n");
3554 if (!has_full_constraints)
3558 if (!_regulator_is_enabled(rdev))
3586 has_full_constraints = 1;
3602 board_wants_dummy_regulator =
true;
3628 return regulator->
rdev->reg_data;
3649 return rdev->
desc->id;
3665 #ifdef CONFIG_DEBUG_FS
3666 static ssize_t supply_map_read_file(
struct file *
file,
char __user *user_buf,
3667 size_t count, loff_t *ppos)
3698 #ifdef CONFIG_DEBUG_FS
3699 .read = supply_map_read_file,
3704 static int __init regulator_init(
void)
3712 pr_warn(
"regulator: Failed to create debugfs directory\n");
3725 static int __init regulator_init_complete(
void)
3738 if (of_have_populated_dt())
3739 has_full_constraints =
true;
3748 ops = rdev->
desc->ops;
3768 if (has_full_constraints) {
3774 rdev_err(rdev,
"couldn't disable: %d\n", ret);
3782 rdev_warn(rdev,
"incomplete constraints, leaving on\n");