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 *max_uA = rdev->constraints->max_uA; in regulator_check_current_limit()
502 if (*min_uA < rdev->constraints->min_uA) in regulator_check_current_limit()
503 *min_uA = rdev->constraints->min_uA; in regulator_check_current_limit()
506 rdev_err(rdev, "unsupportable current range: %d-%duA\n", in regulator_check_current_limit()
515 static int regulator_mode_constrain(struct regulator_dev *rdev, in regulator_mode_constrain() argument
525 rdev_err(rdev, "invalid mode %x specified\n", *mode); in regulator_mode_constrain()
529 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_MODE)) { in regulator_mode_constrain()
530 rdev_err(rdev, "mode operation not allowed\n"); in regulator_mode_constrain()
539 if (rdev->constraints->valid_modes_mask & *mode) in regulator_mode_constrain()
548 regulator_get_suspend_state(struct regulator_dev *rdev, suspend_state_t state) in regulator_get_suspend_state() argument
550 if (rdev->constraints == NULL) in regulator_get_suspend_state()
555 return &rdev->constraints->state_standby; in regulator_get_suspend_state()
557 return &rdev->constraints->state_mem; in regulator_get_suspend_state()
559 return &rdev->constraints->state_disk; in regulator_get_suspend_state()
566 regulator_get_suspend_state_check(struct regulator_dev *rdev, suspend_state_t state) in regulator_get_suspend_state_check() argument
570 rstate = regulator_get_suspend_state(rdev, state); in regulator_get_suspend_state_check()
580 if (rdev->desc->ops->set_suspend_voltage || in regulator_get_suspend_state_check()
581 rdev->desc->ops->set_suspend_mode) in regulator_get_suspend_state_check()
582 rdev_warn(rdev, "No configuration\n"); in regulator_get_suspend_state_check()
592 struct regulator_dev *rdev = dev_get_drvdata(dev); in microvolts_show() local
595 regulator_lock(rdev); in microvolts_show()
596 uV = regulator_get_voltage_rdev(rdev); in microvolts_show()
597 regulator_unlock(rdev); in microvolts_show()
608 struct regulator_dev *rdev = dev_get_drvdata(dev); in microamps_show() local
610 return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev)); in microamps_show()
617 struct regulator_dev *rdev = dev_get_drvdata(dev); in name_show() local
619 return sprintf(buf, "%s\n", rdev_get_name(rdev)); in name_show()
646 struct regulator_dev *rdev = dev_get_drvdata(dev); in opmode_show() local
648 return regulator_print_opmode(buf, _regulator_get_mode(rdev)); in opmode_show()
665 struct regulator_dev *rdev = dev_get_drvdata(dev); in state_show() local
668 regulator_lock(rdev); in state_show()
669 ret = regulator_print_state(buf, _regulator_is_enabled(rdev)); in state_show()
670 regulator_unlock(rdev); in state_show()
679 struct regulator_dev *rdev = dev_get_drvdata(dev); in status_show() local
683 status = rdev->desc->ops->get_status(rdev); in status_show()
726 struct regulator_dev *rdev = dev_get_drvdata(dev); in min_microamps_show() local
728 if (!rdev->constraints) in min_microamps_show()
731 return sprintf(buf, "%d\n", rdev->constraints->min_uA); in min_microamps_show()
738 struct regulator_dev *rdev = dev_get_drvdata(dev); in max_microamps_show() local
740 if (!rdev->constraints) in max_microamps_show()
743 return sprintf(buf, "%d\n", rdev->constraints->max_uA); in max_microamps_show()
750 struct regulator_dev *rdev = dev_get_drvdata(dev); in min_microvolts_show() local
752 if (!rdev->constraints) in min_microvolts_show()
755 return sprintf(buf, "%d\n", rdev->constraints->min_uV); in min_microvolts_show()
762 struct regulator_dev *rdev = dev_get_drvdata(dev); in max_microvolts_show() local
764 if (!rdev->constraints) in max_microvolts_show()
767 return sprintf(buf, "%d\n", rdev->constraints->max_uV); in max_microvolts_show()
774 struct regulator_dev *rdev = dev_get_drvdata(dev); in requested_microamps_show() local
778 regulator_lock(rdev); in requested_microamps_show()
779 list_for_each_entry(regulator, &rdev->consumer_list, list) { in requested_microamps_show()
783 regulator_unlock(rdev); in requested_microamps_show()
791 struct regulator_dev *rdev = dev_get_drvdata(dev); in num_users_show() local
792 return sprintf(buf, "%d\n", rdev->use_count); in num_users_show()
799 struct regulator_dev *rdev = dev_get_drvdata(dev); in type_show() local
801 switch (rdev->desc->type) { in type_show()
814 struct regulator_dev *rdev = dev_get_drvdata(dev); in suspend_mem_microvolts_show() local
816 return sprintf(buf, "%d\n", rdev->constraints->state_mem.uV); in suspend_mem_microvolts_show()
823 struct regulator_dev *rdev = dev_get_drvdata(dev); in suspend_disk_microvolts_show() local
825 return sprintf(buf, "%d\n", rdev->constraints->state_disk.uV); in suspend_disk_microvolts_show()
832 struct regulator_dev *rdev = dev_get_drvdata(dev); in suspend_standby_microvolts_show() local
834 return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV); in suspend_standby_microvolts_show()
841 struct regulator_dev *rdev = dev_get_drvdata(dev); in suspend_mem_mode_show() local
844 rdev->constraints->state_mem.mode); in suspend_mem_mode_show()
851 struct regulator_dev *rdev = dev_get_drvdata(dev); in suspend_disk_mode_show() local
854 rdev->constraints->state_disk.mode); in suspend_disk_mode_show()
861 struct regulator_dev *rdev = dev_get_drvdata(dev); in suspend_standby_mode_show() local
864 rdev->constraints->state_standby.mode); in suspend_standby_mode_show()
871 struct regulator_dev *rdev = dev_get_drvdata(dev); in suspend_mem_state_show() local
874 rdev->constraints->state_mem.enabled); in suspend_mem_state_show()
881 struct regulator_dev *rdev = dev_get_drvdata(dev); in suspend_disk_state_show() local
884 rdev->constraints->state_disk.enabled); in suspend_disk_state_show()
891 struct regulator_dev *rdev = dev_get_drvdata(dev); in suspend_standby_state_show() local
894 rdev->constraints->state_standby.enabled); in suspend_standby_state_show()
901 struct regulator_dev *rdev = dev_get_drvdata(dev); in bypass_show() local
906 ret = rdev->desc->ops->get_bypass(rdev, &bypass); in bypass_show()
925 struct regulator_dev *rdev = dev_get_drvdata(dev); \
926 ret = _regulator_get_error_flags(rdev, &flags); \
946 static int drms_uA_update(struct regulator_dev *rdev) in drms_uA_update() argument
956 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_DRMS)) { in drms_uA_update()
957 rdev_dbg(rdev, "DRMS operation not allowed\n"); in drms_uA_update()
961 if (!rdev->desc->ops->get_optimum_mode && in drms_uA_update()
962 !rdev->desc->ops->set_load) in drms_uA_update()
965 if (!rdev->desc->ops->set_mode && in drms_uA_update()
966 !rdev->desc->ops->set_load) in drms_uA_update()
970 list_for_each_entry(sibling, &rdev->consumer_list, list) { in drms_uA_update()
975 current_uA += rdev->constraints->system_load; in drms_uA_update()
977 if (rdev->desc->ops->set_load) { in drms_uA_update()
979 err = rdev->desc->ops->set_load(rdev, current_uA); in drms_uA_update()
981 rdev_err(rdev, "failed to set load %d: %pe\n", in drms_uA_update()
991 if (!rdev->constraints->valid_modes_mask) { in drms_uA_update()
992 rdev_dbg(rdev, "Can change modes; but no valid mode\n"); in drms_uA_update()
997 output_uV = regulator_get_voltage_rdev(rdev); in drms_uA_update()
1004 rdev_dbg(rdev, "invalid output voltage found\n"); in drms_uA_update()
1008 if (rdev->supply) in drms_uA_update()
1009 input_uV = regulator_get_voltage_rdev(rdev->supply->rdev); in drms_uA_update()
1011 input_uV = rdev->constraints->input_uV; in drms_uA_update()
1018 rdev_dbg(rdev, "invalid input voltage found\n"); in drms_uA_update()
1021 mode = rdev->desc->ops->get_optimum_mode(rdev, input_uV, in drms_uA_update()
1025 err = regulator_mode_constrain(rdev, &mode); in drms_uA_update()
1027 rdev_err(rdev, "failed to get optimum mode @ %d uA %d -> %d uV: %pe\n", in drms_uA_update()
1032 err = rdev->desc->ops->set_mode(rdev, mode); in drms_uA_update()
1034 rdev_err(rdev, "failed to set optimum mode %x: %pe\n", in drms_uA_update()
1041 static int __suspend_set_state(struct regulator_dev *rdev, in __suspend_set_state() argument
1047 rdev->desc->ops->set_suspend_enable) in __suspend_set_state()
1048 ret = rdev->desc->ops->set_suspend_enable(rdev); in __suspend_set_state()
1050 rdev->desc->ops->set_suspend_disable) in __suspend_set_state()
1051 ret = rdev->desc->ops->set_suspend_disable(rdev); in __suspend_set_state()
1056 rdev_err(rdev, "failed to enabled/disable: %pe\n", ERR_PTR(ret)); in __suspend_set_state()
1060 if (rdev->desc->ops->set_suspend_voltage && rstate->uV > 0) { in __suspend_set_state()
1061 ret = rdev->desc->ops->set_suspend_voltage(rdev, rstate->uV); in __suspend_set_state()
1063 rdev_err(rdev, "failed to set voltage: %pe\n", ERR_PTR(ret)); in __suspend_set_state()
1068 if (rdev->desc->ops->set_suspend_mode && rstate->mode > 0) { in __suspend_set_state()
1069 ret = rdev->desc->ops->set_suspend_mode(rdev, rstate->mode); in __suspend_set_state()
1071 rdev_err(rdev, "failed to set mode: %pe\n", ERR_PTR(ret)); in __suspend_set_state()
1079 static int suspend_set_initial_state(struct regulator_dev *rdev) in suspend_set_initial_state() argument
1083 rstate = regulator_get_suspend_state_check(rdev, in suspend_set_initial_state()
1084 rdev->constraints->initial_state); in suspend_set_initial_state()
1088 return __suspend_set_state(rdev, rstate); in suspend_set_initial_state()
1092 static void print_constraints_debug(struct regulator_dev *rdev) in print_constraints_debug() argument
1094 struct regulation_constraints *constraints = rdev->constraints; in print_constraints_debug()
1113 ret = regulator_get_voltage_rdev(rdev); in print_constraints_debug()
1136 ret = _regulator_get_current_limit(rdev); in print_constraints_debug()
1157 _regulator_is_enabled(rdev) ? "enabled" : "disabled"); in print_constraints_debug()
1159 rdev_dbg(rdev, "%s\n", buf); in print_constraints_debug()
1162 static inline void print_constraints_debug(struct regulator_dev *rdev) {} in print_constraints_debug() argument
1165 static void print_constraints(struct regulator_dev *rdev) in print_constraints() argument
1167 struct regulation_constraints *constraints = rdev->constraints; in print_constraints()
1169 print_constraints_debug(rdev); in print_constraints()
1172 !regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) in print_constraints()
1173 rdev_warn(rdev, in print_constraints()
1177 static int machine_constraints_voltage(struct regulator_dev *rdev, in machine_constraints_voltage() argument
1180 const struct regulator_ops *ops = rdev->desc->ops; in machine_constraints_voltage()
1184 if (rdev->constraints->apply_uV && in machine_constraints_voltage()
1185 rdev->constraints->min_uV && rdev->constraints->max_uV) { in machine_constraints_voltage()
1187 int current_uV = regulator_get_voltage_rdev(rdev); in machine_constraints_voltage()
1191 rdev_info(rdev, "Setting %d-%duV\n", in machine_constraints_voltage()
1192 rdev->constraints->min_uV, in machine_constraints_voltage()
1193 rdev->constraints->max_uV); in machine_constraints_voltage()
1194 _regulator_do_set_voltage(rdev, in machine_constraints_voltage()
1195 rdev->constraints->min_uV, in machine_constraints_voltage()
1196 rdev->constraints->max_uV); in machine_constraints_voltage()
1197 current_uV = regulator_get_voltage_rdev(rdev); in machine_constraints_voltage()
1202 rdev_err(rdev, in machine_constraints_voltage()
1216 if (current_uV < rdev->constraints->min_uV) { in machine_constraints_voltage()
1217 target_min = rdev->constraints->min_uV; in machine_constraints_voltage()
1218 target_max = rdev->constraints->min_uV; in machine_constraints_voltage()
1221 if (current_uV > rdev->constraints->max_uV) { in machine_constraints_voltage()
1222 target_min = rdev->constraints->max_uV; in machine_constraints_voltage()
1223 target_max = rdev->constraints->max_uV; in machine_constraints_voltage()
1227 rdev_info(rdev, "Bringing %duV into %d-%duV\n", in machine_constraints_voltage()
1230 rdev, target_min, target_max); in machine_constraints_voltage()
1232 rdev_err(rdev, in machine_constraints_voltage()
1243 if (ops->list_voltage && rdev->desc->n_voltages) { in machine_constraints_voltage()
1244 int count = rdev->desc->n_voltages; in machine_constraints_voltage()
1267 rdev_err(rdev, "invalid voltage constraints\n"); in machine_constraints_voltage()
1272 if (rdev->desc->continuous_voltage_range) in machine_constraints_voltage()
1279 value = ops->list_voltage(rdev, i); in machine_constraints_voltage()
1292 rdev_err(rdev, in machine_constraints_voltage()
1300 rdev_dbg(rdev, "override min_uV, %d -> %d\n", in machine_constraints_voltage()
1305 rdev_dbg(rdev, "override max_uV, %d -> %d\n", in machine_constraints_voltage()
1314 static int machine_constraints_current(struct regulator_dev *rdev, in machine_constraints_current() argument
1317 const struct regulator_ops *ops = rdev->desc->ops; in machine_constraints_current()
1324 rdev_err(rdev, "Invalid current constraints\n"); in machine_constraints_current()
1329 rdev_warn(rdev, "Operation of current configuration missing\n"); in machine_constraints_current()
1334 ret = ops->set_current_limit(rdev, constraints->min_uA, in machine_constraints_current()
1337 rdev_err(rdev, "Failed to set current constraint, %d\n", ret); in machine_constraints_current()
1344 static int _regulator_do_enable(struct regulator_dev *rdev);
1346 static int notif_set_limit(struct regulator_dev *rdev, in notif_set_limit() argument
1362 return set(rdev, limit, severity, enable); in notif_set_limit()
1365 static int handle_notify_limits(struct regulator_dev *rdev, in handle_notify_limits() argument
1375 ret = notif_set_limit(rdev, set, limits->prot, in handle_notify_limits()
1381 ret = notif_set_limit(rdev, set, limits->err, in handle_notify_limits()
1387 ret = notif_set_limit(rdev, set, limits->warn, in handle_notify_limits()
1404 static int set_machine_constraints(struct regulator_dev *rdev) in set_machine_constraints() argument
1407 const struct regulator_ops *ops = rdev->desc->ops; in set_machine_constraints()
1409 ret = machine_constraints_voltage(rdev, rdev->constraints); in set_machine_constraints()
1413 ret = machine_constraints_current(rdev, rdev->constraints); in set_machine_constraints()
1417 if (rdev->constraints->ilim_uA && ops->set_input_current_limit) { in set_machine_constraints()
1418 ret = ops->set_input_current_limit(rdev, in set_machine_constraints()
1419 rdev->constraints->ilim_uA); in set_machine_constraints()
1421 rdev_err(rdev, "failed to set input limit: %pe\n", ERR_PTR(ret)); in set_machine_constraints()
1427 if (rdev->constraints->initial_state) { in set_machine_constraints()
1428 ret = suspend_set_initial_state(rdev); in set_machine_constraints()
1430 rdev_err(rdev, "failed to set suspend state: %pe\n", ERR_PTR(ret)); in set_machine_constraints()
1435 if (rdev->constraints->initial_mode) { in set_machine_constraints()
1437 rdev_err(rdev, "no set_mode operation\n"); in set_machine_constraints()
1441 ret = ops->set_mode(rdev, rdev->constraints->initial_mode); in set_machine_constraints()
1443 rdev_err(rdev, "failed to set initial mode: %pe\n", ERR_PTR(ret)); in set_machine_constraints()
1446 } else if (rdev->constraints->system_load) { in set_machine_constraints()
1451 drms_uA_update(rdev); in set_machine_constraints()
1454 if ((rdev->constraints->ramp_delay || rdev->constraints->ramp_disable) in set_machine_constraints()
1456 ret = ops->set_ramp_delay(rdev, rdev->constraints->ramp_delay); in set_machine_constraints()
1458 rdev_err(rdev, "failed to set ramp_delay: %pe\n", ERR_PTR(ret)); in set_machine_constraints()
1463 if (rdev->constraints->pull_down && ops->set_pull_down) { in set_machine_constraints()
1464 ret = ops->set_pull_down(rdev); in set_machine_constraints()
1466 rdev_err(rdev, "failed to set pull down: %pe\n", ERR_PTR(ret)); in set_machine_constraints()
1471 if (rdev->constraints->soft_start && ops->set_soft_start) { in set_machine_constraints()
1472 ret = ops->set_soft_start(rdev); in set_machine_constraints()
1474 rdev_err(rdev, "failed to set soft start: %pe\n", ERR_PTR(ret)); in set_machine_constraints()
1493 if (rdev->constraints->over_current_protection in set_machine_constraints()
1495 int lim = rdev->constraints->over_curr_limits.prot; in set_machine_constraints()
1497 ret = ops->set_over_current_protection(rdev, lim, in set_machine_constraints()
1501 rdev_err(rdev, "failed to set over current protection: %pe\n", in set_machine_constraints()
1507 if (rdev->constraints->over_current_detection) in set_machine_constraints()
1508 ret = handle_notify_limits(rdev, in set_machine_constraints()
1510 &rdev->constraints->over_curr_limits); in set_machine_constraints()
1513 rdev_err(rdev, "failed to set over current limits: %pe\n", in set_machine_constraints()
1517 rdev_warn(rdev, in set_machine_constraints()
1521 if (rdev->constraints->over_voltage_detection) in set_machine_constraints()
1522 ret = handle_notify_limits(rdev, in set_machine_constraints()
1524 &rdev->constraints->over_voltage_limits); in set_machine_constraints()
1527 rdev_err(rdev, "failed to set over voltage limits %pe\n", in set_machine_constraints()
1531 rdev_warn(rdev, in set_machine_constraints()
1535 if (rdev->constraints->under_voltage_detection) in set_machine_constraints()
1536 ret = handle_notify_limits(rdev, in set_machine_constraints()
1538 &rdev->constraints->under_voltage_limits); in set_machine_constraints()
1541 rdev_err(rdev, "failed to set under voltage limits %pe\n", in set_machine_constraints()
1545 rdev_warn(rdev, in set_machine_constraints()
1549 if (rdev->constraints->over_temp_detection) in set_machine_constraints()
1550 ret = handle_notify_limits(rdev, in set_machine_constraints()
1552 &rdev->constraints->temp_limits); in set_machine_constraints()
1555 rdev_err(rdev, "failed to set temperature limits %pe\n", in set_machine_constraints()
1559 rdev_warn(rdev, in set_machine_constraints()
1563 if (rdev->constraints->active_discharge && ops->set_active_discharge) { in set_machine_constraints()
1564 bool ad_state = (rdev->constraints->active_discharge == in set_machine_constraints()
1567 ret = ops->set_active_discharge(rdev, ad_state); in set_machine_constraints()
1569 rdev_err(rdev, "failed to set active discharge: %pe\n", ERR_PTR(ret)); in set_machine_constraints()
1581 if (!rdev->ena_pin && !ops->enable) { in set_machine_constraints()
1582 if (rdev->supply_name && !rdev->supply) in set_machine_constraints()
1585 if (rdev->supply) in set_machine_constraints()
1586 rdev->constraints->always_on = in set_machine_constraints()
1587 rdev->supply->rdev->constraints->always_on; in set_machine_constraints()
1589 rdev->constraints->always_on = true; in set_machine_constraints()
1595 if (rdev->constraints->always_on || rdev->constraints->boot_on) { in set_machine_constraints()
1599 if (rdev->supply_name && !rdev->supply) in set_machine_constraints()
1606 if (rdev->supply && in set_machine_constraints()
1607 (rdev->constraints->always_on || in set_machine_constraints()
1608 !regulator_is_enabled(rdev->supply))) { in set_machine_constraints()
1609 ret = regulator_enable(rdev->supply); in set_machine_constraints()
1611 _regulator_put(rdev->supply); in set_machine_constraints()
1612 rdev->supply = NULL; in set_machine_constraints()
1617 ret = _regulator_do_enable(rdev); in set_machine_constraints()
1619 rdev_err(rdev, "failed to enable: %pe\n", ERR_PTR(ret)); in set_machine_constraints()
1623 if (rdev->constraints->always_on) in set_machine_constraints()
1624 rdev->use_count++; in set_machine_constraints()
1625 } else if (rdev->desc->off_on_delay) { in set_machine_constraints()
1626 rdev->last_off = ktime_get(); in set_machine_constraints()
1629 print_constraints(rdev); in set_machine_constraints()
1644 static int set_supply(struct regulator_dev *rdev, in set_supply() argument
1649 rdev_dbg(rdev, "supplied by %s\n", rdev_get_name(supply_rdev)); in set_supply()
1654 rdev->supply = create_regulator(supply_rdev, &rdev->dev, "SUPPLY"); in set_supply()
1655 if (rdev->supply == NULL) { in set_supply()
1678 static int set_consumer_device_supply(struct regulator_dev *rdev, in set_consumer_device_supply() argument
1697 new_node->regulator = rdev; in set_consumer_device_supply()
1725 dev_name(&rdev->dev), rdev_get_name(rdev)); in set_consumer_device_supply()
1741 static void unset_regulator_supplies(struct regulator_dev *rdev) in unset_regulator_supplies() argument
1746 if (rdev == node->regulator) { in unset_regulator_supplies()
1760 const struct regulation_constraints *c = regulator->rdev->constraints; in constraint_flags_read_file()
1805 static struct regulator *create_regulator(struct regulator_dev *rdev, in create_regulator() argument
1812 lockdep_assert_held_once(&rdev->mutex.base); in create_regulator()
1838 regulator->rdev = rdev; in create_regulator()
1841 list_add(®ulator->list, &rdev->consumer_list); in create_regulator()
1847 err = sysfs_create_link_nowarn(&rdev->dev.kobj, &dev->kobj, in create_regulator()
1850 rdev_dbg(rdev, "could not add device link %s: %pe\n", in create_regulator()
1857 regulator->debugfs = debugfs_create_dir(supply_name, rdev->debugfs); in create_regulator()
1859 rdev_dbg(rdev, "Failed to create debugfs directory\n"); in create_regulator()
1880 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_STATUS) && in create_regulator()
1881 _regulator_is_enabled(rdev)) in create_regulator()
1887 static int _regulator_get_enable_time(struct regulator_dev *rdev) in _regulator_get_enable_time() argument
1889 if (rdev->constraints && rdev->constraints->enable_time) in _regulator_get_enable_time()
1890 return rdev->constraints->enable_time; in _regulator_get_enable_time()
1891 if (rdev->desc->ops->enable_time) in _regulator_get_enable_time()
1892 return rdev->desc->ops->enable_time(rdev); in _regulator_get_enable_time()
1893 return rdev->desc->enable_time; in _regulator_get_enable_time()
2002 static int regulator_resolve_supply(struct regulator_dev *rdev) in regulator_resolve_supply() argument
2005 struct device *dev = rdev->dev.parent; in regulator_resolve_supply()
2010 if (!rdev->supply_name) in regulator_resolve_supply()
2014 if (rdev->supply) in regulator_resolve_supply()
2017 r = regulator_dev_lookup(dev, rdev->supply_name); in regulator_resolve_supply()
2030 rdev->supply_name, rdev->desc->name); in regulator_resolve_supply()
2036 if (r == rdev) { in regulator_resolve_supply()
2038 rdev->desc->name, rdev->supply_name); in regulator_resolve_supply()
2053 if (r->dev.parent && r->dev.parent != rdev->dev.parent) { in regulator_resolve_supply()
2073 regulator_lock_two(rdev, r, &ww_ctx); in regulator_resolve_supply()
2076 if (rdev->supply) { in regulator_resolve_supply()
2077 regulator_unlock_two(rdev, r, &ww_ctx); in regulator_resolve_supply()
2082 ret = set_supply(rdev, r); in regulator_resolve_supply()
2084 regulator_unlock_two(rdev, r, &ww_ctx); in regulator_resolve_supply()
2089 regulator_unlock_two(rdev, r, &ww_ctx); in regulator_resolve_supply()
2096 if (rdev->use_count) { in regulator_resolve_supply()
2097 ret = regulator_enable(rdev->supply); in regulator_resolve_supply()
2099 _regulator_put(rdev->supply); in regulator_resolve_supply()
2100 rdev->supply = NULL; in regulator_resolve_supply()
2139 struct regulator *_regulator_get_common(struct regulator_dev *rdev, struct device *dev, in _regulator_get_common() argument
2146 if (IS_ERR(rdev)) { in _regulator_get_common()
2147 ret = PTR_ERR(rdev); in _regulator_get_common()
2170 rdev = dummy_regulator_rdev; in _regulator_get_common()
2171 get_device(&rdev->dev); in _regulator_get_common()
2184 if (rdev->exclusive) { in _regulator_get_common()
2186 put_device(&rdev->dev); in _regulator_get_common()
2190 if (get_type == EXCLUSIVE_GET && rdev->open_count) { in _regulator_get_common()
2192 put_device(&rdev->dev); in _regulator_get_common()
2197 ret = (rdev->coupling_desc.n_resolved != rdev->coupling_desc.n_coupled); in _regulator_get_common()
2202 put_device(&rdev->dev); in _regulator_get_common()
2206 ret = regulator_resolve_supply(rdev); in _regulator_get_common()
2209 put_device(&rdev->dev); in _regulator_get_common()
2213 if (!try_module_get(rdev->owner)) { in _regulator_get_common()
2215 put_device(&rdev->dev); in _regulator_get_common()
2219 regulator_lock(rdev); in _regulator_get_common()
2220 regulator = create_regulator(rdev, dev, id); in _regulator_get_common()
2221 regulator_unlock(rdev); in _regulator_get_common()
2224 module_put(rdev->owner); in _regulator_get_common()
2225 put_device(&rdev->dev); in _regulator_get_common()
2229 rdev->open_count++; in _regulator_get_common()
2231 rdev->exclusive = 1; in _regulator_get_common()
2233 ret = _regulator_is_enabled(rdev); in _regulator_get_common()
2235 rdev->use_count = 1; in _regulator_get_common()
2239 if (rdev->supply) { in _regulator_get_common()
2240 ret = regulator_enable(rdev->supply); in _regulator_get_common()
2243 module_put(rdev->owner); in _regulator_get_common()
2244 put_device(&rdev->dev); in _regulator_get_common()
2249 rdev->use_count = 0; in _regulator_get_common()
2254 link = device_link_add(dev, &rdev->dev, DL_FLAG_STATELESS); in _regulator_get_common()
2265 struct regulator_dev *rdev; in _regulator_get() local
2272 rdev = regulator_dev_lookup(dev, id); in _regulator_get()
2273 return _regulator_get_common(rdev, dev, id, get_type); in _regulator_get()
2351 struct regulator_dev *rdev = regulator->rdev; in destroy_regulator() local
2357 device_link_remove(regulator->dev, &rdev->dev); in destroy_regulator()
2360 sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name); in destroy_regulator()
2363 regulator_lock(rdev); in destroy_regulator()
2366 rdev->open_count--; in destroy_regulator()
2367 rdev->exclusive = 0; in destroy_regulator()
2368 regulator_unlock(rdev); in destroy_regulator()
2377 struct regulator_dev *rdev; in _regulator_put() local
2387 rdev = regulator->rdev; in _regulator_put()
2391 module_put(rdev->owner); in _regulator_put()
2392 put_device(&rdev->dev); in _regulator_put()
2543 static int regulator_ena_gpio_request(struct regulator_dev *rdev, in regulator_ena_gpio_request() argument
2556 rdev_dbg(rdev, "GPIO is already used\n"); in regulator_ena_gpio_request()
2574 rdev->ena_pin = pin; in regulator_ena_gpio_request()
2582 static void regulator_ena_gpio_free(struct regulator_dev *rdev) in regulator_ena_gpio_free() argument
2586 if (!rdev->ena_pin) in regulator_ena_gpio_free()
2591 if (pin != rdev->ena_pin) in regulator_ena_gpio_free()
2603 rdev->ena_pin = NULL; in regulator_ena_gpio_free()
2616 static int regulator_ena_gpio_ctrl(struct regulator_dev *rdev, bool enable) in regulator_ena_gpio_ctrl() argument
2618 struct regulator_enable_gpio *pin = rdev->ena_pin; in regulator_ena_gpio_ctrl()
2694 static inline int _regulator_check_status_enabled(struct regulator_dev *rdev) in _regulator_check_status_enabled() argument
2696 int ret = rdev->desc->ops->get_status(rdev); in _regulator_check_status_enabled()
2699 rdev_info(rdev, "get_status returned error: %d\n", ret); in _regulator_check_status_enabled()
2713 static int _regulator_do_enable(struct regulator_dev *rdev) in _regulator_do_enable() argument
2718 ret = _regulator_get_enable_time(rdev); in _regulator_do_enable()
2722 rdev_warn(rdev, "enable_time() failed: %pe\n", ERR_PTR(ret)); in _regulator_do_enable()
2726 trace_regulator_enable(rdev_get_name(rdev)); in _regulator_do_enable()
2728 if (rdev->desc->off_on_delay) { in _regulator_do_enable()
2732 ktime_t end = ktime_add_us(rdev->last_off, rdev->desc->off_on_delay); in _regulator_do_enable()
2739 if (rdev->ena_pin) { in _regulator_do_enable()
2740 if (!rdev->ena_gpio_state) { in _regulator_do_enable()
2741 ret = regulator_ena_gpio_ctrl(rdev, true); in _regulator_do_enable()
2744 rdev->ena_gpio_state = 1; in _regulator_do_enable()
2746 } else if (rdev->desc->ops->enable) { in _regulator_do_enable()
2747 ret = rdev->desc->ops->enable(rdev); in _regulator_do_enable()
2758 trace_regulator_enable_delay(rdev_get_name(rdev)); in _regulator_do_enable()
2766 if (rdev->desc->poll_enabled_time) { in _regulator_do_enable()
2770 _regulator_delay_helper(rdev->desc->poll_enabled_time); in _regulator_do_enable()
2772 if (rdev->desc->ops->get_status) { in _regulator_do_enable()
2773 ret = _regulator_check_status_enabled(rdev); in _regulator_do_enable()
2778 } else if (rdev->desc->ops->is_enabled(rdev)) in _regulator_do_enable()
2781 time_remaining -= rdev->desc->poll_enabled_time; in _regulator_do_enable()
2785 rdev_err(rdev, "Enabled check timed out\n"); in _regulator_do_enable()
2792 trace_regulator_enable_complete(rdev_get_name(rdev)); in _regulator_do_enable()
2820 struct regulator_dev *rdev = regulator->rdev; in _regulator_handle_consumer_enable() local
2822 lockdep_assert_held_once(&rdev->mutex.base); in _regulator_handle_consumer_enable()
2826 ret = drms_uA_update(rdev); in _regulator_handle_consumer_enable()
2845 struct regulator_dev *rdev = regulator->rdev; in _regulator_handle_consumer_disable() local
2847 lockdep_assert_held_once(&rdev->mutex.base); in _regulator_handle_consumer_disable()
2850 rdev_err(rdev, "Underflow of regulator enable count\n"); in _regulator_handle_consumer_disable()
2856 return drms_uA_update(rdev); in _regulator_handle_consumer_disable()
2864 struct regulator_dev *rdev = regulator->rdev; in _regulator_enable() local
2867 lockdep_assert_held_once(&rdev->mutex.base); in _regulator_enable()
2869 if (rdev->use_count == 0 && rdev->supply) { in _regulator_enable()
2870 ret = _regulator_enable(rdev->supply); in _regulator_enable()
2876 if (rdev->coupling_desc.n_coupled > 1) { in _regulator_enable()
2877 ret = regulator_balance_voltage(rdev, PM_SUSPEND_ON); in _regulator_enable()
2886 if (rdev->use_count == 0) { in _regulator_enable()
2891 ret = _regulator_is_enabled(rdev); in _regulator_enable()
2893 if (!regulator_ops_is_valid(rdev, in _regulator_enable()
2899 ret = _regulator_do_enable(rdev); in _regulator_enable()
2903 _notifier_call_chain(rdev, REGULATOR_EVENT_ENABLE, in _regulator_enable()
2906 rdev_err(rdev, "is_enabled() failed: %pe\n", ERR_PTR(ret)); in _regulator_enable()
2913 rdev->use_count++; in _regulator_enable()
2921 if (rdev->use_count == 0 && rdev->supply) in _regulator_enable()
2922 _regulator_disable(rdev->supply); in _regulator_enable()
2942 struct regulator_dev *rdev = regulator->rdev; in regulator_enable() local
2946 regulator_lock_dependent(rdev, &ww_ctx); in regulator_enable()
2948 regulator_unlock_dependent(rdev, &ww_ctx); in regulator_enable()
2954 static int _regulator_do_disable(struct regulator_dev *rdev) in _regulator_do_disable() argument
2958 trace_regulator_disable(rdev_get_name(rdev)); in _regulator_do_disable()
2960 if (rdev->ena_pin) { in _regulator_do_disable()
2961 if (rdev->ena_gpio_state) { in _regulator_do_disable()
2962 ret = regulator_ena_gpio_ctrl(rdev, false); in _regulator_do_disable()
2965 rdev->ena_gpio_state = 0; in _regulator_do_disable()
2968 } else if (rdev->desc->ops->disable) { in _regulator_do_disable()
2969 ret = rdev->desc->ops->disable(rdev); in _regulator_do_disable()
2974 if (rdev->desc->off_on_delay) in _regulator_do_disable()
2975 rdev->last_off = ktime_get_boottime(); in _regulator_do_disable()
2977 trace_regulator_disable_complete(rdev_get_name(rdev)); in _regulator_do_disable()
2985 struct regulator_dev *rdev = regulator->rdev; in _regulator_disable() local
2988 lockdep_assert_held_once(&rdev->mutex.base); in _regulator_disable()
2991 "unbalanced disables for %s\n", rdev_get_name(rdev))) in _regulator_disable()
2997 if (rdev->use_count == 1 && in _regulator_disable()
2998 (rdev->constraints && !rdev->constraints->always_on)) { in _regulator_disable()
3001 if (regulator_ops_is_valid(rdev, REGULATOR_CHANGE_STATUS)) { in _regulator_disable()
3002 ret = _notifier_call_chain(rdev, in _regulator_disable()
3008 ret = _regulator_do_disable(rdev); in _regulator_disable()
3010 rdev_err(rdev, "failed to disable: %pe\n", ERR_PTR(ret)); in _regulator_disable()
3011 _notifier_call_chain(rdev, in _regulator_disable()
3016 _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE, in _regulator_disable()
3020 rdev->use_count = 0; in _regulator_disable()
3021 } else if (rdev->use_count > 1) { in _regulator_disable()
3022 rdev->use_count--; in _regulator_disable()
3029 if (ret == 0 && rdev->coupling_desc.n_coupled > 1) in _regulator_disable()
3030 ret = regulator_balance_voltage(rdev, PM_SUSPEND_ON); in _regulator_disable()
3032 if (ret == 0 && rdev->use_count == 0 && rdev->supply) in _regulator_disable()
3033 ret = _regulator_disable(rdev->supply); in _regulator_disable()
3054 struct regulator_dev *rdev = regulator->rdev; in regulator_disable() local
3058 regulator_lock_dependent(rdev, &ww_ctx); in regulator_disable()
3060 regulator_unlock_dependent(rdev, &ww_ctx); in regulator_disable()
3067 static int _regulator_force_disable(struct regulator_dev *rdev) in _regulator_force_disable() argument
3071 lockdep_assert_held_once(&rdev->mutex.base); in _regulator_force_disable()
3073 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE | in _regulator_force_disable()
3078 ret = _regulator_do_disable(rdev); in _regulator_force_disable()
3080 rdev_err(rdev, "failed to force disable: %pe\n", ERR_PTR(ret)); in _regulator_force_disable()
3081 _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE | in _regulator_force_disable()
3086 _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE | in _regulator_force_disable()
3105 struct regulator_dev *rdev = regulator->rdev; in regulator_force_disable() local
3109 regulator_lock_dependent(rdev, &ww_ctx); in regulator_force_disable()
3111 ret = _regulator_force_disable(regulator->rdev); in regulator_force_disable()
3113 if (rdev->coupling_desc.n_coupled > 1) in regulator_force_disable()
3114 regulator_balance_voltage(rdev, PM_SUSPEND_ON); in regulator_force_disable()
3118 ret = drms_uA_update(rdev); in regulator_force_disable()
3121 if (rdev->use_count != 0 && rdev->supply) in regulator_force_disable()
3122 _regulator_disable(rdev->supply); in regulator_force_disable()
3124 regulator_unlock_dependent(rdev, &ww_ctx); in regulator_force_disable()
3132 struct regulator_dev *rdev = container_of(work, struct regulator_dev, in regulator_disable_work() local
3139 regulator_lock_dependent(rdev, &ww_ctx); in regulator_disable_work()
3147 cancel_delayed_work(&rdev->disable_work); in regulator_disable_work()
3149 list_for_each_entry(regulator, &rdev->consumer_list, list) { in regulator_disable_work()
3161 rdev_err(rdev, "Deferred disable failed: %pe\n", in regulator_disable_work()
3167 if (rdev->coupling_desc.n_coupled > 1) in regulator_disable_work()
3168 regulator_balance_voltage(rdev, PM_SUSPEND_ON); in regulator_disable_work()
3170 regulator_unlock_dependent(rdev, &ww_ctx); in regulator_disable_work()
3189 struct regulator_dev *rdev = regulator->rdev; in regulator_disable_deferred() local
3194 regulator_lock(rdev); in regulator_disable_deferred()
3196 mod_delayed_work(system_power_efficient_wq, &rdev->disable_work, in regulator_disable_deferred()
3198 regulator_unlock(rdev); in regulator_disable_deferred()
3204 static int _regulator_is_enabled(struct regulator_dev *rdev) in _regulator_is_enabled() argument
3207 if (rdev->ena_pin) in _regulator_is_enabled()
3208 return rdev->ena_gpio_state; in _regulator_is_enabled()
3211 if (!rdev->desc->ops->is_enabled) in _regulator_is_enabled()
3214 return rdev->desc->ops->is_enabled(rdev); in _regulator_is_enabled()
3217 static int _regulator_list_voltage(struct regulator_dev *rdev, in _regulator_list_voltage() argument
3220 const struct regulator_ops *ops = rdev->desc->ops; in _regulator_list_voltage()
3223 if (rdev->desc->fixed_uV && rdev->desc->n_voltages == 1 && !selector) in _regulator_list_voltage()
3224 return rdev->desc->fixed_uV; in _regulator_list_voltage()
3227 if (selector >= rdev->desc->n_voltages) in _regulator_list_voltage()
3229 if (selector < rdev->desc->linear_min_sel) in _regulator_list_voltage()
3232 regulator_lock(rdev); in _regulator_list_voltage()
3233 ret = ops->list_voltage(rdev, selector); in _regulator_list_voltage()
3235 regulator_unlock(rdev); in _regulator_list_voltage()
3236 } else if (rdev->is_switch && rdev->supply) { in _regulator_list_voltage()
3237 ret = _regulator_list_voltage(rdev->supply->rdev, in _regulator_list_voltage()
3244 if (ret < rdev->constraints->min_uV) in _regulator_list_voltage()
3246 else if (ret > rdev->constraints->max_uV) in _regulator_list_voltage()
3272 regulator_lock(regulator->rdev); in regulator_is_enabled()
3273 ret = _regulator_is_enabled(regulator->rdev); in regulator_is_enabled()
3274 regulator_unlock(regulator->rdev); in regulator_is_enabled()
3291 struct regulator_dev *rdev = regulator->rdev; in regulator_count_voltages() local
3293 if (rdev->desc->n_voltages) in regulator_count_voltages()
3294 return rdev->desc->n_voltages; in regulator_count_voltages()
3296 if (!rdev->is_switch || !rdev->supply) in regulator_count_voltages()
3299 return regulator_count_voltages(rdev->supply); in regulator_count_voltages()
3315 return _regulator_list_voltage(regulator->rdev, selector, 1); in regulator_list_voltage()
3328 struct regmap *map = regulator->rdev->regmap; in regulator_get_regmap()
3355 struct regulator_dev *rdev = regulator->rdev; in regulator_get_hardware_vsel_register() local
3356 const struct regulator_ops *ops = rdev->desc->ops; in regulator_get_hardware_vsel_register()
3361 *vsel_reg = rdev->desc->vsel_reg; in regulator_get_hardware_vsel_register()
3362 *vsel_mask = rdev->desc->vsel_mask; in regulator_get_hardware_vsel_register()
3384 struct regulator_dev *rdev = regulator->rdev; in regulator_list_hardware_vsel() local
3385 const struct regulator_ops *ops = rdev->desc->ops; in regulator_list_hardware_vsel()
3387 if (selector >= rdev->desc->n_voltages) in regulator_list_hardware_vsel()
3389 if (selector < rdev->desc->linear_min_sel) in regulator_list_hardware_vsel()
3410 struct regulator_dev *rdev = regulator->rdev; in regulator_hardware_enable() local
3411 const struct regulator_ops *ops = rdev->desc->ops; in regulator_hardware_enable()
3414 if (!rdev->exclusive || !ops || !ops->enable || !ops->disable) in regulator_hardware_enable()
3418 ret = ops->enable(rdev); in regulator_hardware_enable()
3420 ret = ops->disable(rdev); in regulator_hardware_enable()
3435 struct regulator_dev *rdev = regulator->rdev; in regulator_get_linear_step() local
3437 return rdev->desc->uV_step; in regulator_get_linear_step()
3455 struct regulator_dev *rdev = regulator->rdev; in regulator_is_supported_voltage() local
3459 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) { in regulator_is_supported_voltage()
3468 if (rdev->desc->continuous_voltage_range) in regulator_is_supported_voltage()
3469 return min_uV >= rdev->constraints->min_uV && in regulator_is_supported_voltage()
3470 max_uV <= rdev->constraints->max_uV; in regulator_is_supported_voltage()
3488 static int regulator_map_voltage(struct regulator_dev *rdev, int min_uV, in regulator_map_voltage() argument
3491 const struct regulator_desc *desc = rdev->desc; in regulator_map_voltage()
3494 return desc->ops->map_voltage(rdev, min_uV, max_uV); in regulator_map_voltage()
3497 return regulator_map_voltage_linear(rdev, min_uV, max_uV); in regulator_map_voltage()
3500 return regulator_map_voltage_linear_range(rdev, min_uV, max_uV); in regulator_map_voltage()
3504 return regulator_map_voltage_pickable_linear_range(rdev, in regulator_map_voltage()
3507 return regulator_map_voltage_iterate(rdev, min_uV, max_uV); in regulator_map_voltage()
3510 static int _regulator_call_set_voltage(struct regulator_dev *rdev, in _regulator_call_set_voltage() argument
3517 data.old_uV = regulator_get_voltage_rdev(rdev); in _regulator_call_set_voltage()
3520 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_PRE_VOLTAGE_CHANGE, in _regulator_call_set_voltage()
3525 ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV, selector); in _regulator_call_set_voltage()
3529 _notifier_call_chain(rdev, REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE, in _regulator_call_set_voltage()
3535 static int _regulator_call_set_voltage_sel(struct regulator_dev *rdev, in _regulator_call_set_voltage_sel() argument
3541 data.old_uV = regulator_get_voltage_rdev(rdev); in _regulator_call_set_voltage_sel()
3544 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_PRE_VOLTAGE_CHANGE, in _regulator_call_set_voltage_sel()
3549 ret = rdev->desc->ops->set_voltage_sel(rdev, selector); in _regulator_call_set_voltage_sel()
3553 _notifier_call_chain(rdev, REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE, in _regulator_call_set_voltage_sel()
3559 static int _regulator_set_voltage_sel_step(struct regulator_dev *rdev, in _regulator_set_voltage_sel_step() argument
3562 const struct regulator_ops *ops = rdev->desc->ops; in _regulator_set_voltage_sel_step()
3566 if (!_regulator_is_enabled(rdev)) in _regulator_set_voltage_sel_step()
3572 old_sel = ops->get_voltage_sel(rdev); in _regulator_set_voltage_sel_step()
3582 for (curr_sel = old_sel + rdev->desc->vsel_step; in _regulator_set_voltage_sel_step()
3584 curr_sel += rdev->desc->vsel_step) { in _regulator_set_voltage_sel_step()
3591 ret = ops->set_voltage_sel(rdev, curr_sel); in _regulator_set_voltage_sel_step()
3597 for (curr_sel = old_sel - rdev->desc->vsel_step; in _regulator_set_voltage_sel_step()
3599 curr_sel -= rdev->desc->vsel_step) { in _regulator_set_voltage_sel_step()
3600 ret = ops->set_voltage_sel(rdev, curr_sel); in _regulator_set_voltage_sel_step()
3608 return _regulator_call_set_voltage_sel(rdev, uV, new_selector); in _regulator_set_voltage_sel_step()
3615 (void)ops->set_voltage_sel(rdev, old_sel); in _regulator_set_voltage_sel_step()
3619 static int _regulator_set_voltage_time(struct regulator_dev *rdev, in _regulator_set_voltage_time() argument
3624 if (rdev->constraints->ramp_delay) in _regulator_set_voltage_time()
3625 ramp_delay = rdev->constraints->ramp_delay; in _regulator_set_voltage_time()
3626 else if (rdev->desc->ramp_delay) in _regulator_set_voltage_time()
3627 ramp_delay = rdev->desc->ramp_delay; in _regulator_set_voltage_time()
3628 else if (rdev->constraints->settling_time) in _regulator_set_voltage_time()
3629 return rdev->constraints->settling_time; in _regulator_set_voltage_time()
3630 else if (rdev->constraints->settling_time_up && in _regulator_set_voltage_time()
3632 return rdev->constraints->settling_time_up; in _regulator_set_voltage_time()
3633 else if (rdev->constraints->settling_time_down && in _regulator_set_voltage_time()
3635 return rdev->constraints->settling_time_down; in _regulator_set_voltage_time()
3643 static int _regulator_do_set_voltage(struct regulator_dev *rdev, in _regulator_do_set_voltage() argument
3651 const struct regulator_ops *ops = rdev->desc->ops; in _regulator_do_set_voltage()
3652 int old_uV = regulator_get_voltage_rdev(rdev); in _regulator_do_set_voltage()
3654 trace_regulator_set_voltage(rdev_get_name(rdev), min_uV, max_uV); in _regulator_do_set_voltage()
3656 min_uV += rdev->constraints->uV_offset; in _regulator_do_set_voltage()
3657 max_uV += rdev->constraints->uV_offset; in _regulator_do_set_voltage()
3663 if (_regulator_is_enabled(rdev) && in _regulator_do_set_voltage()
3665 old_selector = ops->get_voltage_sel(rdev); in _regulator_do_set_voltage()
3671 ret = _regulator_call_set_voltage(rdev, min_uV, max_uV, in _regulator_do_set_voltage()
3676 best_val = ops->list_voltage(rdev, in _regulator_do_set_voltage()
3679 best_val = regulator_get_voltage_rdev(rdev); in _regulator_do_set_voltage()
3683 ret = regulator_map_voltage(rdev, min_uV, max_uV); in _regulator_do_set_voltage()
3685 best_val = ops->list_voltage(rdev, ret); in _regulator_do_set_voltage()
3690 else if (rdev->desc->vsel_step) in _regulator_do_set_voltage()
3692 rdev, best_val, selector); in _regulator_do_set_voltage()
3695 rdev, best_val, selector); in _regulator_do_set_voltage()
3713 delay = ops->set_voltage_time_sel(rdev, old_selector, in _regulator_do_set_voltage()
3718 delay = ops->set_voltage_time(rdev, old_uV, in _regulator_do_set_voltage()
3721 delay = _regulator_set_voltage_time(rdev, in _regulator_do_set_voltage()
3728 rdev_warn(rdev, "failed to get delay: %pe\n", ERR_PTR(delay)); in _regulator_do_set_voltage()
3738 _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, in _regulator_do_set_voltage()
3743 trace_regulator_set_voltage_complete(rdev_get_name(rdev), best_val); in _regulator_do_set_voltage()
3748 static int _regulator_do_set_suspend_voltage(struct regulator_dev *rdev, in _regulator_do_set_suspend_voltage() argument
3754 rstate = regulator_get_suspend_state(rdev, state); in _regulator_do_set_suspend_voltage()
3763 sel = regulator_map_voltage(rdev, min_uV, max_uV); in _regulator_do_set_suspend_voltage()
3767 uV = rdev->desc->ops->list_voltage(rdev, sel); in _regulator_do_set_suspend_voltage()
3778 struct regulator_dev *rdev = regulator->rdev; in regulator_set_voltage_unlocked() local
3795 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) { in regulator_set_voltage_unlocked()
3796 current_uV = regulator_get_voltage_rdev(rdev); in regulator_set_voltage_unlocked()
3805 if (!rdev->desc->ops->set_voltage && in regulator_set_voltage_unlocked()
3806 !rdev->desc->ops->set_voltage_sel) { in regulator_set_voltage_unlocked()
3812 ret = regulator_check_voltage(rdev, &min_uV, &max_uV); in regulator_set_voltage_unlocked()
3823 ret = regulator_balance_voltage(rdev, state); in regulator_set_voltage_unlocked()
3833 int regulator_set_voltage_rdev(struct regulator_dev *rdev, int min_uV, in regulator_set_voltage_rdev() argument
3840 if (rdev->supply && in regulator_set_voltage_rdev()
3841 regulator_ops_is_valid(rdev->supply->rdev, in regulator_set_voltage_rdev()
3843 (rdev->desc->min_dropout_uV || !(rdev->desc->ops->get_voltage || in regulator_set_voltage_rdev()
3844 rdev->desc->ops->get_voltage_sel))) { in regulator_set_voltage_rdev()
3848 selector = regulator_map_voltage(rdev, min_uV, max_uV); in regulator_set_voltage_rdev()
3854 best_supply_uV = _regulator_list_voltage(rdev, selector, 0); in regulator_set_voltage_rdev()
3860 best_supply_uV += rdev->desc->min_dropout_uV; in regulator_set_voltage_rdev()
3862 current_supply_uV = regulator_get_voltage_rdev(rdev->supply->rdev); in regulator_set_voltage_rdev()
3872 ret = regulator_set_voltage_unlocked(rdev->supply, in regulator_set_voltage_rdev()
3875 dev_err(&rdev->dev, "Failed to increase supply voltage: %pe\n", in regulator_set_voltage_rdev()
3882 ret = _regulator_do_set_voltage(rdev, min_uV, max_uV); in regulator_set_voltage_rdev()
3884 ret = _regulator_do_set_suspend_voltage(rdev, min_uV, in regulator_set_voltage_rdev()
3890 ret = regulator_set_voltage_unlocked(rdev->supply, in regulator_set_voltage_rdev()
3893 dev_warn(&rdev->dev, "Failed to decrease supply voltage: %pe\n", in regulator_set_voltage_rdev()
3904 static int regulator_limit_voltage_step(struct regulator_dev *rdev, in regulator_limit_voltage_step() argument
3907 struct regulation_constraints *constraints = rdev->constraints; in regulator_limit_voltage_step()
3910 if (!constraints->max_uV_step || !_regulator_is_enabled(rdev)) in regulator_limit_voltage_step()
3914 *current_uV = regulator_get_voltage_rdev(rdev); in regulator_limit_voltage_step()
3934 static int regulator_get_optimal_voltage(struct regulator_dev *rdev, in regulator_get_optimal_voltage() argument
3940 struct coupling_desc *c_desc = &rdev->coupling_desc; in regulator_get_optimal_voltage()
3942 struct regulation_constraints *constraints = rdev->constraints; in regulator_get_optimal_voltage()
3963 ret = regulator_check_consumers(rdev, in regulator_get_optimal_voltage()
4047 ret = regulator_limit_voltage_step(rdev, current_uV, in regulator_get_optimal_voltage()
4059 if (_regulator_is_enabled(rdev)) { in regulator_get_optimal_voltage()
4060 ret = regulator_get_voltage_rdev(rdev); in regulator_get_optimal_voltage()
4076 int regulator_do_balance_voltage(struct regulator_dev *rdev, in regulator_do_balance_voltage() argument
4081 struct coupling_desc *c_desc = &rdev->coupling_desc; in regulator_do_balance_voltage()
4159 static int regulator_balance_voltage(struct regulator_dev *rdev, in regulator_balance_voltage() argument
4162 struct coupling_desc *c_desc = &rdev->coupling_desc; in regulator_balance_voltage()
4174 rdev_err(rdev, "Not all coupled regulators registered\n"); in regulator_balance_voltage()
4180 return coupler->balance_voltage(coupler, rdev, state); in regulator_balance_voltage()
4182 return regulator_do_balance_voltage(rdev, state, skip_coupled); in regulator_balance_voltage()
4210 regulator_lock_dependent(regulator->rdev, &ww_ctx); in regulator_set_voltage()
4215 regulator_unlock_dependent(regulator->rdev, &ww_ctx); in regulator_set_voltage()
4221 static inline int regulator_suspend_toggle(struct regulator_dev *rdev, in regulator_suspend_toggle() argument
4226 rstate = regulator_get_suspend_state(rdev, state); in regulator_suspend_toggle()
4238 int regulator_suspend_enable(struct regulator_dev *rdev, in regulator_suspend_enable() argument
4241 return regulator_suspend_toggle(rdev, state, true); in regulator_suspend_enable()
4245 int regulator_suspend_disable(struct regulator_dev *rdev, in regulator_suspend_disable() argument
4255 list_for_each_entry(regulator, &rdev->consumer_list, list) { in regulator_suspend_disable()
4261 return regulator_suspend_toggle(rdev, state, false); in regulator_suspend_disable()
4269 struct regulator_dev *rdev = regulator->rdev; in _regulator_set_suspend_voltage() local
4272 rstate = regulator_get_suspend_state(rdev, state); in _regulator_set_suspend_voltage()
4277 rdev_err(rdev, "The suspend voltage can't be changed!\n"); in _regulator_set_suspend_voltage()
4294 regulator_lock_dependent(regulator->rdev, &ww_ctx); in regulator_set_suspend_voltage()
4299 regulator_unlock_dependent(regulator->rdev, &ww_ctx); in regulator_set_suspend_voltage()
4320 struct regulator_dev *rdev = regulator->rdev; in regulator_set_voltage_time() local
4321 const struct regulator_ops *ops = rdev->desc->ops; in regulator_set_voltage_time()
4328 return ops->set_voltage_time(rdev, old_uV, new_uV); in regulator_set_voltage_time()
4330 return _regulator_set_voltage_time(rdev, old_uV, new_uV); in regulator_set_voltage_time()
4333 if (!ops->list_voltage || !rdev->desc->n_voltages) in regulator_set_voltage_time()
4336 for (i = 0; i < rdev->desc->n_voltages; i++) { in regulator_set_voltage_time()
4338 if (i < rdev->desc->linear_min_sel) in regulator_set_voltage_time()
4358 return ops->set_voltage_time_sel(rdev, old_sel, new_sel); in regulator_set_voltage_time()
4376 int regulator_set_voltage_time_sel(struct regulator_dev *rdev, in regulator_set_voltage_time_sel() argument
4383 if (!rdev->desc->ops->list_voltage) in regulator_set_voltage_time_sel()
4386 old_volt = rdev->desc->ops->list_voltage(rdev, old_selector); in regulator_set_voltage_time_sel()
4387 new_volt = rdev->desc->ops->list_voltage(rdev, new_selector); in regulator_set_voltage_time_sel()
4389 if (rdev->desc->ops->set_voltage_time) in regulator_set_voltage_time_sel()
4390 return rdev->desc->ops->set_voltage_time(rdev, old_volt, in regulator_set_voltage_time_sel()
4393 return _regulator_set_voltage_time(rdev, old_volt, new_volt); in regulator_set_voltage_time_sel()
4397 int regulator_sync_voltage_rdev(struct regulator_dev *rdev) in regulator_sync_voltage_rdev() argument
4401 regulator_lock(rdev); in regulator_sync_voltage_rdev()
4403 if (!rdev->desc->ops->set_voltage && in regulator_sync_voltage_rdev()
4404 !rdev->desc->ops->set_voltage_sel) { in regulator_sync_voltage_rdev()
4410 if (rdev->coupling_desc.n_coupled > 1) in regulator_sync_voltage_rdev()
4411 ret = regulator_balance_voltage(rdev, PM_SUSPEND_ON); in regulator_sync_voltage_rdev()
4416 regulator_unlock(rdev); in regulator_sync_voltage_rdev()
4432 struct regulator_dev *rdev = regulator->rdev; in regulator_sync_voltage() local
4436 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) in regulator_sync_voltage()
4439 regulator_lock(rdev); in regulator_sync_voltage()
4441 if (!rdev->desc->ops->set_voltage && in regulator_sync_voltage()
4442 !rdev->desc->ops->set_voltage_sel) { in regulator_sync_voltage()
4457 ret = regulator_check_voltage(rdev, &min_uV, &max_uV); in regulator_sync_voltage()
4461 ret = regulator_check_consumers(rdev, &min_uV, &max_uV, 0); in regulator_sync_voltage()
4466 if (rdev->coupling_desc.n_coupled > 1) in regulator_sync_voltage()
4467 ret = regulator_balance_voltage(rdev, PM_SUSPEND_ON); in regulator_sync_voltage()
4469 ret = _regulator_do_set_voltage(rdev, min_uV, max_uV); in regulator_sync_voltage()
4472 regulator_unlock(rdev); in regulator_sync_voltage()
4477 int regulator_get_voltage_rdev(struct regulator_dev *rdev) in regulator_get_voltage_rdev() argument
4482 if (rdev->desc->ops->get_bypass) { in regulator_get_voltage_rdev()
4483 ret = rdev->desc->ops->get_bypass(rdev, &bypassed); in regulator_get_voltage_rdev()
4488 if (!rdev->supply) { in regulator_get_voltage_rdev()
4489 rdev_err(rdev, in regulator_get_voltage_rdev()
4494 return regulator_get_voltage_rdev(rdev->supply->rdev); in regulator_get_voltage_rdev()
4498 if (rdev->desc->ops->get_voltage_sel) { in regulator_get_voltage_rdev()
4499 sel = rdev->desc->ops->get_voltage_sel(rdev); in regulator_get_voltage_rdev()
4502 ret = rdev->desc->ops->list_voltage(rdev, sel); in regulator_get_voltage_rdev()
4503 } else if (rdev->desc->ops->get_voltage) { in regulator_get_voltage_rdev()
4504 ret = rdev->desc->ops->get_voltage(rdev); in regulator_get_voltage_rdev()
4505 } else if (rdev->desc->ops->list_voltage) { in regulator_get_voltage_rdev()
4506 ret = rdev->desc->ops->list_voltage(rdev, 0); in regulator_get_voltage_rdev()
4507 } else if (rdev->desc->fixed_uV && (rdev->desc->n_voltages == 1)) { in regulator_get_voltage_rdev()
4508 ret = rdev->desc->fixed_uV; in regulator_get_voltage_rdev()
4509 } else if (rdev->supply) { in regulator_get_voltage_rdev()
4510 ret = regulator_get_voltage_rdev(rdev->supply->rdev); in regulator_get_voltage_rdev()
4511 } else if (rdev->supply_name) { in regulator_get_voltage_rdev()
4519 return ret - rdev->constraints->uV_offset; in regulator_get_voltage_rdev()
4537 regulator_lock_dependent(regulator->rdev, &ww_ctx); in regulator_get_voltage()
4538 ret = regulator_get_voltage_rdev(regulator->rdev); in regulator_get_voltage()
4539 regulator_unlock_dependent(regulator->rdev, &ww_ctx); in regulator_get_voltage()
4566 struct regulator_dev *rdev = regulator->rdev; in regulator_set_current_limit() local
4569 regulator_lock(rdev); in regulator_set_current_limit()
4572 if (!rdev->desc->ops->set_current_limit) { in regulator_set_current_limit()
4578 ret = regulator_check_current_limit(rdev, &min_uA, &max_uA); in regulator_set_current_limit()
4582 ret = rdev->desc->ops->set_current_limit(rdev, min_uA, max_uA); in regulator_set_current_limit()
4584 regulator_unlock(rdev); in regulator_set_current_limit()
4589 static int _regulator_get_current_limit_unlocked(struct regulator_dev *rdev) in _regulator_get_current_limit_unlocked() argument
4592 if (!rdev->desc->ops->get_current_limit) in _regulator_get_current_limit_unlocked()
4595 return rdev->desc->ops->get_current_limit(rdev); in _regulator_get_current_limit_unlocked()
4598 static int _regulator_get_current_limit(struct regulator_dev *rdev) in _regulator_get_current_limit() argument
4602 regulator_lock(rdev); in _regulator_get_current_limit()
4603 ret = _regulator_get_current_limit_unlocked(rdev); in _regulator_get_current_limit()
4604 regulator_unlock(rdev); in _regulator_get_current_limit()
4621 return _regulator_get_current_limit(regulator->rdev); in regulator_get_current_limit()
4640 struct regulator_dev *rdev = regulator->rdev; in regulator_set_mode() local
4644 regulator_lock(rdev); in regulator_set_mode()
4647 if (!rdev->desc->ops->set_mode) { in regulator_set_mode()
4653 if (rdev->desc->ops->get_mode) { in regulator_set_mode()
4654 regulator_curr_mode = rdev->desc->ops->get_mode(rdev); in regulator_set_mode()
4662 ret = regulator_mode_constrain(rdev, &mode); in regulator_set_mode()
4666 ret = rdev->desc->ops->set_mode(rdev, mode); in regulator_set_mode()
4668 regulator_unlock(rdev); in regulator_set_mode()
4673 static unsigned int _regulator_get_mode_unlocked(struct regulator_dev *rdev) in _regulator_get_mode_unlocked() argument
4676 if (!rdev->desc->ops->get_mode) in _regulator_get_mode_unlocked()
4679 return rdev->desc->ops->get_mode(rdev); in _regulator_get_mode_unlocked()
4682 static unsigned int _regulator_get_mode(struct regulator_dev *rdev) in _regulator_get_mode() argument
4686 regulator_lock(rdev); in _regulator_get_mode()
4687 ret = _regulator_get_mode_unlocked(rdev); in _regulator_get_mode()
4688 regulator_unlock(rdev); in _regulator_get_mode()
4704 return _regulator_get_mode(regulator->rdev); in regulator_get_mode()
4708 static int rdev_get_cached_err_flags(struct regulator_dev *rdev) in rdev_get_cached_err_flags() argument
4712 if (rdev->use_cached_err) { in rdev_get_cached_err_flags()
4713 spin_lock(&rdev->err_lock); in rdev_get_cached_err_flags()
4714 ret = rdev->cached_err; in rdev_get_cached_err_flags()
4715 spin_unlock(&rdev->err_lock); in rdev_get_cached_err_flags()
4720 static int _regulator_get_error_flags(struct regulator_dev *rdev, in _regulator_get_error_flags() argument
4725 regulator_lock(rdev); in _regulator_get_error_flags()
4727 cached_flags = rdev_get_cached_err_flags(rdev); in _regulator_get_error_flags()
4729 if (rdev->desc->ops->get_error_flags) in _regulator_get_error_flags()
4730 ret = rdev->desc->ops->get_error_flags(rdev, flags); in _regulator_get_error_flags()
4731 else if (!rdev->use_cached_err) in _regulator_get_error_flags()
4736 regulator_unlock(rdev); in _regulator_get_error_flags()
4753 return _regulator_get_error_flags(regulator->rdev, flags); in regulator_get_error_flags()
4793 struct regulator_dev *rdev = regulator->rdev; in regulator_set_load() local
4797 regulator_lock(rdev); in regulator_set_load()
4801 ret = drms_uA_update(rdev); in regulator_set_load()
4805 regulator_unlock(rdev); in regulator_set_load()
4827 struct regulator_dev *rdev = regulator->rdev; in regulator_allow_bypass() local
4828 const char *name = rdev_get_name(rdev); in regulator_allow_bypass()
4831 if (!rdev->desc->ops->set_bypass) in regulator_allow_bypass()
4834 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_BYPASS)) in regulator_allow_bypass()
4837 regulator_lock(rdev); in regulator_allow_bypass()
4840 rdev->bypass_count++; in regulator_allow_bypass()
4842 if (rdev->bypass_count == rdev->open_count) { in regulator_allow_bypass()
4845 ret = rdev->desc->ops->set_bypass(rdev, enable); in regulator_allow_bypass()
4847 rdev->bypass_count--; in regulator_allow_bypass()
4853 rdev->bypass_count--; in regulator_allow_bypass()
4855 if (rdev->bypass_count != rdev->open_count) { in regulator_allow_bypass()
4858 ret = rdev->desc->ops->set_bypass(rdev, enable); in regulator_allow_bypass()
4860 rdev->bypass_count++; in regulator_allow_bypass()
4869 regulator_unlock(rdev); in regulator_allow_bypass()
4887 return blocking_notifier_chain_register(®ulator->rdev->notifier, in regulator_register_notifier()
4904 return blocking_notifier_chain_unregister(®ulator->rdev->notifier, in regulator_unregister_notifier()
4912 static int _notifier_call_chain(struct regulator_dev *rdev, in _notifier_call_chain() argument
4916 int ret = blocking_notifier_call_chain(&rdev->notifier, event, data); in _notifier_call_chain()
4919 struct device *parent = rdev->dev.parent; in _notifier_call_chain()
4920 const char *rname = rdev_get_name(rdev); in _notifier_call_chain()
4924 if (parent && rname == rdev->desc->name) { in _notifier_call_chain()
5156 static void regulator_handle_critical(struct regulator_dev *rdev, in regulator_handle_critical() argument
5161 if (!rdev->constraints->system_critical) in regulator_handle_critical()
5179 rdev->constraints->uv_less_critical_window_ms); in regulator_handle_critical()
5193 int regulator_notifier_call_chain(struct regulator_dev *rdev, in regulator_notifier_call_chain() argument
5196 regulator_handle_critical(rdev, event); in regulator_notifier_call_chain()
5198 _notifier_call_chain(rdev, event, data); in regulator_notifier_call_chain()
5274 struct regulator_dev *rdev = dev_to_rdev(dev); in regulator_attr_is_visible() local
5275 const struct regulator_ops *ops = rdev->desc->ops; in regulator_attr_is_visible()
5286 if ((ops->get_voltage && ops->get_voltage(rdev) >= 0) || in regulator_attr_is_visible()
5287 (ops->get_voltage_sel && ops->get_voltage_sel(rdev) >= 0) || in regulator_attr_is_visible()
5288 (ops->list_voltage && ops->list_voltage(rdev, 0) >= 0) || in regulator_attr_is_visible()
5289 (rdev->desc->fixed_uV && rdev->desc->n_voltages == 1)) in regulator_attr_is_visible()
5301 return (rdev->ena_pin || ops->is_enabled) ? mode : 0; in regulator_attr_is_visible()
5359 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_dev_release() local
5361 debugfs_remove_recursive(rdev->debugfs); in regulator_dev_release()
5362 kfree(rdev->constraints); in regulator_dev_release()
5363 of_node_put(rdev->dev.of_node); in regulator_dev_release()
5364 kfree(rdev); in regulator_dev_release()
5367 static void rdev_init_debugfs(struct regulator_dev *rdev) in rdev_init_debugfs() argument
5369 struct device *parent = rdev->dev.parent; in rdev_init_debugfs()
5370 const char *rname = rdev_get_name(rdev); in rdev_init_debugfs()
5374 if (parent && rname == rdev->desc->name) { in rdev_init_debugfs()
5380 rdev->debugfs = debugfs_create_dir(rname, debugfs_root); in rdev_init_debugfs()
5381 if (IS_ERR(rdev->debugfs)) in rdev_init_debugfs()
5382 rdev_dbg(rdev, "Failed to create debugfs directory\n"); in rdev_init_debugfs()
5384 debugfs_create_u32("use_count", 0444, rdev->debugfs, in rdev_init_debugfs()
5385 &rdev->use_count); in rdev_init_debugfs()
5386 debugfs_create_u32("open_count", 0444, rdev->debugfs, in rdev_init_debugfs()
5387 &rdev->open_count); in rdev_init_debugfs()
5388 debugfs_create_u32("bypass_count", 0444, rdev->debugfs, in rdev_init_debugfs()
5389 &rdev->bypass_count); in rdev_init_debugfs()
5394 struct regulator_dev *rdev = dev_to_rdev(dev); in regulator_register_resolve_supply() local
5396 if (regulator_resolve_supply(rdev)) in regulator_register_resolve_supply()
5397 rdev_dbg(rdev, "unable to resolve supply\n"); in regulator_register_resolve_supply()
5412 regulator_find_coupler(struct regulator_dev *rdev) in regulator_find_coupler() argument
5423 err = coupler->attach_regulator(coupler, rdev); in regulator_find_coupler()
5426 rdev->coupling_desc.n_coupled > 2) in regulator_find_coupler()
5445 coupler->detach_regulator(coupler, rdev); in regulator_find_coupler()
5447 rdev_err(rdev, in regulator_find_coupler()
5453 static void regulator_resolve_coupling(struct regulator_dev *rdev) in regulator_resolve_coupling() argument
5455 struct regulator_coupler *coupler = rdev->coupling_desc.coupler; in regulator_resolve_coupling()
5456 struct coupling_desc *c_desc = &rdev->coupling_desc; in regulator_resolve_coupling()
5466 c_rdev = of_parse_coupled_regulator(rdev, i - 1); in regulator_resolve_coupling()
5472 rdev_err(rdev, "coupler mismatch with %s\n", in regulator_resolve_coupling()
5484 static void regulator_remove_coupling(struct regulator_dev *rdev) in regulator_remove_coupling() argument
5486 struct regulator_coupler *coupler = rdev->coupling_desc.coupler; in regulator_remove_coupling()
5487 struct coupling_desc *__c_desc, *c_desc = &rdev->coupling_desc; in regulator_remove_coupling()
5509 if (__c_rdev == rdev) { in regulator_remove_coupling()
5523 err = coupler->detach_regulator(coupler, rdev); in regulator_remove_coupling()
5525 rdev_err(rdev, "failed to detach from coupler: %pe\n", in regulator_remove_coupling()
5529 kfree(rdev->coupling_desc.coupled_rdevs); in regulator_remove_coupling()
5530 rdev->coupling_desc.coupled_rdevs = NULL; in regulator_remove_coupling()
5533 static int regulator_init_coupling(struct regulator_dev *rdev) in regulator_init_coupling() argument
5541 n_phandles = of_get_n_coupled(rdev); in regulator_init_coupling()
5547 rdev->coupling_desc.coupled_rdevs = coupled; in regulator_init_coupling()
5553 rdev->coupling_desc.coupled_rdevs[0] = rdev; in regulator_init_coupling()
5554 rdev->coupling_desc.n_coupled = n_phandles + 1; in regulator_init_coupling()
5555 rdev->coupling_desc.n_resolved++; in regulator_init_coupling()
5561 if (!of_check_coupling_data(rdev)) in regulator_init_coupling()
5565 rdev->coupling_desc.coupler = regulator_find_coupler(rdev); in regulator_init_coupling()
5568 if (IS_ERR(rdev->coupling_desc.coupler)) { in regulator_init_coupling()
5569 err = PTR_ERR(rdev->coupling_desc.coupler); in regulator_init_coupling()
5570 rdev_err(rdev, "failed to get coupler: %pe\n", ERR_PTR(err)); in regulator_init_coupling()
5578 struct regulator_dev *rdev) in generic_coupler_attach() argument
5580 if (rdev->coupling_desc.n_coupled > 2) { in generic_coupler_attach()
5581 rdev_err(rdev, in generic_coupler_attach()
5586 if (!rdev->constraints->always_on) { in generic_coupler_attach()
5587 rdev_err(rdev, in generic_coupler_attach()
5618 struct regulator_dev *rdev; in regulator_register() local
5664 rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); in regulator_register()
5665 if (rdev == NULL) { in regulator_register()
5669 device_initialize(&rdev->dev); in regulator_register()
5670 dev_set_drvdata(&rdev->dev, rdev); in regulator_register()
5671 rdev->dev.class = ®ulator_class; in regulator_register()
5672 spin_lock_init(&rdev->err_lock); in regulator_register()
5685 &rdev->dev.of_node); in regulator_register()
5709 rdev->dev.of_node = of_node_get(config->of_node); in regulator_register()
5712 ww_mutex_init(&rdev->mutex, ®ulator_ww_class); in regulator_register()
5713 rdev->reg_data = config->driver_data; in regulator_register()
5714 rdev->owner = regulator_desc->owner; in regulator_register()
5715 rdev->desc = regulator_desc; in regulator_register()
5717 rdev->regmap = config->regmap; in regulator_register()
5719 rdev->regmap = dev_get_regmap(dev, NULL); in regulator_register()
5721 rdev->regmap = dev_get_regmap(dev->parent, NULL); in regulator_register()
5722 INIT_LIST_HEAD(&rdev->consumer_list); in regulator_register()
5723 INIT_LIST_HEAD(&rdev->list); in regulator_register()
5724 BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier); in regulator_register()
5725 INIT_DELAYED_WORK(&rdev->disable_work, regulator_disable_work); in regulator_register()
5728 rdev->supply_name = init_data->supply_regulator; in regulator_register()
5730 rdev->supply_name = regulator_desc->supply_name; in regulator_register()
5733 rdev->dev.parent = config->dev; in regulator_register()
5734 dev_set_name(&rdev->dev, "regulator.%lu", in regulator_register()
5739 rdev->constraints = kmemdup(&init_data->constraints, in regulator_register()
5740 sizeof(*rdev->constraints), in regulator_register()
5743 rdev->constraints = kzalloc(sizeof(*rdev->constraints), in regulator_register()
5745 if (!rdev->constraints) { in regulator_register()
5750 if ((rdev->supply_name && !rdev->supply) && in regulator_register()
5751 (rdev->constraints->always_on || in regulator_register()
5752 rdev->constraints->boot_on)) { in regulator_register()
5753 ret = regulator_resolve_supply(rdev); in regulator_register()
5755 rdev_dbg(rdev, "unable to resolve supply early: %pe\n", in regulator_register()
5763 ret = init_data->regulator_init(rdev->reg_data); in regulator_register()
5769 ret = regulator_ena_gpio_request(rdev, config); in regulator_register()
5771 rdev_err(rdev, "Failed to request enable GPIO: %pe\n", in regulator_register()
5780 ret = set_machine_constraints(rdev); in regulator_register()
5789 rdev_dbg(rdev, "will resolve supply early: %s\n", in regulator_register()
5790 rdev->supply_name); in regulator_register()
5791 ret = regulator_resolve_supply(rdev); in regulator_register()
5793 ret = set_machine_constraints(rdev); in regulator_register()
5795 rdev_dbg(rdev, "unable to resolve supply early: %pe\n", in regulator_register()
5801 ret = regulator_init_coupling(rdev); in regulator_register()
5808 ret = set_consumer_device_supply(rdev, in regulator_register()
5819 if (!rdev->desc->ops->get_voltage && in regulator_register()
5820 !rdev->desc->ops->list_voltage && in regulator_register()
5821 !rdev->desc->fixed_uV) in regulator_register()
5822 rdev->is_switch = true; in regulator_register()
5824 ret = device_add(&rdev->dev); in regulator_register()
5828 rdev_init_debugfs(rdev); in regulator_register()
5832 regulator_resolve_coupling(rdev); in regulator_register()
5839 return rdev; in regulator_register()
5843 unset_regulator_supplies(rdev); in regulator_register()
5844 regulator_remove_coupling(rdev); in regulator_register()
5847 regulator_put(rdev->supply); in regulator_register()
5848 kfree(rdev->coupling_desc.coupled_rdevs); in regulator_register()
5850 regulator_ena_gpio_free(rdev); in regulator_register()
5856 put_device(&rdev->dev); in regulator_register()
5870 void regulator_unregister(struct regulator_dev *rdev) in regulator_unregister() argument
5872 if (rdev == NULL) in regulator_unregister()
5875 if (rdev->supply) { in regulator_unregister()
5876 while (rdev->use_count--) in regulator_unregister()
5877 regulator_disable(rdev->supply); in regulator_unregister()
5878 regulator_put(rdev->supply); in regulator_unregister()
5881 flush_work(&rdev->disable_work.work); in regulator_unregister()
5885 WARN_ON(rdev->open_count); in regulator_unregister()
5886 regulator_remove_coupling(rdev); in regulator_unregister()
5887 unset_regulator_supplies(rdev); in regulator_unregister()
5888 list_del(&rdev->list); in regulator_unregister()
5889 regulator_ena_gpio_free(rdev); in regulator_unregister()
5890 device_unregister(&rdev->dev); in regulator_unregister()
5907 struct regulator_dev *rdev = dev_to_rdev(dev); in regulator_suspend() local
5912 rstate = regulator_get_suspend_state_check(rdev, state); in regulator_suspend()
5916 regulator_lock(rdev); in regulator_suspend()
5917 ret = __suspend_set_state(rdev, rstate); in regulator_suspend()
5918 regulator_unlock(rdev); in regulator_suspend()
5926 struct regulator_dev *rdev = dev_to_rdev(dev); in regulator_resume() local
5930 rstate = regulator_get_suspend_state(rdev, state); in regulator_resume()
5935 if (!rdev->desc->ops->resume) in regulator_resume()
5938 regulator_lock(rdev); in regulator_resume()
5942 ret = rdev->desc->ops->resume(rdev); in regulator_resume()
5944 regulator_unlock(rdev); in regulator_resume()
5996 void *rdev_get_drvdata(struct regulator_dev *rdev) in rdev_get_drvdata() argument
5998 return rdev->reg_data; in rdev_get_drvdata()
6013 return regulator->rdev->reg_data; in regulator_get_drvdata()
6024 regulator->rdev->reg_data = data; in regulator_set_drvdata()
6034 int rdev_get_id(struct regulator_dev *rdev) in rdev_get_id() argument
6036 return rdev->desc->id; in rdev_get_id()
6040 struct device *rdev_get_dev(struct regulator_dev *rdev) in rdev_get_dev() argument
6042 return &rdev->dev; in rdev_get_dev()
6046 struct regmap *rdev_get_regmap(struct regulator_dev *rdev) in rdev_get_regmap() argument
6048 return rdev->regmap; in rdev_get_regmap()
6080 struct regulator_dev *rdev,
6085 struct regulator_dev *rdev = dev_to_rdev(dev); in regulator_summary_show_children() local
6088 if (rdev->supply && rdev->supply->rdev == summary_data->parent) in regulator_summary_show_children()
6089 regulator_summary_show_subtree(summary_data->s, rdev, in regulator_summary_show_children()
6096 struct regulator_dev *rdev, in regulator_summary_show_subtree() argument
6104 if (!rdev) in regulator_summary_show_subtree()
6107 opmode = _regulator_get_mode_unlocked(rdev); in regulator_summary_show_subtree()
6110 30 - level * 3, rdev_get_name(rdev), in regulator_summary_show_subtree()
6111 rdev->use_count, rdev->open_count, rdev->bypass_count, in regulator_summary_show_subtree()
6114 seq_printf(s, "%5dmV ", regulator_get_voltage_rdev(rdev) / 1000); in regulator_summary_show_subtree()
6116 _regulator_get_current_limit_unlocked(rdev) / 1000); in regulator_summary_show_subtree()
6118 c = rdev->constraints; in regulator_summary_show_subtree()
6120 switch (rdev->desc->type) { in regulator_summary_show_subtree()
6134 list_for_each_entry(consumer, &rdev->consumer_list, list) { in regulator_summary_show_subtree()
6144 switch (rdev->desc->type) { in regulator_summary_show_subtree()
6163 summary_data.parent = rdev; in regulator_summary_show_subtree()
6177 struct regulator_dev *rdev = dev_to_rdev(dev); in regulator_summary_lock_one() local
6181 if (rdev != *lock_data->old_contended_rdev) { in regulator_summary_lock_one()
6182 ret = regulator_lock_nested(rdev, lock_data->ww_ctx); in regulator_summary_lock_one()
6185 *lock_data->new_contended_rdev = rdev; in regulator_summary_lock_one()
6197 struct regulator_dev *rdev = dev_to_rdev(dev); in regulator_summary_unlock_one() local
6201 if (rdev == *lock_data->new_contended_rdev) in regulator_summary_unlock_one()
6205 regulator_unlock(rdev); in regulator_summary_unlock_one()
6271 struct regulator_dev *rdev = dev_to_rdev(dev); in regulator_summary_show_roots() local
6274 if (!rdev->supply) in regulator_summary_show_roots()
6275 regulator_summary_show_subtree(s, rdev, 0); in regulator_summary_show_roots()
6328 struct regulator_dev *rdev = dev_to_rdev(dev); in regulator_late_cleanup() local
6329 struct regulation_constraints *c = rdev->constraints; in regulator_late_cleanup()
6335 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_STATUS)) in regulator_late_cleanup()
6338 regulator_lock(rdev); in regulator_late_cleanup()
6340 if (rdev->use_count) in regulator_late_cleanup()
6344 if (_regulator_is_enabled(rdev) <= 0) in regulator_late_cleanup()
6351 rdev_info(rdev, "disabling\n"); in regulator_late_cleanup()
6352 ret = _regulator_do_disable(rdev); in regulator_late_cleanup()
6354 rdev_err(rdev, "couldn't disable: %pe\n", ERR_PTR(ret)); in regulator_late_cleanup()
6361 rdev_warn(rdev, "incomplete constraints, leaving on\n"); in regulator_late_cleanup()
6365 regulator_unlock(rdev); in regulator_late_cleanup()