Lines Matching refs:rdev
86 static int _regulator_is_enabled(struct regulator_dev *rdev);
88 static int _regulator_get_error_flags(struct regulator_dev *rdev, unsigned int *flags);
89 static int _regulator_get_current_limit(struct regulator_dev *rdev);
90 static unsigned int _regulator_get_mode(struct regulator_dev *rdev);
91 static int _notifier_call_chain(struct regulator_dev *rdev,
93 static int _regulator_do_set_voltage(struct regulator_dev *rdev,
95 static int regulator_balance_voltage(struct regulator_dev *rdev,
97 static struct regulator *create_regulator(struct regulator_dev *rdev,
103 const char *rdev_get_name(struct regulator_dev *rdev) in rdev_get_name() argument
105 if (rdev->constraints && rdev->constraints->name) in rdev_get_name()
106 return rdev->constraints->name; in rdev_get_name()
107 else if (rdev->desc->name) in rdev_get_name()
108 return rdev->desc->name; in rdev_get_name()
119 static bool regulator_ops_is_valid(struct regulator_dev *rdev, int ops) in regulator_ops_is_valid() argument
121 if (!rdev->constraints) { in regulator_ops_is_valid()
122 rdev_err(rdev, "no constraints\n"); in regulator_ops_is_valid()
126 if (rdev->constraints->valid_ops_mask & ops) in regulator_ops_is_valid()
145 static inline int regulator_lock_nested(struct regulator_dev *rdev, in regulator_lock_nested() argument
153 if (!ww_mutex_trylock(&rdev->mutex, ww_ctx)) { in regulator_lock_nested()
154 if (rdev->mutex_owner == current) in regulator_lock_nested()
155 rdev->ref_cnt++; in regulator_lock_nested()
161 ret = ww_mutex_lock(&rdev->mutex, ww_ctx); in regulator_lock_nested()
169 rdev->ref_cnt++; in regulator_lock_nested()
170 rdev->mutex_owner = current; in regulator_lock_nested()
188 static void regulator_lock(struct regulator_dev *rdev) in regulator_lock() argument
190 regulator_lock_nested(rdev, NULL); in regulator_lock()
200 static void regulator_unlock(struct regulator_dev *rdev) in regulator_unlock() argument
204 if (--rdev->ref_cnt == 0) { in regulator_unlock()
205 rdev->mutex_owner = NULL; in regulator_unlock()
206 ww_mutex_unlock(&rdev->mutex); in regulator_unlock()
209 WARN_ON_ONCE(rdev->ref_cnt < 0); in regulator_unlock()
279 static bool regulator_supply_is_couple(struct regulator_dev *rdev) in regulator_supply_is_couple() argument
284 for (i = 1; i < rdev->coupling_desc.n_coupled; i++) { in regulator_supply_is_couple()
285 c_rdev = rdev->coupling_desc.coupled_rdevs[i]; in regulator_supply_is_couple()
287 if (rdev->supply->rdev == c_rdev) in regulator_supply_is_couple()
294 static void regulator_unlock_recursive(struct regulator_dev *rdev, in regulator_unlock_recursive() argument
301 c_rdev = rdev->coupling_desc.coupled_rdevs[i - 1]; in regulator_unlock_recursive()
307 supply_rdev = c_rdev->supply->rdev; in regulator_unlock_recursive()
318 static int regulator_lock_recursive(struct regulator_dev *rdev, in regulator_lock_recursive() argument
326 for (i = 0; i < rdev->coupling_desc.n_coupled; i++) { in regulator_lock_recursive()
327 c_rdev = rdev->coupling_desc.coupled_rdevs[i]; in regulator_lock_recursive()
348 err = regulator_lock_recursive(c_rdev->supply->rdev, in regulator_lock_recursive()
362 regulator_unlock_recursive(rdev, i); in regulator_lock_recursive()
375 static void regulator_unlock_dependent(struct regulator_dev *rdev, in regulator_unlock_dependent() argument
378 regulator_unlock_recursive(rdev, rdev->coupling_desc.n_coupled); in regulator_unlock_dependent()
390 static void regulator_lock_dependent(struct regulator_dev *rdev, in regulator_lock_dependent() argument
409 err = regulator_lock_recursive(rdev, in regulator_lock_dependent()
425 int regulator_check_voltage(struct regulator_dev *rdev, in regulator_check_voltage() argument
430 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) { in regulator_check_voltage()
431 rdev_err(rdev, "voltage operation not allowed\n"); in regulator_check_voltage()
435 if (*max_uV > rdev->constraints->max_uV) in regulator_check_voltage()
436 *max_uV = rdev->constraints->max_uV; in regulator_check_voltage()
437 if (*min_uV < rdev->constraints->min_uV) in regulator_check_voltage()
438 *min_uV = rdev->constraints->min_uV; in regulator_check_voltage()
441 rdev_err(rdev, "unsupportable voltage range: %d-%duV\n", in regulator_check_voltage()
458 int regulator_check_consumers(struct regulator_dev *rdev, in regulator_check_consumers() argument
465 list_for_each_entry(regulator, &rdev->consumer_list, list) { in regulator_check_consumers()
481 rdev_err(rdev, "Restricting voltage, %u-%uuV\n", in regulator_check_consumers()
490 static int regulator_check_current_limit(struct regulator_dev *rdev, in regulator_check_current_limit() argument
495 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_CURRENT)) { in regulator_check_current_limit()
496 rdev_err(rdev, "current operation not allowed\n"); in regulator_check_current_limit()
500 if (*max_uA > rdev->constraints->max_uA && in regulator_check_current_limit()
501 rdev->constraints->max_uA) in regulator_check_current_limit()
502 *max_uA = rdev->constraints->max_uA; in regulator_check_current_limit()
503 if (*min_uA < rdev->constraints->min_uA) in regulator_check_current_limit()
504 *min_uA = rdev->constraints->min_uA; in regulator_check_current_limit()
507 rdev_err(rdev, "unsupportable current range: %d-%duA\n", in regulator_check_current_limit()
516 static int regulator_mode_constrain(struct regulator_dev *rdev, in regulator_mode_constrain() argument
526 rdev_err(rdev, "invalid mode %x specified\n", *mode); in regulator_mode_constrain()
530 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_MODE)) { in regulator_mode_constrain()
531 rdev_err(rdev, "mode operation not allowed\n"); in regulator_mode_constrain()
540 if (rdev->constraints->valid_modes_mask & *mode) in regulator_mode_constrain()
549 regulator_get_suspend_state(struct regulator_dev *rdev, suspend_state_t state) in regulator_get_suspend_state() argument
551 if (rdev->constraints == NULL) in regulator_get_suspend_state()
556 return &rdev->constraints->state_standby; in regulator_get_suspend_state()
558 return &rdev->constraints->state_mem; in regulator_get_suspend_state()
560 return &rdev->constraints->state_disk; in regulator_get_suspend_state()
567 regulator_get_suspend_state_check(struct regulator_dev *rdev, suspend_state_t state) in regulator_get_suspend_state_check() argument
571 rstate = regulator_get_suspend_state(rdev, state); in regulator_get_suspend_state_check()
581 if (rdev->desc->ops->set_suspend_voltage || in regulator_get_suspend_state_check()
582 rdev->desc->ops->set_suspend_mode) in regulator_get_suspend_state_check()
583 rdev_warn(rdev, "No configuration\n"); in regulator_get_suspend_state_check()
593 struct regulator_dev *rdev = dev_get_drvdata(dev); in microvolts_show() local
596 regulator_lock(rdev); in microvolts_show()
597 uV = regulator_get_voltage_rdev(rdev); in microvolts_show()
598 regulator_unlock(rdev); in microvolts_show()
609 struct regulator_dev *rdev = dev_get_drvdata(dev); in microamps_show() local
611 return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev)); in microamps_show()
618 struct regulator_dev *rdev = dev_get_drvdata(dev); in name_show() local
620 return sprintf(buf, "%s\n", rdev_get_name(rdev)); in name_show()
647 struct regulator_dev *rdev = dev_get_drvdata(dev); in opmode_show() local
649 return regulator_print_opmode(buf, _regulator_get_mode(rdev)); in opmode_show()
666 struct regulator_dev *rdev = dev_get_drvdata(dev); in state_show() local
669 regulator_lock(rdev); in state_show()
670 ret = regulator_print_state(buf, _regulator_is_enabled(rdev)); in state_show()
671 regulator_unlock(rdev); in state_show()
680 struct regulator_dev *rdev = dev_get_drvdata(dev); in status_show() local
684 status = rdev->desc->ops->get_status(rdev); in status_show()
727 struct regulator_dev *rdev = dev_get_drvdata(dev); in min_microamps_show() local
729 if (!rdev->constraints) in min_microamps_show()
732 return sprintf(buf, "%d\n", rdev->constraints->min_uA); in min_microamps_show()
739 struct regulator_dev *rdev = dev_get_drvdata(dev); in max_microamps_show() local
741 if (!rdev->constraints) in max_microamps_show()
744 return sprintf(buf, "%d\n", rdev->constraints->max_uA); in max_microamps_show()
751 struct regulator_dev *rdev = dev_get_drvdata(dev); in min_microvolts_show() local
753 if (!rdev->constraints) in min_microvolts_show()
756 return sprintf(buf, "%d\n", rdev->constraints->min_uV); in min_microvolts_show()
763 struct regulator_dev *rdev = dev_get_drvdata(dev); in max_microvolts_show() local
765 if (!rdev->constraints) in max_microvolts_show()
768 return sprintf(buf, "%d\n", rdev->constraints->max_uV); in max_microvolts_show()
775 struct regulator_dev *rdev = dev_get_drvdata(dev); in requested_microamps_show() local
779 regulator_lock(rdev); in requested_microamps_show()
780 list_for_each_entry(regulator, &rdev->consumer_list, list) { in requested_microamps_show()
784 regulator_unlock(rdev); in requested_microamps_show()
792 struct regulator_dev *rdev = dev_get_drvdata(dev); in num_users_show() local
793 return sprintf(buf, "%d\n", rdev->use_count); in num_users_show()
800 struct regulator_dev *rdev = dev_get_drvdata(dev); in type_show() local
802 switch (rdev->desc->type) { in type_show()
815 struct regulator_dev *rdev = dev_get_drvdata(dev); in suspend_mem_microvolts_show() local
817 return sprintf(buf, "%d\n", rdev->constraints->state_mem.uV); in suspend_mem_microvolts_show()
824 struct regulator_dev *rdev = dev_get_drvdata(dev); in suspend_disk_microvolts_show() local
826 return sprintf(buf, "%d\n", rdev->constraints->state_disk.uV); in suspend_disk_microvolts_show()
833 struct regulator_dev *rdev = dev_get_drvdata(dev); in suspend_standby_microvolts_show() local
835 return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV); in suspend_standby_microvolts_show()
842 struct regulator_dev *rdev = dev_get_drvdata(dev); in suspend_mem_mode_show() local
845 rdev->constraints->state_mem.mode); in suspend_mem_mode_show()
852 struct regulator_dev *rdev = dev_get_drvdata(dev); in suspend_disk_mode_show() local
855 rdev->constraints->state_disk.mode); in suspend_disk_mode_show()
862 struct regulator_dev *rdev = dev_get_drvdata(dev); in suspend_standby_mode_show() local
865 rdev->constraints->state_standby.mode); in suspend_standby_mode_show()
872 struct regulator_dev *rdev = dev_get_drvdata(dev); in suspend_mem_state_show() local
875 rdev->constraints->state_mem.enabled); in suspend_mem_state_show()
882 struct regulator_dev *rdev = dev_get_drvdata(dev); in suspend_disk_state_show() local
885 rdev->constraints->state_disk.enabled); in suspend_disk_state_show()
892 struct regulator_dev *rdev = dev_get_drvdata(dev); in suspend_standby_state_show() local
895 rdev->constraints->state_standby.enabled); in suspend_standby_state_show()
902 struct regulator_dev *rdev = dev_get_drvdata(dev); in bypass_show() local
907 ret = rdev->desc->ops->get_bypass(rdev, &bypass); in bypass_show()
924 struct regulator_dev *rdev = dev_get_drvdata(dev); in power_budget_milliwatt_show() local
926 return sprintf(buf, "%d\n", rdev->constraints->pw_budget_mW); in power_budget_milliwatt_show()
934 struct regulator_dev *rdev = dev_get_drvdata(dev); in power_requested_milliwatt_show() local
936 return sprintf(buf, "%d\n", rdev->pw_requested_mW); in power_requested_milliwatt_show()
946 struct regulator_dev *rdev = dev_get_drvdata(dev); \
947 ret = _regulator_get_error_flags(rdev, &flags); \
967 static int drms_uA_update(struct regulator_dev *rdev) in drms_uA_update() argument
977 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_DRMS)) { in drms_uA_update()
978 rdev_dbg(rdev, "DRMS operation not allowed\n"); in drms_uA_update()
982 if (!rdev->desc->ops->get_optimum_mode && in drms_uA_update()
983 !rdev->desc->ops->set_load) in drms_uA_update()
986 if (!rdev->desc->ops->set_mode && in drms_uA_update()
987 !rdev->desc->ops->set_load) in drms_uA_update()
991 list_for_each_entry(sibling, &rdev->consumer_list, list) { in drms_uA_update()
996 current_uA += rdev->constraints->system_load; in drms_uA_update()
998 if (rdev->desc->ops->set_load) { in drms_uA_update()
1000 err = rdev->desc->ops->set_load(rdev, current_uA); in drms_uA_update()
1002 rdev_err(rdev, "failed to set load %d: %pe\n", in drms_uA_update()
1012 if (!rdev->constraints->valid_modes_mask) { in drms_uA_update()
1013 rdev_dbg(rdev, "Can change modes; but no valid mode\n"); in drms_uA_update()
1018 output_uV = regulator_get_voltage_rdev(rdev); in drms_uA_update()
1025 rdev_dbg(rdev, "invalid output voltage found\n"); in drms_uA_update()
1029 if (rdev->supply) in drms_uA_update()
1030 input_uV = regulator_get_voltage_rdev(rdev->supply->rdev); in drms_uA_update()
1032 input_uV = rdev->constraints->input_uV; in drms_uA_update()
1039 rdev_dbg(rdev, "invalid input voltage found\n"); in drms_uA_update()
1042 mode = rdev->desc->ops->get_optimum_mode(rdev, input_uV, in drms_uA_update()
1046 err = regulator_mode_constrain(rdev, &mode); in drms_uA_update()
1048 rdev_err(rdev, "failed to get optimum mode @ %d uA %d -> %d uV: %pe\n", in drms_uA_update()
1053 err = rdev->desc->ops->set_mode(rdev, mode); in drms_uA_update()
1055 rdev_err(rdev, "failed to set optimum mode %x: %pe\n", in drms_uA_update()
1062 static int __suspend_set_state(struct regulator_dev *rdev, in __suspend_set_state() argument
1068 rdev->desc->ops->set_suspend_enable) in __suspend_set_state()
1069 ret = rdev->desc->ops->set_suspend_enable(rdev); in __suspend_set_state()
1071 rdev->desc->ops->set_suspend_disable) in __suspend_set_state()
1072 ret = rdev->desc->ops->set_suspend_disable(rdev); in __suspend_set_state()
1077 rdev_err(rdev, "failed to enabled/disable: %pe\n", ERR_PTR(ret)); in __suspend_set_state()
1081 if (rdev->desc->ops->set_suspend_voltage && rstate->uV > 0) { in __suspend_set_state()
1082 ret = rdev->desc->ops->set_suspend_voltage(rdev, rstate->uV); in __suspend_set_state()
1084 rdev_err(rdev, "failed to set voltage: %pe\n", ERR_PTR(ret)); in __suspend_set_state()
1089 if (rdev->desc->ops->set_suspend_mode && rstate->mode > 0) { in __suspend_set_state()
1090 ret = rdev->desc->ops->set_suspend_mode(rdev, rstate->mode); in __suspend_set_state()
1092 rdev_err(rdev, "failed to set mode: %pe\n", ERR_PTR(ret)); in __suspend_set_state()
1100 static int suspend_set_initial_state(struct regulator_dev *rdev) in suspend_set_initial_state() argument
1104 rstate = regulator_get_suspend_state_check(rdev, in suspend_set_initial_state()
1105 rdev->constraints->initial_state); in suspend_set_initial_state()
1109 return __suspend_set_state(rdev, rstate); in suspend_set_initial_state()
1113 static void print_constraints_debug(struct regulator_dev *rdev) in print_constraints_debug() argument
1115 struct regulation_constraints *constraints = rdev->constraints; in print_constraints_debug()
1134 ret = regulator_get_voltage_rdev(rdev); in print_constraints_debug()
1157 ret = _regulator_get_current_limit(rdev); in print_constraints_debug()
1182 _regulator_is_enabled(rdev) ? "enabled" : "disabled"); in print_constraints_debug()
1184 rdev_dbg(rdev, "%s\n", buf); in print_constraints_debug()
1187 static inline void print_constraints_debug(struct regulator_dev *rdev) {} in print_constraints_debug() argument
1190 static void print_constraints(struct regulator_dev *rdev) in print_constraints() argument
1192 struct regulation_constraints *constraints = rdev->constraints; in print_constraints()
1194 print_constraints_debug(rdev); in print_constraints()
1197 !regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) in print_constraints()
1198 rdev_warn(rdev, in print_constraints()
1202 static int machine_constraints_voltage(struct regulator_dev *rdev, in machine_constraints_voltage() argument
1205 const struct regulator_ops *ops = rdev->desc->ops; in machine_constraints_voltage()
1209 if (rdev->constraints->apply_uV && in machine_constraints_voltage()
1210 rdev->constraints->min_uV && rdev->constraints->max_uV) { in machine_constraints_voltage()
1212 int current_uV = regulator_get_voltage_rdev(rdev); in machine_constraints_voltage()
1216 rdev_info(rdev, "Setting %d-%duV\n", in machine_constraints_voltage()
1217 rdev->constraints->min_uV, in machine_constraints_voltage()
1218 rdev->constraints->max_uV); in machine_constraints_voltage()
1219 _regulator_do_set_voltage(rdev, in machine_constraints_voltage()
1220 rdev->constraints->min_uV, in machine_constraints_voltage()
1221 rdev->constraints->max_uV); in machine_constraints_voltage()
1222 current_uV = regulator_get_voltage_rdev(rdev); in machine_constraints_voltage()
1227 rdev_err(rdev, in machine_constraints_voltage()
1241 if (current_uV < rdev->constraints->min_uV) { in machine_constraints_voltage()
1242 target_min = rdev->constraints->min_uV; in machine_constraints_voltage()
1243 target_max = rdev->constraints->min_uV; in machine_constraints_voltage()
1246 if (current_uV > rdev->constraints->max_uV) { in machine_constraints_voltage()
1247 target_min = rdev->constraints->max_uV; in machine_constraints_voltage()
1248 target_max = rdev->constraints->max_uV; in machine_constraints_voltage()
1252 rdev_info(rdev, "Bringing %duV into %d-%duV\n", in machine_constraints_voltage()
1255 rdev, target_min, target_max); in machine_constraints_voltage()
1257 rdev_err(rdev, in machine_constraints_voltage()
1268 if (ops->list_voltage && rdev->desc->n_voltages) { in machine_constraints_voltage()
1269 int count = rdev->desc->n_voltages; in machine_constraints_voltage()
1292 rdev_err(rdev, "invalid voltage constraints\n"); in machine_constraints_voltage()
1297 if (rdev->desc->continuous_voltage_range) in machine_constraints_voltage()
1304 value = ops->list_voltage(rdev, i); in machine_constraints_voltage()
1317 rdev_err(rdev, in machine_constraints_voltage()
1325 rdev_dbg(rdev, "override min_uV, %d -> %d\n", in machine_constraints_voltage()
1330 rdev_dbg(rdev, "override max_uV, %d -> %d\n", in machine_constraints_voltage()
1339 static int machine_constraints_current(struct regulator_dev *rdev, in machine_constraints_current() argument
1342 const struct regulator_ops *ops = rdev->desc->ops; in machine_constraints_current()
1349 rdev_err(rdev, "Invalid current constraints\n"); in machine_constraints_current()
1354 rdev_warn(rdev, "Operation of current configuration missing\n"); in machine_constraints_current()
1359 ret = ops->set_current_limit(rdev, constraints->min_uA, in machine_constraints_current()
1362 rdev_err(rdev, "Failed to set current constraint, %d\n", ret); in machine_constraints_current()
1369 static int _regulator_do_enable(struct regulator_dev *rdev);
1371 static int notif_set_limit(struct regulator_dev *rdev, in notif_set_limit() argument
1387 return set(rdev, limit, severity, enable); in notif_set_limit()
1390 static int handle_notify_limits(struct regulator_dev *rdev, in handle_notify_limits() argument
1400 ret = notif_set_limit(rdev, set, limits->prot, in handle_notify_limits()
1406 ret = notif_set_limit(rdev, set, limits->err, in handle_notify_limits()
1412 ret = notif_set_limit(rdev, set, limits->warn, in handle_notify_limits()
1429 static int set_machine_constraints(struct regulator_dev *rdev) in set_machine_constraints() argument
1432 const struct regulator_ops *ops = rdev->desc->ops; in set_machine_constraints()
1434 ret = machine_constraints_voltage(rdev, rdev->constraints); in set_machine_constraints()
1438 ret = machine_constraints_current(rdev, rdev->constraints); in set_machine_constraints()
1442 if (rdev->constraints->ilim_uA && ops->set_input_current_limit) { in set_machine_constraints()
1443 ret = ops->set_input_current_limit(rdev, in set_machine_constraints()
1444 rdev->constraints->ilim_uA); in set_machine_constraints()
1446 rdev_err(rdev, "failed to set input limit: %pe\n", ERR_PTR(ret)); in set_machine_constraints()
1452 if (rdev->constraints->initial_state) { in set_machine_constraints()
1453 ret = suspend_set_initial_state(rdev); in set_machine_constraints()
1455 rdev_err(rdev, "failed to set suspend state: %pe\n", ERR_PTR(ret)); in set_machine_constraints()
1460 if (rdev->constraints->initial_mode) { in set_machine_constraints()
1462 rdev_err(rdev, "no set_mode operation\n"); in set_machine_constraints()
1466 ret = ops->set_mode(rdev, rdev->constraints->initial_mode); in set_machine_constraints()
1468 rdev_err(rdev, "failed to set initial mode: %pe\n", ERR_PTR(ret)); in set_machine_constraints()
1471 } else if (rdev->constraints->system_load) { in set_machine_constraints()
1476 drms_uA_update(rdev); in set_machine_constraints()
1479 if ((rdev->constraints->ramp_delay || rdev->constraints->ramp_disable) in set_machine_constraints()
1481 ret = ops->set_ramp_delay(rdev, rdev->constraints->ramp_delay); in set_machine_constraints()
1483 rdev_err(rdev, "failed to set ramp_delay: %pe\n", ERR_PTR(ret)); in set_machine_constraints()
1488 if (rdev->constraints->pull_down && ops->set_pull_down) { in set_machine_constraints()
1489 ret = ops->set_pull_down(rdev); in set_machine_constraints()
1491 rdev_err(rdev, "failed to set pull down: %pe\n", ERR_PTR(ret)); in set_machine_constraints()
1496 if (rdev->constraints->soft_start && ops->set_soft_start) { in set_machine_constraints()
1497 ret = ops->set_soft_start(rdev); in set_machine_constraints()
1499 rdev_err(rdev, "failed to set soft start: %pe\n", ERR_PTR(ret)); in set_machine_constraints()
1518 if (rdev->constraints->over_current_protection in set_machine_constraints()
1520 int lim = rdev->constraints->over_curr_limits.prot; in set_machine_constraints()
1522 ret = ops->set_over_current_protection(rdev, lim, in set_machine_constraints()
1526 rdev_err(rdev, "failed to set over current protection: %pe\n", in set_machine_constraints()
1532 if (rdev->constraints->over_current_detection) in set_machine_constraints()
1533 ret = handle_notify_limits(rdev, in set_machine_constraints()
1535 &rdev->constraints->over_curr_limits); in set_machine_constraints()
1538 rdev_err(rdev, "failed to set over current limits: %pe\n", in set_machine_constraints()
1542 rdev_warn(rdev, in set_machine_constraints()
1546 if (rdev->constraints->over_voltage_detection) in set_machine_constraints()
1547 ret = handle_notify_limits(rdev, in set_machine_constraints()
1549 &rdev->constraints->over_voltage_limits); in set_machine_constraints()
1552 rdev_err(rdev, "failed to set over voltage limits %pe\n", in set_machine_constraints()
1556 rdev_warn(rdev, in set_machine_constraints()
1560 if (rdev->constraints->under_voltage_detection) in set_machine_constraints()
1561 ret = handle_notify_limits(rdev, in set_machine_constraints()
1563 &rdev->constraints->under_voltage_limits); in set_machine_constraints()
1566 rdev_err(rdev, "failed to set under voltage limits %pe\n", in set_machine_constraints()
1570 rdev_warn(rdev, in set_machine_constraints()
1574 if (rdev->constraints->over_temp_detection) in set_machine_constraints()
1575 ret = handle_notify_limits(rdev, in set_machine_constraints()
1577 &rdev->constraints->temp_limits); in set_machine_constraints()
1580 rdev_err(rdev, "failed to set temperature limits %pe\n", in set_machine_constraints()
1584 rdev_warn(rdev, in set_machine_constraints()
1588 if (rdev->constraints->active_discharge && ops->set_active_discharge) { in set_machine_constraints()
1589 bool ad_state = (rdev->constraints->active_discharge == in set_machine_constraints()
1592 ret = ops->set_active_discharge(rdev, ad_state); in set_machine_constraints()
1594 rdev_err(rdev, "failed to set active discharge: %pe\n", ERR_PTR(ret)); in set_machine_constraints()
1606 if (!rdev->ena_pin && !ops->enable) { in set_machine_constraints()
1607 if (rdev->supply_name && !rdev->supply) in set_machine_constraints()
1610 if (rdev->supply) in set_machine_constraints()
1611 rdev->constraints->always_on = in set_machine_constraints()
1612 rdev->supply->rdev->constraints->always_on; in set_machine_constraints()
1614 rdev->constraints->always_on = true; in set_machine_constraints()
1620 if (rdev->constraints->always_on || rdev->constraints->boot_on) { in set_machine_constraints()
1624 if (rdev->supply_name && !rdev->supply) in set_machine_constraints()
1631 if (rdev->supply && in set_machine_constraints()
1632 (rdev->constraints->always_on || in set_machine_constraints()
1633 !regulator_is_enabled(rdev->supply))) { in set_machine_constraints()
1634 ret = regulator_enable(rdev->supply); in set_machine_constraints()
1636 _regulator_put(rdev->supply); in set_machine_constraints()
1637 rdev->supply = NULL; in set_machine_constraints()
1642 ret = _regulator_do_enable(rdev); in set_machine_constraints()
1644 rdev_err(rdev, "failed to enable: %pe\n", ERR_PTR(ret)); in set_machine_constraints()
1648 if (rdev->constraints->always_on) in set_machine_constraints()
1649 rdev->use_count++; in set_machine_constraints()
1650 } else if (rdev->desc->off_on_delay) { in set_machine_constraints()
1651 rdev->last_off = ktime_get(); in set_machine_constraints()
1654 if (!rdev->constraints->pw_budget_mW) in set_machine_constraints()
1655 rdev->constraints->pw_budget_mW = INT_MAX; in set_machine_constraints()
1657 print_constraints(rdev); in set_machine_constraints()
1672 static int set_supply(struct regulator_dev *rdev, in set_supply() argument
1677 rdev_dbg(rdev, "supplied by %s\n", rdev_get_name(supply_rdev)); in set_supply()
1682 rdev->supply = create_regulator(supply_rdev, &rdev->dev, "SUPPLY"); in set_supply()
1683 if (rdev->supply == NULL) { in set_supply()
1706 static int set_consumer_device_supply(struct regulator_dev *rdev, in set_consumer_device_supply() argument
1725 new_node->regulator = rdev; in set_consumer_device_supply()
1753 dev_name(&rdev->dev), rdev_get_name(rdev)); in set_consumer_device_supply()
1769 static void unset_regulator_supplies(struct regulator_dev *rdev) in unset_regulator_supplies() argument
1774 if (rdev == node->regulator) { in unset_regulator_supplies()
1788 const struct regulation_constraints *c = regulator->rdev->constraints; in constraint_flags_read_file()
1833 static void link_and_create_debugfs(struct regulator *regulator, struct regulator_dev *rdev, in link_and_create_debugfs() argument
1842 err = sysfs_create_link_nowarn(&rdev->dev.kobj, &dev->kobj, in link_and_create_debugfs()
1845 rdev_dbg(rdev, "could not add device link %s: %pe\n", in link_and_create_debugfs()
1852 regulator->debugfs = debugfs_create_dir(regulator->supply_name, rdev->debugfs); in link_and_create_debugfs()
1854 rdev_dbg(rdev, "Failed to create debugfs directory\n"); in link_and_create_debugfs()
1871 static struct regulator *create_regulator(struct regulator_dev *rdev, in create_regulator() argument
1877 lockdep_assert_held_once(&rdev->mutex.base); in create_regulator()
1903 regulator->rdev = rdev; in create_regulator()
1906 list_add(®ulator->list, &rdev->consumer_list); in create_regulator()
1913 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_STATUS) && in create_regulator()
1914 _regulator_is_enabled(rdev)) in create_regulator()
1920 static int _regulator_get_enable_time(struct regulator_dev *rdev) in _regulator_get_enable_time() argument
1922 if (rdev->constraints && rdev->constraints->enable_time) in _regulator_get_enable_time()
1923 return rdev->constraints->enable_time; in _regulator_get_enable_time()
1924 if (rdev->desc->ops->enable_time) in _regulator_get_enable_time()
1925 return rdev->desc->ops->enable_time(rdev); in _regulator_get_enable_time()
1926 return rdev->desc->enable_time; in _regulator_get_enable_time()
2042 static int regulator_resolve_supply(struct regulator_dev *rdev) in regulator_resolve_supply() argument
2045 struct device *dev = rdev->dev.parent; in regulator_resolve_supply()
2050 if (!rdev->supply_name) in regulator_resolve_supply()
2054 if (rdev->supply) in regulator_resolve_supply()
2060 r = regulator_dt_lookup(&rdev->dev, rdev->supply_name); in regulator_resolve_supply()
2066 r = regulator_dev_lookup(dev, rdev->supply_name); in regulator_resolve_supply()
2084 rdev->supply_name, rdev->desc->name); in regulator_resolve_supply()
2090 if (r == rdev) { in regulator_resolve_supply()
2092 rdev->desc->name, rdev->supply_name); in regulator_resolve_supply()
2111 if (r->dev.parent && r->dev.parent != rdev->dev.parent) { in regulator_resolve_supply()
2131 regulator_lock_two(rdev, r, &ww_ctx); in regulator_resolve_supply()
2134 if (rdev->supply) { in regulator_resolve_supply()
2135 regulator_unlock_two(rdev, r, &ww_ctx); in regulator_resolve_supply()
2140 ret = set_supply(rdev, r); in regulator_resolve_supply()
2142 regulator_unlock_two(rdev, r, &ww_ctx); in regulator_resolve_supply()
2147 regulator_unlock_two(rdev, r, &ww_ctx); in regulator_resolve_supply()
2150 link_and_create_debugfs(rdev->supply, r, &rdev->dev); in regulator_resolve_supply()
2157 if (rdev->use_count) { in regulator_resolve_supply()
2158 ret = regulator_enable(rdev->supply); in regulator_resolve_supply()
2160 _regulator_put(rdev->supply); in regulator_resolve_supply()
2161 rdev->supply = NULL; in regulator_resolve_supply()
2200 struct regulator *_regulator_get_common(struct regulator_dev *rdev, struct device *dev, in _regulator_get_common() argument
2207 if (IS_ERR(rdev)) { in _regulator_get_common()
2208 ret = PTR_ERR(rdev); in _regulator_get_common()
2230 rdev = dummy_regulator_rdev; in _regulator_get_common()
2231 if (!rdev) in _regulator_get_common()
2234 get_device(&rdev->dev); in _regulator_get_common()
2247 if (rdev->exclusive) { in _regulator_get_common()
2249 put_device(&rdev->dev); in _regulator_get_common()
2253 if (get_type == EXCLUSIVE_GET && rdev->open_count) { in _regulator_get_common()
2255 put_device(&rdev->dev); in _regulator_get_common()
2260 ret = (rdev->coupling_desc.n_resolved != rdev->coupling_desc.n_coupled); in _regulator_get_common()
2265 put_device(&rdev->dev); in _regulator_get_common()
2269 ret = regulator_resolve_supply(rdev); in _regulator_get_common()
2272 put_device(&rdev->dev); in _regulator_get_common()
2276 if (!try_module_get(rdev->owner)) { in _regulator_get_common()
2278 put_device(&rdev->dev); in _regulator_get_common()
2282 regulator_lock(rdev); in _regulator_get_common()
2283 regulator = create_regulator(rdev, dev, id); in _regulator_get_common()
2284 regulator_unlock(rdev); in _regulator_get_common()
2287 module_put(rdev->owner); in _regulator_get_common()
2288 put_device(&rdev->dev); in _regulator_get_common()
2292 link_and_create_debugfs(regulator, rdev, dev); in _regulator_get_common()
2294 rdev->open_count++; in _regulator_get_common()
2296 rdev->exclusive = 1; in _regulator_get_common()
2298 ret = _regulator_is_enabled(rdev); in _regulator_get_common()
2300 rdev->use_count = 1; in _regulator_get_common()
2304 if (rdev->supply) { in _regulator_get_common()
2305 ret = regulator_enable(rdev->supply); in _regulator_get_common()
2308 module_put(rdev->owner); in _regulator_get_common()
2309 put_device(&rdev->dev); in _regulator_get_common()
2314 rdev->use_count = 0; in _regulator_get_common()
2319 link = device_link_add(dev, &rdev->dev, DL_FLAG_STATELESS); in _regulator_get_common()
2330 struct regulator_dev *rdev; in _regulator_get() local
2337 rdev = regulator_dev_lookup(dev, id); in _regulator_get()
2338 return _regulator_get_common(rdev, dev, id, get_type); in _regulator_get()
2416 struct regulator_dev *rdev = regulator->rdev; in destroy_regulator() local
2422 device_link_remove(regulator->dev, &rdev->dev); in destroy_regulator()
2425 sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name); in destroy_regulator()
2428 regulator_lock(rdev); in destroy_regulator()
2431 rdev->open_count--; in destroy_regulator()
2432 rdev->exclusive = 0; in destroy_regulator()
2433 regulator_unlock(rdev); in destroy_regulator()
2442 struct regulator_dev *rdev; in _regulator_put() local
2452 rdev = regulator->rdev; in _regulator_put()
2456 module_put(rdev->owner); in _regulator_put()
2457 put_device(&rdev->dev); in _regulator_put()
2608 static int regulator_ena_gpio_request(struct regulator_dev *rdev, in regulator_ena_gpio_request() argument
2621 rdev_dbg(rdev, "GPIO is already used\n"); in regulator_ena_gpio_request()
2639 rdev->ena_pin = pin; in regulator_ena_gpio_request()
2647 static void regulator_ena_gpio_free(struct regulator_dev *rdev) in regulator_ena_gpio_free() argument
2651 if (!rdev->ena_pin) in regulator_ena_gpio_free()
2656 if (pin != rdev->ena_pin) in regulator_ena_gpio_free()
2668 rdev->ena_pin = NULL; in regulator_ena_gpio_free()
2681 static int regulator_ena_gpio_ctrl(struct regulator_dev *rdev, bool enable) in regulator_ena_gpio_ctrl() argument
2683 struct regulator_enable_gpio *pin = rdev->ena_pin; in regulator_ena_gpio_ctrl()
2720 static inline int _regulator_check_status_enabled(struct regulator_dev *rdev) in _regulator_check_status_enabled() argument
2722 int ret = rdev->desc->ops->get_status(rdev); in _regulator_check_status_enabled()
2725 rdev_info(rdev, "get_status returned error: %d\n", ret); in _regulator_check_status_enabled()
2739 static int _regulator_do_enable(struct regulator_dev *rdev) in _regulator_do_enable() argument
2744 ret = _regulator_get_enable_time(rdev); in _regulator_do_enable()
2748 rdev_warn(rdev, "enable_time() failed: %pe\n", ERR_PTR(ret)); in _regulator_do_enable()
2752 trace_regulator_enable(rdev_get_name(rdev)); in _regulator_do_enable()
2754 if (rdev->desc->off_on_delay) { in _regulator_do_enable()
2758 ktime_t end = ktime_add_us(rdev->last_off, rdev->desc->off_on_delay); in _regulator_do_enable()
2765 if (rdev->ena_pin) { in _regulator_do_enable()
2766 if (!rdev->ena_gpio_state) { in _regulator_do_enable()
2767 ret = regulator_ena_gpio_ctrl(rdev, true); in _regulator_do_enable()
2770 rdev->ena_gpio_state = 1; in _regulator_do_enable()
2772 } else if (rdev->desc->ops->enable) { in _regulator_do_enable()
2773 ret = rdev->desc->ops->enable(rdev); in _regulator_do_enable()
2784 trace_regulator_enable_delay(rdev_get_name(rdev)); in _regulator_do_enable()
2792 if (rdev->desc->poll_enabled_time) { in _regulator_do_enable()
2796 fsleep(rdev->desc->poll_enabled_time); in _regulator_do_enable()
2798 if (rdev->desc->ops->get_status) { in _regulator_do_enable()
2799 ret = _regulator_check_status_enabled(rdev); in _regulator_do_enable()
2804 } else if (rdev->desc->ops->is_enabled(rdev)) in _regulator_do_enable()
2807 time_remaining -= rdev->desc->poll_enabled_time; in _regulator_do_enable()
2811 rdev_err(rdev, "Enabled check timed out\n"); in _regulator_do_enable()
2818 trace_regulator_enable_complete(rdev_get_name(rdev)); in _regulator_do_enable()
2846 struct regulator_dev *rdev = regulator->rdev; in _regulator_handle_consumer_enable() local
2848 lockdep_assert_held_once(&rdev->mutex.base); in _regulator_handle_consumer_enable()
2852 ret = drms_uA_update(rdev); in _regulator_handle_consumer_enable()
2871 struct regulator_dev *rdev = regulator->rdev; in _regulator_handle_consumer_disable() local
2873 lockdep_assert_held_once(&rdev->mutex.base); in _regulator_handle_consumer_disable()
2876 rdev_err(rdev, "Underflow of regulator enable count\n"); in _regulator_handle_consumer_disable()
2882 return drms_uA_update(rdev); in _regulator_handle_consumer_disable()
2890 struct regulator_dev *rdev = regulator->rdev; in _regulator_enable() local
2893 lockdep_assert_held_once(&rdev->mutex.base); in _regulator_enable()
2895 if (rdev->use_count == 0 && rdev->supply) { in _regulator_enable()
2896 ret = _regulator_enable(rdev->supply); in _regulator_enable()
2902 if (rdev->coupling_desc.n_coupled > 1) { in _regulator_enable()
2903 ret = regulator_balance_voltage(rdev, PM_SUSPEND_ON); in _regulator_enable()
2912 if (rdev->use_count == 0) { in _regulator_enable()
2917 ret = _regulator_is_enabled(rdev); in _regulator_enable()
2919 if (!regulator_ops_is_valid(rdev, in _regulator_enable()
2925 ret = _regulator_do_enable(rdev); in _regulator_enable()
2929 _notifier_call_chain(rdev, REGULATOR_EVENT_ENABLE, in _regulator_enable()
2932 rdev_err(rdev, "is_enabled() failed: %pe\n", ERR_PTR(ret)); in _regulator_enable()
2939 rdev->use_count++; in _regulator_enable()
2947 if (rdev->use_count == 0 && rdev->supply) in _regulator_enable()
2948 _regulator_disable(rdev->supply); in _regulator_enable()
2968 struct regulator_dev *rdev = regulator->rdev; in regulator_enable() local
2972 regulator_lock_dependent(rdev, &ww_ctx); in regulator_enable()
2974 regulator_unlock_dependent(rdev, &ww_ctx); in regulator_enable()
2980 static int _regulator_do_disable(struct regulator_dev *rdev) in _regulator_do_disable() argument
2984 trace_regulator_disable(rdev_get_name(rdev)); in _regulator_do_disable()
2986 if (rdev->ena_pin) { in _regulator_do_disable()
2987 if (rdev->ena_gpio_state) { in _regulator_do_disable()
2988 ret = regulator_ena_gpio_ctrl(rdev, false); in _regulator_do_disable()
2991 rdev->ena_gpio_state = 0; in _regulator_do_disable()
2994 } else if (rdev->desc->ops->disable) { in _regulator_do_disable()
2995 ret = rdev->desc->ops->disable(rdev); in _regulator_do_disable()
3000 if (rdev->desc->off_on_delay) in _regulator_do_disable()
3001 rdev->last_off = ktime_get_boottime(); in _regulator_do_disable()
3003 trace_regulator_disable_complete(rdev_get_name(rdev)); in _regulator_do_disable()
3011 struct regulator_dev *rdev = regulator->rdev; in _regulator_disable() local
3014 lockdep_assert_held_once(&rdev->mutex.base); in _regulator_disable()
3017 "unbalanced disables for %s\n", rdev_get_name(rdev))) in _regulator_disable()
3023 if (rdev->use_count == 1 && in _regulator_disable()
3024 (rdev->constraints && !rdev->constraints->always_on)) { in _regulator_disable()
3027 if (regulator_ops_is_valid(rdev, REGULATOR_CHANGE_STATUS)) { in _regulator_disable()
3028 ret = _notifier_call_chain(rdev, in _regulator_disable()
3034 ret = _regulator_do_disable(rdev); in _regulator_disable()
3036 rdev_err(rdev, "failed to disable: %pe\n", ERR_PTR(ret)); in _regulator_disable()
3037 _notifier_call_chain(rdev, in _regulator_disable()
3042 _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE, in _regulator_disable()
3046 rdev->use_count = 0; in _regulator_disable()
3047 } else if (rdev->use_count > 1) { in _regulator_disable()
3048 rdev->use_count--; in _regulator_disable()
3055 if (ret == 0 && rdev->coupling_desc.n_coupled > 1) in _regulator_disable()
3056 ret = regulator_balance_voltage(rdev, PM_SUSPEND_ON); in _regulator_disable()
3058 if (ret == 0 && rdev->use_count == 0 && rdev->supply) in _regulator_disable()
3059 ret = _regulator_disable(rdev->supply); in _regulator_disable()
3080 struct regulator_dev *rdev = regulator->rdev; in regulator_disable() local
3084 regulator_lock_dependent(rdev, &ww_ctx); in regulator_disable()
3086 regulator_unlock_dependent(rdev, &ww_ctx); in regulator_disable()
3093 static int _regulator_force_disable(struct regulator_dev *rdev) in _regulator_force_disable() argument
3097 lockdep_assert_held_once(&rdev->mutex.base); in _regulator_force_disable()
3099 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE | in _regulator_force_disable()
3104 ret = _regulator_do_disable(rdev); in _regulator_force_disable()
3106 rdev_err(rdev, "failed to force disable: %pe\n", ERR_PTR(ret)); in _regulator_force_disable()
3107 _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE | in _regulator_force_disable()
3112 _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE | in _regulator_force_disable()
3131 struct regulator_dev *rdev = regulator->rdev; in regulator_force_disable() local
3135 regulator_lock_dependent(rdev, &ww_ctx); in regulator_force_disable()
3137 ret = _regulator_force_disable(regulator->rdev); in regulator_force_disable()
3139 if (rdev->coupling_desc.n_coupled > 1) in regulator_force_disable()
3140 regulator_balance_voltage(rdev, PM_SUSPEND_ON); in regulator_force_disable()
3144 ret = drms_uA_update(rdev); in regulator_force_disable()
3147 if (rdev->use_count != 0 && rdev->supply) in regulator_force_disable()
3148 _regulator_disable(rdev->supply); in regulator_force_disable()
3150 regulator_unlock_dependent(rdev, &ww_ctx); in regulator_force_disable()
3158 struct regulator_dev *rdev = container_of(work, struct regulator_dev, in regulator_disable_work() local
3165 regulator_lock_dependent(rdev, &ww_ctx); in regulator_disable_work()
3173 cancel_delayed_work(&rdev->disable_work); in regulator_disable_work()
3175 list_for_each_entry(regulator, &rdev->consumer_list, list) { in regulator_disable_work()
3187 rdev_err(rdev, "Deferred disable failed: %pe\n", in regulator_disable_work()
3193 if (rdev->coupling_desc.n_coupled > 1) in regulator_disable_work()
3194 regulator_balance_voltage(rdev, PM_SUSPEND_ON); in regulator_disable_work()
3196 regulator_unlock_dependent(rdev, &ww_ctx); in regulator_disable_work()
3215 struct regulator_dev *rdev = regulator->rdev; in regulator_disable_deferred() local
3220 regulator_lock(rdev); in regulator_disable_deferred()
3222 mod_delayed_work(system_power_efficient_wq, &rdev->disable_work, in regulator_disable_deferred()
3224 regulator_unlock(rdev); in regulator_disable_deferred()
3230 static int _regulator_is_enabled(struct regulator_dev *rdev) in _regulator_is_enabled() argument
3233 if (rdev->ena_pin) in _regulator_is_enabled()
3234 return rdev->ena_gpio_state; in _regulator_is_enabled()
3237 if (!rdev->desc->ops->is_enabled) in _regulator_is_enabled()
3240 return rdev->desc->ops->is_enabled(rdev); in _regulator_is_enabled()
3243 static int _regulator_list_voltage(struct regulator_dev *rdev, in _regulator_list_voltage() argument
3246 const struct regulator_ops *ops = rdev->desc->ops; in _regulator_list_voltage()
3249 if (rdev->desc->fixed_uV && rdev->desc->n_voltages == 1 && !selector) in _regulator_list_voltage()
3250 return rdev->desc->fixed_uV; in _regulator_list_voltage()
3253 if (selector >= rdev->desc->n_voltages) in _regulator_list_voltage()
3255 if (selector < rdev->desc->linear_min_sel) in _regulator_list_voltage()
3258 regulator_lock(rdev); in _regulator_list_voltage()
3259 ret = ops->list_voltage(rdev, selector); in _regulator_list_voltage()
3261 regulator_unlock(rdev); in _regulator_list_voltage()
3262 } else if (rdev->is_switch && rdev->supply) { in _regulator_list_voltage()
3263 ret = _regulator_list_voltage(rdev->supply->rdev, in _regulator_list_voltage()
3270 if (ret < rdev->constraints->min_uV) in _regulator_list_voltage()
3272 else if (ret > rdev->constraints->max_uV) in _regulator_list_voltage()
3298 regulator_lock(regulator->rdev); in regulator_is_enabled()
3299 ret = _regulator_is_enabled(regulator->rdev); in regulator_is_enabled()
3300 regulator_unlock(regulator->rdev); in regulator_is_enabled()
3317 struct regulator_dev *rdev = regulator->rdev; in regulator_count_voltages() local
3319 if (rdev->desc->n_voltages) in regulator_count_voltages()
3320 return rdev->desc->n_voltages; in regulator_count_voltages()
3322 if (!rdev->is_switch || !rdev->supply) in regulator_count_voltages()
3325 return regulator_count_voltages(rdev->supply); in regulator_count_voltages()
3341 return _regulator_list_voltage(regulator->rdev, selector, 1); in regulator_list_voltage()
3354 struct regmap *map = regulator->rdev->regmap; in regulator_get_regmap()
3381 struct regulator_dev *rdev = regulator->rdev; in regulator_get_hardware_vsel_register() local
3382 const struct regulator_ops *ops = rdev->desc->ops; in regulator_get_hardware_vsel_register()
3387 *vsel_reg = rdev->desc->vsel_reg; in regulator_get_hardware_vsel_register()
3388 *vsel_mask = rdev->desc->vsel_mask; in regulator_get_hardware_vsel_register()
3410 struct regulator_dev *rdev = regulator->rdev; in regulator_list_hardware_vsel() local
3411 const struct regulator_ops *ops = rdev->desc->ops; in regulator_list_hardware_vsel()
3413 if (selector >= rdev->desc->n_voltages) in regulator_list_hardware_vsel()
3415 if (selector < rdev->desc->linear_min_sel) in regulator_list_hardware_vsel()
3436 struct regulator_dev *rdev = regulator->rdev; in regulator_hardware_enable() local
3437 const struct regulator_ops *ops = rdev->desc->ops; in regulator_hardware_enable()
3440 if (!rdev->exclusive || !ops || !ops->enable || !ops->disable) in regulator_hardware_enable()
3444 ret = ops->enable(rdev); in regulator_hardware_enable()
3446 ret = ops->disable(rdev); in regulator_hardware_enable()
3461 struct regulator_dev *rdev = regulator->rdev; in regulator_get_linear_step() local
3463 return rdev->desc->uV_step; in regulator_get_linear_step()
3481 struct regulator_dev *rdev = regulator->rdev; in regulator_is_supported_voltage() local
3485 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) { in regulator_is_supported_voltage()
3494 if (rdev->desc->continuous_voltage_range) in regulator_is_supported_voltage()
3495 return min_uV >= rdev->constraints->min_uV && in regulator_is_supported_voltage()
3496 max_uV <= rdev->constraints->max_uV; in regulator_is_supported_voltage()
3514 static int regulator_map_voltage(struct regulator_dev *rdev, int min_uV, in regulator_map_voltage() argument
3517 const struct regulator_desc *desc = rdev->desc; in regulator_map_voltage()
3520 return desc->ops->map_voltage(rdev, min_uV, max_uV); in regulator_map_voltage()
3523 return regulator_map_voltage_linear(rdev, min_uV, max_uV); in regulator_map_voltage()
3526 return regulator_map_voltage_linear_range(rdev, min_uV, max_uV); in regulator_map_voltage()
3530 return regulator_map_voltage_pickable_linear_range(rdev, in regulator_map_voltage()
3533 return regulator_map_voltage_iterate(rdev, min_uV, max_uV); in regulator_map_voltage()
3536 static int _regulator_call_set_voltage(struct regulator_dev *rdev, in _regulator_call_set_voltage() argument
3543 data.old_uV = regulator_get_voltage_rdev(rdev); in _regulator_call_set_voltage()
3546 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_PRE_VOLTAGE_CHANGE, in _regulator_call_set_voltage()
3551 ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV, selector); in _regulator_call_set_voltage()
3555 _notifier_call_chain(rdev, REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE, in _regulator_call_set_voltage()
3561 static int _regulator_call_set_voltage_sel(struct regulator_dev *rdev, in _regulator_call_set_voltage_sel() argument
3567 data.old_uV = regulator_get_voltage_rdev(rdev); in _regulator_call_set_voltage_sel()
3570 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_PRE_VOLTAGE_CHANGE, in _regulator_call_set_voltage_sel()
3575 ret = rdev->desc->ops->set_voltage_sel(rdev, selector); in _regulator_call_set_voltage_sel()
3579 _notifier_call_chain(rdev, REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE, in _regulator_call_set_voltage_sel()
3585 static int _regulator_set_voltage_sel_step(struct regulator_dev *rdev, in _regulator_set_voltage_sel_step() argument
3588 const struct regulator_ops *ops = rdev->desc->ops; in _regulator_set_voltage_sel_step()
3592 if (!_regulator_is_enabled(rdev)) in _regulator_set_voltage_sel_step()
3598 old_sel = ops->get_voltage_sel(rdev); in _regulator_set_voltage_sel_step()
3608 for (curr_sel = old_sel + rdev->desc->vsel_step; in _regulator_set_voltage_sel_step()
3610 curr_sel += rdev->desc->vsel_step) { in _regulator_set_voltage_sel_step()
3617 ret = ops->set_voltage_sel(rdev, curr_sel); in _regulator_set_voltage_sel_step()
3623 for (curr_sel = old_sel - rdev->desc->vsel_step; in _regulator_set_voltage_sel_step()
3625 curr_sel -= rdev->desc->vsel_step) { in _regulator_set_voltage_sel_step()
3626 ret = ops->set_voltage_sel(rdev, curr_sel); in _regulator_set_voltage_sel_step()
3634 return _regulator_call_set_voltage_sel(rdev, uV, new_selector); in _regulator_set_voltage_sel_step()
3641 (void)ops->set_voltage_sel(rdev, old_sel); in _regulator_set_voltage_sel_step()
3645 static int _regulator_set_voltage_time(struct regulator_dev *rdev, in _regulator_set_voltage_time() argument
3650 if (rdev->constraints->ramp_delay) in _regulator_set_voltage_time()
3651 ramp_delay = rdev->constraints->ramp_delay; in _regulator_set_voltage_time()
3652 else if (rdev->desc->ramp_delay) in _regulator_set_voltage_time()
3653 ramp_delay = rdev->desc->ramp_delay; in _regulator_set_voltage_time()
3654 else if (rdev->constraints->settling_time) in _regulator_set_voltage_time()
3655 return rdev->constraints->settling_time; in _regulator_set_voltage_time()
3656 else if (rdev->constraints->settling_time_up && in _regulator_set_voltage_time()
3658 return rdev->constraints->settling_time_up; in _regulator_set_voltage_time()
3659 else if (rdev->constraints->settling_time_down && in _regulator_set_voltage_time()
3661 return rdev->constraints->settling_time_down; in _regulator_set_voltage_time()
3669 static int _regulator_do_set_voltage(struct regulator_dev *rdev, in _regulator_do_set_voltage() argument
3677 const struct regulator_ops *ops = rdev->desc->ops; in _regulator_do_set_voltage()
3678 int old_uV = regulator_get_voltage_rdev(rdev); in _regulator_do_set_voltage()
3680 trace_regulator_set_voltage(rdev_get_name(rdev), min_uV, max_uV); in _regulator_do_set_voltage()
3682 min_uV += rdev->constraints->uV_offset; in _regulator_do_set_voltage()
3683 max_uV += rdev->constraints->uV_offset; in _regulator_do_set_voltage()
3689 if (_regulator_is_enabled(rdev) && in _regulator_do_set_voltage()
3691 old_selector = ops->get_voltage_sel(rdev); in _regulator_do_set_voltage()
3697 ret = _regulator_call_set_voltage(rdev, min_uV, max_uV, in _regulator_do_set_voltage()
3702 best_val = ops->list_voltage(rdev, in _regulator_do_set_voltage()
3705 best_val = regulator_get_voltage_rdev(rdev); in _regulator_do_set_voltage()
3709 ret = regulator_map_voltage(rdev, min_uV, max_uV); in _regulator_do_set_voltage()
3711 best_val = ops->list_voltage(rdev, ret); in _regulator_do_set_voltage()
3716 else if (rdev->desc->vsel_step) in _regulator_do_set_voltage()
3718 rdev, best_val, selector); in _regulator_do_set_voltage()
3721 rdev, best_val, selector); in _regulator_do_set_voltage()
3739 delay = ops->set_voltage_time_sel(rdev, old_selector, in _regulator_do_set_voltage()
3744 delay = ops->set_voltage_time(rdev, old_uV, in _regulator_do_set_voltage()
3747 delay = _regulator_set_voltage_time(rdev, in _regulator_do_set_voltage()
3754 rdev_warn(rdev, "failed to get delay: %pe\n", ERR_PTR(delay)); in _regulator_do_set_voltage()
3764 _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, in _regulator_do_set_voltage()
3769 trace_regulator_set_voltage_complete(rdev_get_name(rdev), best_val); in _regulator_do_set_voltage()
3774 static int _regulator_do_set_suspend_voltage(struct regulator_dev *rdev, in _regulator_do_set_suspend_voltage() argument
3780 rstate = regulator_get_suspend_state(rdev, state); in _regulator_do_set_suspend_voltage()
3789 sel = regulator_map_voltage(rdev, min_uV, max_uV); in _regulator_do_set_suspend_voltage()
3793 uV = rdev->desc->ops->list_voltage(rdev, sel); in _regulator_do_set_suspend_voltage()
3800 static int regulator_get_voltage_delta(struct regulator_dev *rdev, int uV) in regulator_get_voltage_delta() argument
3802 int current_uV = regulator_get_voltage_rdev(rdev); in regulator_get_voltage_delta()
3814 struct regulator_dev *rdev = regulator->rdev; in regulator_set_voltage_unlocked() local
3831 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) { in regulator_set_voltage_unlocked()
3832 current_uV = regulator_get_voltage_rdev(rdev); in regulator_set_voltage_unlocked()
3841 if (!rdev->desc->ops->set_voltage && in regulator_set_voltage_unlocked()
3842 !rdev->desc->ops->set_voltage_sel) { in regulator_set_voltage_unlocked()
3848 ret = regulator_check_voltage(rdev, &min_uV, &max_uV); in regulator_set_voltage_unlocked()
3859 ret = regulator_balance_voltage(rdev, state); in regulator_set_voltage_unlocked()
3865 if (rdev->constraints->max_uV_step > 0) { in regulator_set_voltage_unlocked()
3869 ret = regulator_get_voltage_delta(rdev, min_uV); in regulator_set_voltage_unlocked()
3876 ret = regulator_balance_voltage(rdev, state); in regulator_set_voltage_unlocked()
3880 ret = regulator_get_voltage_delta(rdev, min_uV); in regulator_set_voltage_unlocked()
3887 if (delta - new_delta < rdev->constraints->max_uV_step) { in regulator_set_voltage_unlocked()
3900 int regulator_set_voltage_rdev(struct regulator_dev *rdev, int min_uV, in regulator_set_voltage_rdev() argument
3907 if (rdev->supply && in regulator_set_voltage_rdev()
3908 regulator_ops_is_valid(rdev->supply->rdev, in regulator_set_voltage_rdev()
3910 (rdev->desc->min_dropout_uV || !(rdev->desc->ops->get_voltage || in regulator_set_voltage_rdev()
3911 rdev->desc->ops->get_voltage_sel))) { in regulator_set_voltage_rdev()
3915 selector = regulator_map_voltage(rdev, min_uV, max_uV); in regulator_set_voltage_rdev()
3921 best_supply_uV = _regulator_list_voltage(rdev, selector, 0); in regulator_set_voltage_rdev()
3927 best_supply_uV += rdev->desc->min_dropout_uV; in regulator_set_voltage_rdev()
3929 current_supply_uV = regulator_get_voltage_rdev(rdev->supply->rdev); in regulator_set_voltage_rdev()
3939 ret = regulator_set_voltage_unlocked(rdev->supply, in regulator_set_voltage_rdev()
3942 dev_err(&rdev->dev, "Failed to increase supply voltage: %pe\n", in regulator_set_voltage_rdev()
3949 ret = _regulator_do_set_voltage(rdev, min_uV, max_uV); in regulator_set_voltage_rdev()
3951 ret = _regulator_do_set_suspend_voltage(rdev, min_uV, in regulator_set_voltage_rdev()
3957 ret = regulator_set_voltage_unlocked(rdev->supply, in regulator_set_voltage_rdev()
3960 dev_warn(&rdev->dev, "Failed to decrease supply voltage: %pe\n", in regulator_set_voltage_rdev()
3971 static int regulator_limit_voltage_step(struct regulator_dev *rdev, in regulator_limit_voltage_step() argument
3974 struct regulation_constraints *constraints = rdev->constraints; in regulator_limit_voltage_step()
3977 if (!constraints->max_uV_step || !_regulator_is_enabled(rdev)) in regulator_limit_voltage_step()
3981 *current_uV = regulator_get_voltage_rdev(rdev); in regulator_limit_voltage_step()
4001 static int regulator_get_optimal_voltage(struct regulator_dev *rdev, in regulator_get_optimal_voltage() argument
4007 struct coupling_desc *c_desc = &rdev->coupling_desc; in regulator_get_optimal_voltage()
4009 struct regulation_constraints *constraints = rdev->constraints; in regulator_get_optimal_voltage()
4030 ret = regulator_check_consumers(rdev, in regulator_get_optimal_voltage()
4114 ret = regulator_limit_voltage_step(rdev, current_uV, in regulator_get_optimal_voltage()
4126 if (_regulator_is_enabled(rdev)) { in regulator_get_optimal_voltage()
4127 ret = regulator_get_voltage_rdev(rdev); in regulator_get_optimal_voltage()
4143 int regulator_do_balance_voltage(struct regulator_dev *rdev, in regulator_do_balance_voltage() argument
4148 struct coupling_desc *c_desc = &rdev->coupling_desc; in regulator_do_balance_voltage()
4226 static int regulator_balance_voltage(struct regulator_dev *rdev, in regulator_balance_voltage() argument
4229 struct coupling_desc *c_desc = &rdev->coupling_desc; in regulator_balance_voltage()
4241 rdev_err(rdev, "Not all coupled regulators registered\n"); in regulator_balance_voltage()
4247 return coupler->balance_voltage(coupler, rdev, state); in regulator_balance_voltage()
4249 return regulator_do_balance_voltage(rdev, state, skip_coupled); in regulator_balance_voltage()
4277 regulator_lock_dependent(regulator->rdev, &ww_ctx); in regulator_set_voltage()
4282 regulator_unlock_dependent(regulator->rdev, &ww_ctx); in regulator_set_voltage()
4288 static inline int regulator_suspend_toggle(struct regulator_dev *rdev, in regulator_suspend_toggle() argument
4293 rstate = regulator_get_suspend_state(rdev, state); in regulator_suspend_toggle()
4305 int regulator_suspend_enable(struct regulator_dev *rdev, in regulator_suspend_enable() argument
4308 return regulator_suspend_toggle(rdev, state, true); in regulator_suspend_enable()
4312 int regulator_suspend_disable(struct regulator_dev *rdev, in regulator_suspend_disable() argument
4322 list_for_each_entry(regulator, &rdev->consumer_list, list) { in regulator_suspend_disable()
4328 return regulator_suspend_toggle(rdev, state, false); in regulator_suspend_disable()
4336 struct regulator_dev *rdev = regulator->rdev; in _regulator_set_suspend_voltage() local
4339 rstate = regulator_get_suspend_state(rdev, state); in _regulator_set_suspend_voltage()
4344 rdev_err(rdev, "The suspend voltage can't be changed!\n"); in _regulator_set_suspend_voltage()
4361 regulator_lock_dependent(regulator->rdev, &ww_ctx); in regulator_set_suspend_voltage()
4366 regulator_unlock_dependent(regulator->rdev, &ww_ctx); in regulator_set_suspend_voltage()
4387 struct regulator_dev *rdev = regulator->rdev; in regulator_set_voltage_time() local
4388 const struct regulator_ops *ops = rdev->desc->ops; in regulator_set_voltage_time()
4395 return ops->set_voltage_time(rdev, old_uV, new_uV); in regulator_set_voltage_time()
4397 return _regulator_set_voltage_time(rdev, old_uV, new_uV); in regulator_set_voltage_time()
4400 if (!ops->list_voltage || !rdev->desc->n_voltages) in regulator_set_voltage_time()
4403 for (i = 0; i < rdev->desc->n_voltages; i++) { in regulator_set_voltage_time()
4405 if (i < rdev->desc->linear_min_sel) in regulator_set_voltage_time()
4425 return ops->set_voltage_time_sel(rdev, old_sel, new_sel); in regulator_set_voltage_time()
4443 int regulator_set_voltage_time_sel(struct regulator_dev *rdev, in regulator_set_voltage_time_sel() argument
4450 if (!rdev->desc->ops->list_voltage) in regulator_set_voltage_time_sel()
4453 old_volt = rdev->desc->ops->list_voltage(rdev, old_selector); in regulator_set_voltage_time_sel()
4454 new_volt = rdev->desc->ops->list_voltage(rdev, new_selector); in regulator_set_voltage_time_sel()
4456 if (rdev->desc->ops->set_voltage_time) in regulator_set_voltage_time_sel()
4457 return rdev->desc->ops->set_voltage_time(rdev, old_volt, in regulator_set_voltage_time_sel()
4460 return _regulator_set_voltage_time(rdev, old_volt, new_volt); in regulator_set_voltage_time_sel()
4464 int regulator_sync_voltage_rdev(struct regulator_dev *rdev) in regulator_sync_voltage_rdev() argument
4468 regulator_lock(rdev); in regulator_sync_voltage_rdev()
4470 if (!rdev->desc->ops->set_voltage && in regulator_sync_voltage_rdev()
4471 !rdev->desc->ops->set_voltage_sel) { in regulator_sync_voltage_rdev()
4477 if (rdev->coupling_desc.n_coupled > 1) in regulator_sync_voltage_rdev()
4478 ret = regulator_balance_voltage(rdev, PM_SUSPEND_ON); in regulator_sync_voltage_rdev()
4483 regulator_unlock(rdev); in regulator_sync_voltage_rdev()
4499 struct regulator_dev *rdev = regulator->rdev; in regulator_sync_voltage() local
4503 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) in regulator_sync_voltage()
4506 regulator_lock(rdev); in regulator_sync_voltage()
4508 if (!rdev->desc->ops->set_voltage && in regulator_sync_voltage()
4509 !rdev->desc->ops->set_voltage_sel) { in regulator_sync_voltage()
4524 ret = regulator_check_voltage(rdev, &min_uV, &max_uV); in regulator_sync_voltage()
4528 ret = regulator_check_consumers(rdev, &min_uV, &max_uV, 0); in regulator_sync_voltage()
4533 if (rdev->coupling_desc.n_coupled > 1) in regulator_sync_voltage()
4534 ret = regulator_balance_voltage(rdev, PM_SUSPEND_ON); in regulator_sync_voltage()
4536 ret = _regulator_do_set_voltage(rdev, min_uV, max_uV); in regulator_sync_voltage()
4539 regulator_unlock(rdev); in regulator_sync_voltage()
4544 int regulator_get_voltage_rdev(struct regulator_dev *rdev) in regulator_get_voltage_rdev() argument
4549 if (rdev->desc->ops->get_bypass) { in regulator_get_voltage_rdev()
4550 ret = rdev->desc->ops->get_bypass(rdev, &bypassed); in regulator_get_voltage_rdev()
4555 if (!rdev->supply) { in regulator_get_voltage_rdev()
4556 rdev_err(rdev, in regulator_get_voltage_rdev()
4561 return regulator_get_voltage_rdev(rdev->supply->rdev); in regulator_get_voltage_rdev()
4565 if (rdev->desc->ops->get_voltage_sel) { in regulator_get_voltage_rdev()
4566 sel = rdev->desc->ops->get_voltage_sel(rdev); in regulator_get_voltage_rdev()
4569 ret = rdev->desc->ops->list_voltage(rdev, sel); in regulator_get_voltage_rdev()
4570 } else if (rdev->desc->ops->get_voltage) { in regulator_get_voltage_rdev()
4571 ret = rdev->desc->ops->get_voltage(rdev); in regulator_get_voltage_rdev()
4572 } else if (rdev->desc->ops->list_voltage) { in regulator_get_voltage_rdev()
4573 ret = rdev->desc->ops->list_voltage(rdev, 0); in regulator_get_voltage_rdev()
4574 } else if (rdev->desc->fixed_uV && (rdev->desc->n_voltages == 1)) { in regulator_get_voltage_rdev()
4575 ret = rdev->desc->fixed_uV; in regulator_get_voltage_rdev()
4576 } else if (rdev->supply) { in regulator_get_voltage_rdev()
4577 ret = regulator_get_voltage_rdev(rdev->supply->rdev); in regulator_get_voltage_rdev()
4578 } else if (rdev->supply_name) { in regulator_get_voltage_rdev()
4586 return ret - rdev->constraints->uV_offset; in regulator_get_voltage_rdev()
4604 regulator_lock_dependent(regulator->rdev, &ww_ctx); in regulator_get_voltage()
4605 ret = regulator_get_voltage_rdev(regulator->rdev); in regulator_get_voltage()
4606 regulator_unlock_dependent(regulator->rdev, &ww_ctx); in regulator_get_voltage()
4633 struct regulator_dev *rdev = regulator->rdev; in regulator_set_current_limit() local
4636 regulator_lock(rdev); in regulator_set_current_limit()
4639 if (!rdev->desc->ops->set_current_limit) { in regulator_set_current_limit()
4645 ret = regulator_check_current_limit(rdev, &min_uA, &max_uA); in regulator_set_current_limit()
4649 ret = rdev->desc->ops->set_current_limit(rdev, min_uA, max_uA); in regulator_set_current_limit()
4651 regulator_unlock(rdev); in regulator_set_current_limit()
4656 static int _regulator_get_current_limit_unlocked(struct regulator_dev *rdev) in _regulator_get_current_limit_unlocked() argument
4659 if (!rdev->desc->ops->get_current_limit) in _regulator_get_current_limit_unlocked()
4662 return rdev->desc->ops->get_current_limit(rdev); in _regulator_get_current_limit_unlocked()
4665 static int _regulator_get_current_limit(struct regulator_dev *rdev) in _regulator_get_current_limit() argument
4669 regulator_lock(rdev); in _regulator_get_current_limit()
4670 ret = _regulator_get_current_limit_unlocked(rdev); in _regulator_get_current_limit()
4671 regulator_unlock(rdev); in _regulator_get_current_limit()
4688 return _regulator_get_current_limit(regulator->rdev); in regulator_get_current_limit()
4700 return regulator->rdev->constraints->pw_budget_mW - in regulator_get_unclaimed_power_budget()
4701 regulator->rdev->pw_requested_mW; in regulator_get_unclaimed_power_budget()
4715 struct regulator_dev *rdev = regulator->rdev; in regulator_request_power_budget() local
4718 regulator_lock(rdev); in regulator_request_power_budget()
4719 if (rdev->supply) { in regulator_request_power_budget()
4720 ret = regulator_request_power_budget(rdev->supply, pw_req); in regulator_request_power_budget()
4725 pw_tot_req = rdev->pw_requested_mW + pw_req; in regulator_request_power_budget()
4726 if (pw_tot_req > rdev->constraints->pw_budget_mW) { in regulator_request_power_budget()
4727 rdev_warn(rdev, "power requested %d mW out of budget %d mW", in regulator_request_power_budget()
4729 rdev->constraints->pw_budget_mW - rdev->pw_requested_mW); in regulator_request_power_budget()
4730 regulator_notifier_call_chain(rdev, in regulator_request_power_budget()
4737 rdev->pw_requested_mW = pw_tot_req; in regulator_request_power_budget()
4739 regulator_unlock(rdev); in regulator_request_power_budget()
4754 struct regulator_dev *rdev = regulator->rdev; in regulator_free_power_budget() local
4757 regulator_lock(rdev); in regulator_free_power_budget()
4758 if (rdev->supply) in regulator_free_power_budget()
4759 regulator_free_power_budget(rdev->supply, pw); in regulator_free_power_budget()
4761 pw_tot_req = rdev->pw_requested_mW - pw; in regulator_free_power_budget()
4763 rdev->pw_requested_mW = pw_tot_req; in regulator_free_power_budget()
4765 rdev_warn(rdev, in regulator_free_power_budget()
4767 pw, rdev->pw_requested_mW); in regulator_free_power_budget()
4769 regulator_unlock(rdev); in regulator_free_power_budget()
4788 struct regulator_dev *rdev = regulator->rdev; in regulator_set_mode() local
4792 regulator_lock(rdev); in regulator_set_mode()
4795 if (!rdev->desc->ops->set_mode) { in regulator_set_mode()
4801 if (rdev->desc->ops->get_mode) { in regulator_set_mode()
4802 regulator_curr_mode = rdev->desc->ops->get_mode(rdev); in regulator_set_mode()
4810 ret = regulator_mode_constrain(rdev, &mode); in regulator_set_mode()
4814 ret = rdev->desc->ops->set_mode(rdev, mode); in regulator_set_mode()
4816 regulator_unlock(rdev); in regulator_set_mode()
4821 static unsigned int _regulator_get_mode_unlocked(struct regulator_dev *rdev) in _regulator_get_mode_unlocked() argument
4824 if (!rdev->desc->ops->get_mode) in _regulator_get_mode_unlocked()
4827 return rdev->desc->ops->get_mode(rdev); in _regulator_get_mode_unlocked()
4830 static unsigned int _regulator_get_mode(struct regulator_dev *rdev) in _regulator_get_mode() argument
4834 regulator_lock(rdev); in _regulator_get_mode()
4835 ret = _regulator_get_mode_unlocked(rdev); in _regulator_get_mode()
4836 regulator_unlock(rdev); in _regulator_get_mode()
4852 return _regulator_get_mode(regulator->rdev); in regulator_get_mode()
4856 static int rdev_get_cached_err_flags(struct regulator_dev *rdev) in rdev_get_cached_err_flags() argument
4860 if (rdev->use_cached_err) { in rdev_get_cached_err_flags()
4861 spin_lock(&rdev->err_lock); in rdev_get_cached_err_flags()
4862 ret = rdev->cached_err; in rdev_get_cached_err_flags()
4863 spin_unlock(&rdev->err_lock); in rdev_get_cached_err_flags()
4868 static int _regulator_get_error_flags(struct regulator_dev *rdev, in _regulator_get_error_flags() argument
4873 regulator_lock(rdev); in _regulator_get_error_flags()
4875 cached_flags = rdev_get_cached_err_flags(rdev); in _regulator_get_error_flags()
4877 if (rdev->desc->ops->get_error_flags) in _regulator_get_error_flags()
4878 ret = rdev->desc->ops->get_error_flags(rdev, flags); in _regulator_get_error_flags()
4879 else if (!rdev->use_cached_err) in _regulator_get_error_flags()
4884 regulator_unlock(rdev); in _regulator_get_error_flags()
4901 return _regulator_get_error_flags(regulator->rdev, flags); in regulator_get_error_flags()
4941 struct regulator_dev *rdev = regulator->rdev; in regulator_set_load() local
4945 regulator_lock(rdev); in regulator_set_load()
4949 ret = drms_uA_update(rdev); in regulator_set_load()
4953 regulator_unlock(rdev); in regulator_set_load()
4975 struct regulator_dev *rdev = regulator->rdev; in regulator_allow_bypass() local
4976 const char *name = rdev_get_name(rdev); in regulator_allow_bypass()
4979 if (!rdev->desc->ops->set_bypass) in regulator_allow_bypass()
4982 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_BYPASS)) in regulator_allow_bypass()
4985 regulator_lock(rdev); in regulator_allow_bypass()
4988 rdev->bypass_count++; in regulator_allow_bypass()
4990 if (rdev->bypass_count == rdev->open_count) { in regulator_allow_bypass()
4993 ret = rdev->desc->ops->set_bypass(rdev, enable); in regulator_allow_bypass()
4995 rdev->bypass_count--; in regulator_allow_bypass()
5001 rdev->bypass_count--; in regulator_allow_bypass()
5003 if (rdev->bypass_count != rdev->open_count) { in regulator_allow_bypass()
5006 ret = rdev->desc->ops->set_bypass(rdev, enable); in regulator_allow_bypass()
5008 rdev->bypass_count++; in regulator_allow_bypass()
5017 regulator_unlock(rdev); in regulator_allow_bypass()
5035 return blocking_notifier_chain_register(®ulator->rdev->notifier, in regulator_register_notifier()
5052 return blocking_notifier_chain_unregister(®ulator->rdev->notifier, in regulator_unregister_notifier()
5060 static int _notifier_call_chain(struct regulator_dev *rdev, in _notifier_call_chain() argument
5064 int ret = blocking_notifier_call_chain(&rdev->notifier, event, data); in _notifier_call_chain()
5067 struct device *parent = rdev->dev.parent; in _notifier_call_chain()
5068 const char *rname = rdev_get_name(rdev); in _notifier_call_chain()
5072 if (parent && rname == rdev->desc->name) { in _notifier_call_chain()
5304 static void regulator_handle_critical(struct regulator_dev *rdev, in regulator_handle_critical() argument
5309 if (!rdev->constraints->system_critical) in regulator_handle_critical()
5327 rdev->constraints->uv_less_critical_window_ms); in regulator_handle_critical()
5341 int regulator_notifier_call_chain(struct regulator_dev *rdev, in regulator_notifier_call_chain() argument
5344 regulator_handle_critical(rdev, event); in regulator_notifier_call_chain()
5346 _notifier_call_chain(rdev, event, data); in regulator_notifier_call_chain()
5424 struct regulator_dev *rdev = dev_to_rdev(dev); in regulator_attr_is_visible() local
5425 const struct regulator_ops *ops = rdev->desc->ops; in regulator_attr_is_visible()
5436 if ((ops->get_voltage && ops->get_voltage(rdev) >= 0) || in regulator_attr_is_visible()
5437 (ops->get_voltage_sel && ops->get_voltage_sel(rdev) >= 0) || in regulator_attr_is_visible()
5438 (ops->list_voltage && ops->list_voltage(rdev, 0) >= 0) || in regulator_attr_is_visible()
5439 (rdev->desc->fixed_uV && rdev->desc->n_voltages == 1)) in regulator_attr_is_visible()
5451 return (rdev->ena_pin || ops->is_enabled) ? mode : 0; in regulator_attr_is_visible()
5496 return rdev->constraints->pw_budget_mW != INT_MAX ? mode : 0; in regulator_attr_is_visible()
5513 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_dev_release() local
5515 debugfs_remove_recursive(rdev->debugfs); in regulator_dev_release()
5516 kfree(rdev->constraints); in regulator_dev_release()
5517 of_node_put(rdev->dev.of_node); in regulator_dev_release()
5518 kfree(rdev); in regulator_dev_release()
5521 static void rdev_init_debugfs(struct regulator_dev *rdev) in rdev_init_debugfs() argument
5523 struct device *parent = rdev->dev.parent; in rdev_init_debugfs()
5524 const char *rname = rdev_get_name(rdev); in rdev_init_debugfs()
5528 if (parent && rname == rdev->desc->name) { in rdev_init_debugfs()
5534 rdev->debugfs = debugfs_create_dir(rname, debugfs_root); in rdev_init_debugfs()
5535 if (IS_ERR(rdev->debugfs)) in rdev_init_debugfs()
5536 rdev_dbg(rdev, "Failed to create debugfs directory\n"); in rdev_init_debugfs()
5538 debugfs_create_u32("use_count", 0444, rdev->debugfs, in rdev_init_debugfs()
5539 &rdev->use_count); in rdev_init_debugfs()
5540 debugfs_create_u32("open_count", 0444, rdev->debugfs, in rdev_init_debugfs()
5541 &rdev->open_count); in rdev_init_debugfs()
5542 debugfs_create_u32("bypass_count", 0444, rdev->debugfs, in rdev_init_debugfs()
5543 &rdev->bypass_count); in rdev_init_debugfs()
5548 struct regulator_dev *rdev = dev_to_rdev(dev); in regulator_register_resolve_supply() local
5550 if (regulator_resolve_supply(rdev)) in regulator_register_resolve_supply()
5551 rdev_dbg(rdev, "unable to resolve supply\n"); in regulator_register_resolve_supply()
5566 regulator_find_coupler(struct regulator_dev *rdev) in regulator_find_coupler() argument
5577 err = coupler->attach_regulator(coupler, rdev); in regulator_find_coupler()
5580 rdev->coupling_desc.n_coupled > 2) in regulator_find_coupler()
5599 coupler->detach_regulator(coupler, rdev); in regulator_find_coupler()
5601 rdev_err(rdev, in regulator_find_coupler()
5607 static void regulator_resolve_coupling(struct regulator_dev *rdev) in regulator_resolve_coupling() argument
5609 struct regulator_coupler *coupler = rdev->coupling_desc.coupler; in regulator_resolve_coupling()
5610 struct coupling_desc *c_desc = &rdev->coupling_desc; in regulator_resolve_coupling()
5620 c_rdev = of_parse_coupled_regulator(rdev, i - 1); in regulator_resolve_coupling()
5626 rdev_err(rdev, "coupler mismatch with %s\n", in regulator_resolve_coupling()
5638 static void regulator_remove_coupling(struct regulator_dev *rdev) in regulator_remove_coupling() argument
5640 struct regulator_coupler *coupler = rdev->coupling_desc.coupler; in regulator_remove_coupling()
5641 struct coupling_desc *__c_desc, *c_desc = &rdev->coupling_desc; in regulator_remove_coupling()
5663 if (__c_rdev == rdev) { in regulator_remove_coupling()
5677 err = coupler->detach_regulator(coupler, rdev); in regulator_remove_coupling()
5679 rdev_err(rdev, "failed to detach from coupler: %pe\n", in regulator_remove_coupling()
5683 rdev->coupling_desc.n_coupled = 0; in regulator_remove_coupling()
5684 kfree(rdev->coupling_desc.coupled_rdevs); in regulator_remove_coupling()
5685 rdev->coupling_desc.coupled_rdevs = NULL; in regulator_remove_coupling()
5688 static int regulator_init_coupling(struct regulator_dev *rdev) in regulator_init_coupling() argument
5696 n_phandles = of_get_n_coupled(rdev); in regulator_init_coupling()
5702 rdev->coupling_desc.coupled_rdevs = coupled; in regulator_init_coupling()
5708 rdev->coupling_desc.coupled_rdevs[0] = rdev; in regulator_init_coupling()
5709 rdev->coupling_desc.n_coupled = n_phandles + 1; in regulator_init_coupling()
5710 rdev->coupling_desc.n_resolved++; in regulator_init_coupling()
5716 if (!of_check_coupling_data(rdev)) in regulator_init_coupling()
5720 rdev->coupling_desc.coupler = regulator_find_coupler(rdev); in regulator_init_coupling()
5723 if (IS_ERR(rdev->coupling_desc.coupler)) { in regulator_init_coupling()
5724 err = PTR_ERR(rdev->coupling_desc.coupler); in regulator_init_coupling()
5725 rdev_err(rdev, "failed to get coupler: %pe\n", ERR_PTR(err)); in regulator_init_coupling()
5733 struct regulator_dev *rdev) in generic_coupler_attach() argument
5735 if (rdev->coupling_desc.n_coupled > 2) { in generic_coupler_attach()
5736 rdev_err(rdev, in generic_coupler_attach()
5741 if (!rdev->constraints->always_on) { in generic_coupler_attach()
5742 rdev_err(rdev, in generic_coupler_attach()
5773 struct regulator_dev *rdev; in regulator_register() local
5819 rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); in regulator_register()
5820 if (rdev == NULL) { in regulator_register()
5824 device_initialize(&rdev->dev); in regulator_register()
5825 dev_set_drvdata(&rdev->dev, rdev); in regulator_register()
5826 rdev->dev.class = ®ulator_class; in regulator_register()
5827 spin_lock_init(&rdev->err_lock); in regulator_register()
5844 &rdev->dev.of_node); in regulator_register()
5868 rdev->dev.of_node = of_node_get(config->of_node); in regulator_register()
5871 ww_mutex_init(&rdev->mutex, ®ulator_ww_class); in regulator_register()
5872 rdev->reg_data = config->driver_data; in regulator_register()
5873 rdev->owner = regulator_desc->owner; in regulator_register()
5874 rdev->desc = regulator_desc; in regulator_register()
5876 rdev->regmap = config->regmap; in regulator_register()
5878 rdev->regmap = dev_get_regmap(dev, NULL); in regulator_register()
5880 rdev->regmap = dev_get_regmap(dev->parent, NULL); in regulator_register()
5881 INIT_LIST_HEAD(&rdev->consumer_list); in regulator_register()
5882 INIT_LIST_HEAD(&rdev->list); in regulator_register()
5883 BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier); in regulator_register()
5884 INIT_DELAYED_WORK(&rdev->disable_work, regulator_disable_work); in regulator_register()
5887 rdev->supply_name = init_data->supply_regulator; in regulator_register()
5889 rdev->supply_name = regulator_desc->supply_name; in regulator_register()
5892 rdev->dev.parent = config->dev; in regulator_register()
5893 dev_set_name(&rdev->dev, "regulator.%lu", in regulator_register()
5898 rdev->constraints = kmemdup(&init_data->constraints, in regulator_register()
5899 sizeof(*rdev->constraints), in regulator_register()
5902 rdev->constraints = kzalloc(sizeof(*rdev->constraints), in regulator_register()
5904 if (!rdev->constraints) { in regulator_register()
5910 ret = regulator_desc->init_cb(rdev, config); in regulator_register()
5915 if ((rdev->supply_name && !rdev->supply) && in regulator_register()
5916 (rdev->constraints->always_on || in regulator_register()
5917 rdev->constraints->boot_on)) { in regulator_register()
5918 ret = regulator_resolve_supply(rdev); in regulator_register()
5920 rdev_dbg(rdev, "unable to resolve supply early: %pe\n", in regulator_register()
5927 ret = regulator_ena_gpio_request(rdev, config); in regulator_register()
5929 rdev_err(rdev, "Failed to request enable GPIO: %pe\n", in regulator_register()
5938 ret = set_machine_constraints(rdev); in regulator_register()
5947 rdev_dbg(rdev, "will resolve supply early: %s\n", in regulator_register()
5948 rdev->supply_name); in regulator_register()
5949 ret = regulator_resolve_supply(rdev); in regulator_register()
5951 ret = set_machine_constraints(rdev); in regulator_register()
5953 rdev_dbg(rdev, "unable to resolve supply early: %pe\n", in regulator_register()
5959 ret = regulator_init_coupling(rdev); in regulator_register()
5966 ret = set_consumer_device_supply(rdev, in regulator_register()
5977 if (!rdev->desc->ops->get_voltage && in regulator_register()
5978 !rdev->desc->ops->list_voltage && in regulator_register()
5979 !rdev->desc->fixed_uV) in regulator_register()
5980 rdev->is_switch = true; in regulator_register()
5982 ret = device_add(&rdev->dev); in regulator_register()
5986 rdev_init_debugfs(rdev); in regulator_register()
5990 regulator_resolve_coupling(rdev); in regulator_register()
5997 return rdev; in regulator_register()
6001 unset_regulator_supplies(rdev); in regulator_register()
6002 regulator_remove_coupling(rdev); in regulator_register()
6005 regulator_put(rdev->supply); in regulator_register()
6006 kfree(rdev->coupling_desc.coupled_rdevs); in regulator_register()
6008 regulator_ena_gpio_free(rdev); in regulator_register()
6014 put_device(&rdev->dev); in regulator_register()
6028 void regulator_unregister(struct regulator_dev *rdev) in regulator_unregister() argument
6030 if (rdev == NULL) in regulator_unregister()
6033 if (rdev->supply) { in regulator_unregister()
6034 while (rdev->use_count--) in regulator_unregister()
6035 regulator_disable(rdev->supply); in regulator_unregister()
6036 regulator_put(rdev->supply); in regulator_unregister()
6039 flush_work(&rdev->disable_work.work); in regulator_unregister()
6043 WARN_ON(rdev->open_count); in regulator_unregister()
6044 regulator_remove_coupling(rdev); in regulator_unregister()
6045 unset_regulator_supplies(rdev); in regulator_unregister()
6046 list_del(&rdev->list); in regulator_unregister()
6047 regulator_ena_gpio_free(rdev); in regulator_unregister()
6048 device_unregister(&rdev->dev); in regulator_unregister()
6065 struct regulator_dev *rdev = dev_to_rdev(dev); in regulator_suspend() local
6070 rstate = regulator_get_suspend_state_check(rdev, state); in regulator_suspend()
6074 regulator_lock(rdev); in regulator_suspend()
6075 ret = __suspend_set_state(rdev, rstate); in regulator_suspend()
6076 regulator_unlock(rdev); in regulator_suspend()
6084 struct regulator_dev *rdev = dev_to_rdev(dev); in regulator_resume() local
6088 rstate = regulator_get_suspend_state(rdev, state); in regulator_resume()
6093 if (!rdev->desc->ops->resume) in regulator_resume()
6096 regulator_lock(rdev); in regulator_resume()
6100 ret = rdev->desc->ops->resume(rdev); in regulator_resume()
6102 regulator_unlock(rdev); in regulator_resume()
6154 void *rdev_get_drvdata(struct regulator_dev *rdev) in rdev_get_drvdata() argument
6156 return rdev->reg_data; in rdev_get_drvdata()
6171 return regulator->rdev->reg_data; in regulator_get_drvdata()
6182 regulator->rdev->reg_data = data; in regulator_set_drvdata()
6192 int rdev_get_id(struct regulator_dev *rdev) in rdev_get_id() argument
6194 return rdev->desc->id; in rdev_get_id()
6198 struct device *rdev_get_dev(struct regulator_dev *rdev) in rdev_get_dev() argument
6200 return &rdev->dev; in rdev_get_dev()
6204 struct regmap *rdev_get_regmap(struct regulator_dev *rdev) in rdev_get_regmap() argument
6206 return rdev->regmap; in rdev_get_regmap()
6238 struct regulator_dev *rdev,
6243 struct regulator_dev *rdev = dev_to_rdev(dev); in regulator_summary_show_children() local
6246 if (rdev->supply && rdev->supply->rdev == summary_data->parent) in regulator_summary_show_children()
6247 regulator_summary_show_subtree(summary_data->s, rdev, in regulator_summary_show_children()
6254 struct regulator_dev *rdev, in regulator_summary_show_subtree() argument
6262 if (!rdev) in regulator_summary_show_subtree()
6265 opmode = _regulator_get_mode_unlocked(rdev); in regulator_summary_show_subtree()
6268 30 - level * 3, rdev_get_name(rdev), in regulator_summary_show_subtree()
6269 rdev->use_count, rdev->open_count, rdev->bypass_count, in regulator_summary_show_subtree()
6272 seq_printf(s, "%5dmV ", regulator_get_voltage_rdev(rdev) / 1000); in regulator_summary_show_subtree()
6274 _regulator_get_current_limit_unlocked(rdev) / 1000); in regulator_summary_show_subtree()
6276 c = rdev->constraints; in regulator_summary_show_subtree()
6278 switch (rdev->desc->type) { in regulator_summary_show_subtree()
6292 list_for_each_entry(consumer, &rdev->consumer_list, list) { in regulator_summary_show_subtree()
6302 switch (rdev->desc->type) { in regulator_summary_show_subtree()
6321 summary_data.parent = rdev; in regulator_summary_show_subtree()
6335 struct regulator_dev *rdev = dev_to_rdev(dev); in regulator_summary_lock_one() local
6339 if (rdev != *lock_data->old_contended_rdev) { in regulator_summary_lock_one()
6340 ret = regulator_lock_nested(rdev, lock_data->ww_ctx); in regulator_summary_lock_one()
6343 *lock_data->new_contended_rdev = rdev; in regulator_summary_lock_one()
6355 struct regulator_dev *rdev = dev_to_rdev(dev); in regulator_summary_unlock_one() local
6359 if (rdev == *lock_data->new_contended_rdev) in regulator_summary_unlock_one()
6363 regulator_unlock(rdev); in regulator_summary_unlock_one()
6429 struct regulator_dev *rdev = dev_to_rdev(dev); in regulator_summary_show_roots() local
6432 if (!rdev->supply) in regulator_summary_show_roots()
6433 regulator_summary_show_subtree(s, rdev, 0); in regulator_summary_show_roots()
6486 struct regulator_dev *rdev = dev_to_rdev(dev); in regulator_late_cleanup() local
6487 struct regulation_constraints *c = rdev->constraints; in regulator_late_cleanup()
6493 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_STATUS)) in regulator_late_cleanup()
6496 regulator_lock(rdev); in regulator_late_cleanup()
6498 if (rdev->use_count) in regulator_late_cleanup()
6502 if (_regulator_is_enabled(rdev) <= 0) in regulator_late_cleanup()
6509 rdev_info(rdev, "disabling\n"); in regulator_late_cleanup()
6510 ret = _regulator_do_disable(rdev); in regulator_late_cleanup()
6512 rdev_err(rdev, "couldn't disable: %pe\n", ERR_PTR(ret)); in regulator_late_cleanup()
6519 rdev_warn(rdev, "incomplete constraints, leaving on\n"); in regulator_late_cleanup()
6523 regulator_unlock(rdev); in regulator_late_cleanup()