Lines Matching +full:uv +full:- +full:shutdown
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 // core.c -- Voltage/Current Regulator framework.
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()
121 if (!rdev->constraints) { in regulator_ops_is_valid()
126 if (rdev->constraints->valid_ops_mask & ops) in regulator_ops_is_valid()
133 * regulator_lock_nested - lock a single regulator
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()
168 if (lock && ret != -EDEADLK) { in regulator_lock_nested()
169 rdev->ref_cnt++; in regulator_lock_nested()
170 rdev->mutex_owner = current; in regulator_lock_nested()
179 * regulator_lock - lock a single regulator
194 * regulator_unlock - unlock a single regulator
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()
215 * regulator_lock_two - lock two regulators
235 if (ret != -EDEADLOCK) { in regulator_lock_two()
245 ww_mutex_lock_slow(&contended->mutex, ww_ctx); in regulator_lock_two()
246 contended->ref_cnt++; in regulator_lock_two()
247 contended->mutex_owner = current; in regulator_lock_two()
251 if (ret != -EDEADLOCK) { in regulator_lock_two()
262 * regulator_unlock_two - unlock two regulators
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()
300 for (i = n_coupled; i > 0; i--) { in regulator_unlock_recursive()
301 c_rdev = rdev->coupling_desc.coupled_rdevs[i - 1]; in regulator_unlock_recursive()
306 if (c_rdev->supply && !regulator_supply_is_couple(c_rdev)) { in regulator_unlock_recursive()
307 supply_rdev = c_rdev->supply->rdev; in regulator_unlock_recursive()
308 supply_n_coupled = supply_rdev->coupling_desc.n_coupled; in regulator_unlock_recursive()
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()
335 if (err == -EDEADLK) { in regulator_lock_recursive()
341 WARN_ON_ONCE(err != -EALREADY); in regulator_lock_recursive()
347 if (c_rdev->supply && !regulator_supply_is_couple(c_rdev)) { in regulator_lock_recursive()
348 err = regulator_lock_recursive(c_rdev->supply->rdev, in regulator_lock_recursive()
368 * regulator_unlock_dependent - unlock regulator's suppliers and coupled
378 regulator_unlock_recursive(rdev, rdev->coupling_desc.n_coupled); in regulator_unlock_dependent()
383 * regulator_lock_dependent - lock regulator's suppliers and coupled regulators
403 ww_mutex_lock_slow(&new_contended_rdev->mutex, ww_ctx); in regulator_lock_dependent()
405 old_contended_rdev->ref_cnt++; in regulator_lock_dependent()
406 old_contended_rdev->mutex_owner = current; in regulator_lock_dependent()
417 } while (err == -EDEADLK); in regulator_lock_dependent()
432 return -EPERM; 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()
443 return -EINVAL; in regulator_check_voltage()
465 list_for_each_entry(regulator, &rdev->consumer_list, list) { in regulator_check_consumers()
466 voltage = ®ulator->voltage[state]; in regulator_check_consumers()
471 if (!voltage->min_uV && !voltage->max_uV) in regulator_check_consumers()
474 if (*max_uV > voltage->max_uV) in regulator_check_consumers()
475 *max_uV = voltage->max_uV; in regulator_check_consumers()
476 if (*min_uV < voltage->min_uV) in regulator_check_consumers()
477 *min_uV = voltage->min_uV; in regulator_check_consumers()
481 rdev_err(rdev, "Restricting voltage, %u-%uuV\n", in regulator_check_consumers()
483 return -EINVAL; in regulator_check_consumers()
497 return -EPERM; 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()
509 return -EINVAL; in regulator_check_current_limit()
527 return -EINVAL; in regulator_mode_constrain()
532 return -EPERM; in regulator_mode_constrain()
540 if (rdev->constraints->valid_modes_mask & *mode) in regulator_mode_constrain()
545 return -EINVAL; in regulator_mode_constrain()
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()
579 if (rstate->enabled != ENABLE_IN_SUSPEND && in regulator_get_suspend_state_check()
580 rstate->enabled != DISABLE_IN_SUSPEND) { 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()
594 int uV; in microvolts_show() local
597 uV = regulator_get_voltage_rdev(rdev); in microvolts_show()
600 if (uV < 0) in microvolts_show()
601 return uV; in microvolts_show()
602 return sprintf(buf, "%d\n", uV); in microvolts_show()
684 status = rdev->desc->ops->get_status(rdev); in status_show()
717 return -ERANGE; in status_show()
729 if (!rdev->constraints) in min_microamps_show()
732 return sprintf(buf, "%d\n", rdev->constraints->min_uA); in min_microamps_show()
741 if (!rdev->constraints) in max_microamps_show()
744 return sprintf(buf, "%d\n", rdev->constraints->max_uA); in max_microamps_show()
753 if (!rdev->constraints) in min_microvolts_show()
756 return sprintf(buf, "%d\n", rdev->constraints->min_uV); in min_microvolts_show()
765 if (!rdev->constraints) in max_microvolts_show()
768 return sprintf(buf, "%d\n", rdev->constraints->max_uV); in max_microvolts_show()
780 list_for_each_entry(regulator, &rdev->consumer_list, list) { in requested_microamps_show()
781 if (regulator->enable_count) in requested_microamps_show()
782 uA += regulator->uA_load; in requested_microamps_show()
793 return sprintf(buf, "%d\n", rdev->use_count); in num_users_show()
802 switch (rdev->desc->type) { in type_show()
817 return sprintf(buf, "%d\n", rdev->constraints->state_mem.uV); in suspend_mem_microvolts_show()
826 return sprintf(buf, "%d\n", rdev->constraints->state_disk.uV); in suspend_disk_microvolts_show()
835 return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV); in suspend_standby_microvolts_show()
845 rdev->constraints->state_mem.mode); in suspend_mem_mode_show()
855 rdev->constraints->state_disk.mode); in suspend_disk_mode_show()
865 rdev->constraints->state_standby.mode); in suspend_standby_mode_show()
875 rdev->constraints->state_mem.enabled); in suspend_mem_state_show()
885 rdev->constraints->state_disk.enabled); in suspend_disk_state_show()
895 rdev->constraints->state_standby.enabled); in suspend_standby_state_show()
907 ret = rdev->desc->ops->get_bypass(rdev, &bypass); in bypass_show()
962 if (!rdev->desc->ops->get_optimum_mode && in drms_uA_update()
963 !rdev->desc->ops->set_load) in drms_uA_update()
966 if (!rdev->desc->ops->set_mode && in drms_uA_update()
967 !rdev->desc->ops->set_load) in drms_uA_update()
968 return -EINVAL; in drms_uA_update()
971 list_for_each_entry(sibling, &rdev->consumer_list, list) { in drms_uA_update()
972 if (sibling->enable_count) in drms_uA_update()
973 current_uA += sibling->uA_load; in drms_uA_update()
976 current_uA += rdev->constraints->system_load; in drms_uA_update()
978 if (rdev->desc->ops->set_load) { in drms_uA_update()
980 err = rdev->desc->ops->set_load(rdev, current_uA); in drms_uA_update()
986 * Unfortunately in some cases the constraints->valid_ops has in drms_uA_update()
992 if (!rdev->constraints->valid_modes_mask) { in drms_uA_update()
1009 if (rdev->supply) in drms_uA_update()
1010 input_uV = regulator_get_voltage_rdev(rdev->supply->rdev); in drms_uA_update()
1012 input_uV = rdev->constraints->input_uV; in drms_uA_update()
1022 mode = rdev->desc->ops->get_optimum_mode(rdev, input_uV, in drms_uA_update()
1028 rdev_err(rdev, "failed to get optimum mode @ %d uA %d -> %d uV: %pe\n", in drms_uA_update()
1033 err = rdev->desc->ops->set_mode(rdev, mode); in drms_uA_update()
1047 if (rstate->enabled == ENABLE_IN_SUSPEND && in __suspend_set_state()
1048 rdev->desc->ops->set_suspend_enable) in __suspend_set_state()
1049 ret = rdev->desc->ops->set_suspend_enable(rdev); in __suspend_set_state()
1050 else if (rstate->enabled == DISABLE_IN_SUSPEND && in __suspend_set_state()
1051 rdev->desc->ops->set_suspend_disable) in __suspend_set_state()
1052 ret = rdev->desc->ops->set_suspend_disable(rdev); in __suspend_set_state()
1061 if (rdev->desc->ops->set_suspend_voltage && rstate->uV > 0) { in __suspend_set_state()
1062 ret = rdev->desc->ops->set_suspend_voltage(rdev, rstate->uV); in __suspend_set_state()
1069 if (rdev->desc->ops->set_suspend_mode && rstate->mode > 0) { in __suspend_set_state()
1070 ret = rdev->desc->ops->set_suspend_mode(rdev, rstate->mode); in __suspend_set_state()
1085 rdev->constraints->initial_state); in suspend_set_initial_state()
1095 struct regulation_constraints *constraints = rdev->constraints; in print_constraints_debug()
1097 size_t len = sizeof(buf) - 1; in print_constraints_debug()
1101 if (constraints->min_uV && constraints->max_uV) { in print_constraints_debug()
1102 if (constraints->min_uV == constraints->max_uV) in print_constraints_debug()
1103 count += scnprintf(buf + count, len - count, "%d mV ", in print_constraints_debug()
1104 constraints->min_uV / 1000); in print_constraints_debug()
1106 count += scnprintf(buf + count, len - count, in print_constraints_debug()
1107 "%d <--> %d mV ", in print_constraints_debug()
1108 constraints->min_uV / 1000, in print_constraints_debug()
1109 constraints->max_uV / 1000); in print_constraints_debug()
1112 if (!constraints->min_uV || in print_constraints_debug()
1113 constraints->min_uV != constraints->max_uV) { in print_constraints_debug()
1116 count += scnprintf(buf + count, len - count, in print_constraints_debug()
1120 if (constraints->uV_offset) in print_constraints_debug()
1121 count += scnprintf(buf + count, len - count, "%dmV offset ", in print_constraints_debug()
1122 constraints->uV_offset / 1000); in print_constraints_debug()
1124 if (constraints->min_uA && constraints->max_uA) { in print_constraints_debug()
1125 if (constraints->min_uA == constraints->max_uA) in print_constraints_debug()
1126 count += scnprintf(buf + count, len - count, "%d mA ", in print_constraints_debug()
1127 constraints->min_uA / 1000); in print_constraints_debug()
1129 count += scnprintf(buf + count, len - count, in print_constraints_debug()
1130 "%d <--> %d mA ", in print_constraints_debug()
1131 constraints->min_uA / 1000, in print_constraints_debug()
1132 constraints->max_uA / 1000); in print_constraints_debug()
1135 if (!constraints->min_uA || in print_constraints_debug()
1136 constraints->min_uA != constraints->max_uA) { in print_constraints_debug()
1139 count += scnprintf(buf + count, len - count, in print_constraints_debug()
1143 if (constraints->valid_modes_mask & REGULATOR_MODE_FAST) in print_constraints_debug()
1144 count += scnprintf(buf + count, len - count, "fast "); in print_constraints_debug()
1145 if (constraints->valid_modes_mask & REGULATOR_MODE_NORMAL) in print_constraints_debug()
1146 count += scnprintf(buf + count, len - count, "normal "); in print_constraints_debug()
1147 if (constraints->valid_modes_mask & REGULATOR_MODE_IDLE) in print_constraints_debug()
1148 count += scnprintf(buf + count, len - count, "idle "); in print_constraints_debug()
1149 if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY) in print_constraints_debug()
1150 count += scnprintf(buf + count, len - count, "standby "); in print_constraints_debug()
1155 --count; in print_constraints_debug()
1157 count += scnprintf(buf + count, len - count, ", %s", in print_constraints_debug()
1168 struct regulation_constraints *constraints = rdev->constraints; in print_constraints()
1172 if ((constraints->min_uV != constraints->max_uV) && in print_constraints()
1181 const struct regulator_ops *ops = rdev->desc->ops; in machine_constraints_voltage()
1185 if (rdev->constraints->apply_uV && in machine_constraints_voltage()
1186 rdev->constraints->min_uV && rdev->constraints->max_uV) { in machine_constraints_voltage()
1190 if (current_uV == -ENOTRECOVERABLE) { in machine_constraints_voltage()
1192 rdev_info(rdev, "Setting %d-%duV\n", in machine_constraints_voltage()
1193 rdev->constraints->min_uV, in machine_constraints_voltage()
1194 rdev->constraints->max_uV); in machine_constraints_voltage()
1196 rdev->constraints->min_uV, in machine_constraints_voltage()
1197 rdev->constraints->max_uV); in machine_constraints_voltage()
1202 if (current_uV != -EPROBE_DEFER) in machine_constraints_voltage()
1217 if (current_uV < rdev->constraints->min_uV) { in machine_constraints_voltage()
1218 target_min = rdev->constraints->min_uV; in machine_constraints_voltage()
1219 target_max = rdev->constraints->min_uV; in machine_constraints_voltage()
1222 if (current_uV > rdev->constraints->max_uV) { in machine_constraints_voltage()
1223 target_min = rdev->constraints->max_uV; in machine_constraints_voltage()
1224 target_max = rdev->constraints->max_uV; in machine_constraints_voltage()
1228 rdev_info(rdev, "Bringing %duV into %d-%duV\n", in machine_constraints_voltage()
1234 "failed to apply %d-%duV constraint: %pe\n", in machine_constraints_voltage()
1241 /* constrain machine-level voltage specs to fit in machine_constraints_voltage()
1244 if (ops->list_voltage && rdev->desc->n_voltages) { in machine_constraints_voltage()
1245 int count = rdev->desc->n_voltages; in machine_constraints_voltage()
1249 int cmin = constraints->min_uV; in machine_constraints_voltage()
1250 int cmax = constraints->max_uV; in machine_constraints_voltage()
1252 /* it's safe to autoconfigure fixed-voltage supplies in machine_constraints_voltage()
1258 constraints->min_uV = cmin; in machine_constraints_voltage()
1259 constraints->max_uV = cmax; in machine_constraints_voltage()
1266 /* else require explicit machine-level constraints */ in machine_constraints_voltage()
1269 return -EINVAL; in machine_constraints_voltage()
1273 if (rdev->desc->continuous_voltage_range) in machine_constraints_voltage()
1280 value = ops->list_voltage(rdev, i); in machine_constraints_voltage()
1294 "unsupportable voltage constraints %u-%uuV\n", in machine_constraints_voltage()
1296 return -EINVAL; in machine_constraints_voltage()
1300 if (constraints->min_uV < min_uV) { in machine_constraints_voltage()
1301 rdev_dbg(rdev, "override min_uV, %d -> %d\n", in machine_constraints_voltage()
1302 constraints->min_uV, min_uV); in machine_constraints_voltage()
1303 constraints->min_uV = min_uV; in machine_constraints_voltage()
1305 if (constraints->max_uV > max_uV) { in machine_constraints_voltage()
1306 rdev_dbg(rdev, "override max_uV, %d -> %d\n", in machine_constraints_voltage()
1307 constraints->max_uV, max_uV); in machine_constraints_voltage()
1308 constraints->max_uV = max_uV; in machine_constraints_voltage()
1318 const struct regulator_ops *ops = rdev->desc->ops; in machine_constraints_current()
1321 if (!constraints->min_uA && !constraints->max_uA) in machine_constraints_current()
1324 if (constraints->min_uA > constraints->max_uA) { in machine_constraints_current()
1326 return -EINVAL; in machine_constraints_current()
1329 if (!ops->set_current_limit || !ops->get_current_limit) { in machine_constraints_current()
1335 ret = ops->set_current_limit(rdev, constraints->min_uA, in machine_constraints_current()
1336 constraints->max_uA); in machine_constraints_current()
1373 return -EOPNOTSUPP; in handle_notify_limits()
1375 if (limits->prot) in handle_notify_limits()
1376 ret = notif_set_limit(rdev, set, limits->prot, in handle_notify_limits()
1381 if (limits->err) in handle_notify_limits()
1382 ret = notif_set_limit(rdev, set, limits->err, in handle_notify_limits()
1387 if (limits->warn) in handle_notify_limits()
1388 ret = notif_set_limit(rdev, set, limits->warn, in handle_notify_limits()
1394 * set_machine_constraints - sets regulator constraints
1408 const struct regulator_ops *ops = rdev->desc->ops; in set_machine_constraints()
1410 ret = machine_constraints_voltage(rdev, rdev->constraints); in set_machine_constraints()
1414 ret = machine_constraints_current(rdev, rdev->constraints); in set_machine_constraints()
1418 if (rdev->constraints->ilim_uA && ops->set_input_current_limit) { in set_machine_constraints()
1419 ret = ops->set_input_current_limit(rdev, in set_machine_constraints()
1420 rdev->constraints->ilim_uA); in set_machine_constraints()
1428 if (rdev->constraints->initial_state) { in set_machine_constraints()
1436 if (rdev->constraints->initial_mode) { in set_machine_constraints()
1437 if (!ops->set_mode) { in set_machine_constraints()
1439 return -EINVAL; in set_machine_constraints()
1442 ret = ops->set_mode(rdev, rdev->constraints->initial_mode); in set_machine_constraints()
1447 } else if (rdev->constraints->system_load) { in set_machine_constraints()
1455 if ((rdev->constraints->ramp_delay || rdev->constraints->ramp_disable) in set_machine_constraints()
1456 && ops->set_ramp_delay) { in set_machine_constraints()
1457 ret = ops->set_ramp_delay(rdev, rdev->constraints->ramp_delay); in set_machine_constraints()
1464 if (rdev->constraints->pull_down && ops->set_pull_down) { in set_machine_constraints()
1465 ret = ops->set_pull_down(rdev); in set_machine_constraints()
1472 if (rdev->constraints->soft_start && ops->set_soft_start) { in set_machine_constraints()
1473 ret = ops->set_soft_start(rdev); in set_machine_constraints()
1484 * PMIC on board to another type - and the another PMIC's driver does in set_machine_constraints()
1486 * the DT limits are respected - especially if the new PMIC HW also in set_machine_constraints()
1491 * over-curret protection and detection and get rid of this special in set_machine_constraints()
1494 if (rdev->constraints->over_current_protection in set_machine_constraints()
1495 && ops->set_over_current_protection) { in set_machine_constraints()
1496 int lim = rdev->constraints->over_curr_limits.prot; in set_machine_constraints()
1498 ret = ops->set_over_current_protection(rdev, lim, in set_machine_constraints()
1508 if (rdev->constraints->over_current_detection) in set_machine_constraints()
1510 ops->set_over_current_protection, in set_machine_constraints()
1511 &rdev->constraints->over_curr_limits); in set_machine_constraints()
1513 if (ret != -EOPNOTSUPP) { in set_machine_constraints()
1519 "IC does not support requested over-current limits\n"); in set_machine_constraints()
1522 if (rdev->constraints->over_voltage_detection) in set_machine_constraints()
1524 ops->set_over_voltage_protection, in set_machine_constraints()
1525 &rdev->constraints->over_voltage_limits); in set_machine_constraints()
1527 if (ret != -EOPNOTSUPP) { in set_machine_constraints()
1536 if (rdev->constraints->under_voltage_detection) in set_machine_constraints()
1538 ops->set_under_voltage_protection, in set_machine_constraints()
1539 &rdev->constraints->under_voltage_limits); in set_machine_constraints()
1541 if (ret != -EOPNOTSUPP) { in set_machine_constraints()
1550 if (rdev->constraints->over_temp_detection) in set_machine_constraints()
1552 ops->set_thermal_protection, in set_machine_constraints()
1553 &rdev->constraints->temp_limits); in set_machine_constraints()
1555 if (ret != -EOPNOTSUPP) { in set_machine_constraints()
1564 if (rdev->constraints->active_discharge && ops->set_active_discharge) { in set_machine_constraints()
1565 bool ad_state = (rdev->constraints->active_discharge == in set_machine_constraints()
1568 ret = ops->set_active_discharge(rdev, ad_state); in set_machine_constraints()
1582 if (!rdev->ena_pin && !ops->enable) { in set_machine_constraints()
1583 if (rdev->supply_name && !rdev->supply) in set_machine_constraints()
1584 return -EPROBE_DEFER; in set_machine_constraints()
1586 if (rdev->supply) in set_machine_constraints()
1587 rdev->constraints->always_on = in set_machine_constraints()
1588 rdev->supply->rdev->constraints->always_on; in set_machine_constraints()
1590 rdev->constraints->always_on = true; in set_machine_constraints()
1596 if (rdev->constraints->always_on || rdev->constraints->boot_on) { in set_machine_constraints()
1600 if (rdev->supply_name && !rdev->supply) in set_machine_constraints()
1601 return -EPROBE_DEFER; in set_machine_constraints()
1605 * when rdev is only boot-on. in set_machine_constraints()
1607 if (rdev->supply && in set_machine_constraints()
1608 (rdev->constraints->always_on || in set_machine_constraints()
1609 !regulator_is_enabled(rdev->supply))) { in set_machine_constraints()
1610 ret = regulator_enable(rdev->supply); in set_machine_constraints()
1612 _regulator_put(rdev->supply); in set_machine_constraints()
1613 rdev->supply = NULL; in set_machine_constraints()
1619 if (ret < 0 && ret != -EINVAL) { in set_machine_constraints()
1624 if (rdev->constraints->always_on) in set_machine_constraints()
1625 rdev->use_count++; in set_machine_constraints()
1626 } else if (rdev->desc->off_on_delay) { in set_machine_constraints()
1627 rdev->last_off = ktime_get(); in set_machine_constraints()
1635 * set_supply - set regulator supply regulator
1652 if (!try_module_get(supply_rdev->owner)) in set_supply()
1653 return -ENODEV; in set_supply()
1655 rdev->supply = create_regulator(supply_rdev, &rdev->dev, "SUPPLY"); in set_supply()
1656 if (rdev->supply == NULL) { in set_supply()
1657 module_put(supply_rdev->owner); in set_supply()
1658 err = -ENOMEM; in set_supply()
1661 supply_rdev->open_count++; in set_supply()
1667 * set_consumer_device_supply - Bind a regulator to a symbolic supply
1675 * need to provide board-specific regulator names as platform data.
1687 return -EINVAL; in set_consumer_device_supply()
1696 return -ENOMEM; in set_consumer_device_supply()
1698 new_node->regulator = rdev; in set_consumer_device_supply()
1699 new_node->supply = supply; in set_consumer_device_supply()
1702 new_node->dev_name = kstrdup(consumer_dev_name, GFP_KERNEL); in set_consumer_device_supply()
1703 if (new_node->dev_name == NULL) { in set_consumer_device_supply()
1705 return -ENOMEM; in set_consumer_device_supply()
1711 if (node->dev_name && consumer_dev_name) { in set_consumer_device_supply()
1712 if (strcmp(node->dev_name, consumer_dev_name) != 0) in set_consumer_device_supply()
1714 } else if (node->dev_name || consumer_dev_name) { in set_consumer_device_supply()
1718 if (strcmp(node->supply, supply) != 0) in set_consumer_device_supply()
1723 dev_name(&node->regulator->dev), in set_consumer_device_supply()
1724 node->regulator->desc->name, in set_consumer_device_supply()
1726 dev_name(&rdev->dev), rdev_get_name(rdev)); in set_consumer_device_supply()
1730 list_add(&new_node->list, ®ulator_map_list); in set_consumer_device_supply()
1737 kfree(new_node->dev_name); in set_consumer_device_supply()
1739 return -EBUSY; in set_consumer_device_supply()
1747 if (rdev == node->regulator) { in unset_regulator_supplies()
1748 list_del(&node->list); in unset_regulator_supplies()
1749 kfree(node->dev_name); in unset_regulator_supplies()
1760 const struct regulator *regulator = file->private_data; in constraint_flags_read_file()
1761 const struct regulation_constraints *c = regulator->rdev->constraints; in constraint_flags_read_file()
1770 return -ENOMEM; in constraint_flags_read_file()
1780 c->always_on, in constraint_flags_read_file()
1781 c->boot_on, in constraint_flags_read_file()
1782 c->apply_uV, in constraint_flags_read_file()
1783 c->ramp_disable, in constraint_flags_read_file()
1784 c->soft_start, in constraint_flags_read_file()
1785 c->pull_down, in constraint_flags_read_file()
1786 c->over_current_protection); in constraint_flags_read_file()
1813 lockdep_assert_held_once(&rdev->mutex.base); in create_regulator()
1819 size = snprintf(buf, REG_STR_SIZE, "%s-%s", in create_regulator()
1820 dev->kobj.name, supply_name); in create_regulator()
1839 regulator->rdev = rdev; in create_regulator()
1840 regulator->supply_name = supply_name; in create_regulator()
1842 list_add(®ulator->list, &rdev->consumer_list); in create_regulator()
1845 regulator->dev = dev; in create_regulator()
1848 err = sysfs_create_link_nowarn(&rdev->dev.kobj, &dev->kobj, in create_regulator()
1852 dev->kobj.name, ERR_PTR(err)); in create_regulator()
1853 /* non-fatal */ in create_regulator()
1857 if (err != -EEXIST) { in create_regulator()
1858 regulator->debugfs = debugfs_create_dir(supply_name, rdev->debugfs); in create_regulator()
1859 if (IS_ERR(regulator->debugfs)) { in create_regulator()
1861 regulator->debugfs = NULL; in create_regulator()
1865 if (regulator->debugfs) { in create_regulator()
1866 debugfs_create_u32("uA_load", 0444, regulator->debugfs, in create_regulator()
1867 ®ulator->uA_load); in create_regulator()
1868 debugfs_create_u32("min_uV", 0444, regulator->debugfs, in create_regulator()
1869 ®ulator->voltage[PM_SUSPEND_ON].min_uV); in create_regulator()
1870 debugfs_create_u32("max_uV", 0444, regulator->debugfs, in create_regulator()
1871 ®ulator->voltage[PM_SUSPEND_ON].max_uV); in create_regulator()
1872 debugfs_create_file("constraint_flags", 0444, regulator->debugfs, in create_regulator()
1877 * Check now if the regulator is an always on regulator - if in create_regulator()
1883 regulator->always_on = true; in create_regulator()
1890 if (rdev->constraints && rdev->constraints->enable_time) in _regulator_get_enable_time()
1891 return rdev->constraints->enable_time; in _regulator_get_enable_time()
1892 if (rdev->desc->ops->enable_time) in _regulator_get_enable_time()
1893 return rdev->desc->ops->enable_time(rdev); in _regulator_get_enable_time()
1894 return rdev->desc->enable_time; in _regulator_get_enable_time()
1903 if (map->src_dev == dev && strcmp(map->src_supply, supply) == 0) in regulator_find_supply_alias()
1916 *supply, map->alias_supply, in regulator_supply_alias()
1917 dev_name(map->alias_dev)); in regulator_supply_alias()
1918 *dev = map->alias_dev; in regulator_supply_alias()
1919 *supply = map->alias_supply; in regulator_supply_alias()
1940 * regulator_dev_lookup - lookup a regulator device.
1950 * -%ENODEV if lookup fails permanently, -%EPROBE_DEFER if lookup could succeed
1967 if (PTR_ERR(r) == -EPROBE_DEFER) in regulator_dev_lookup()
1970 if (PTR_ERR(r) == -ENODEV) in regulator_dev_lookup()
1974 /* if not found, try doing it non-dt way */ in regulator_dev_lookup()
1981 if (map->dev_name && in regulator_dev_lookup()
1982 (!devname || strcmp(map->dev_name, devname))) in regulator_dev_lookup()
1985 if (strcmp(map->supply, supply) == 0 && in regulator_dev_lookup()
1986 get_device(&map->regulator->dev)) { in regulator_dev_lookup()
1987 r = map->regulator; in regulator_dev_lookup()
2000 return ERR_PTR(-ENODEV); in regulator_dev_lookup()
2006 struct device *dev = rdev->dev.parent; in regulator_resolve_supply()
2011 if (!rdev->supply_name) in regulator_resolve_supply()
2014 /* Supply already resolved? (fast-path without locking contention) */ in regulator_resolve_supply()
2015 if (rdev->supply) in regulator_resolve_supply()
2018 r = regulator_dev_lookup(dev, rdev->supply_name); in regulator_resolve_supply()
2023 if (ret == -EPROBE_DEFER) in regulator_resolve_supply()
2028 get_device(&r->dev); in regulator_resolve_supply()
2030 dev_err(dev, "Failed to resolve %s-supply for %s\n", in regulator_resolve_supply()
2031 rdev->supply_name, rdev->desc->name); in regulator_resolve_supply()
2032 ret = -EPROBE_DEFER; in regulator_resolve_supply()
2039 rdev->desc->name, rdev->supply_name); in regulator_resolve_supply()
2041 ret = -EINVAL; in regulator_resolve_supply()
2045 get_device(&r->dev); in regulator_resolve_supply()
2054 if (r->dev.parent && r->dev.parent != rdev->dev.parent) { in regulator_resolve_supply()
2055 if (!device_is_bound(r->dev.parent)) { in regulator_resolve_supply()
2056 put_device(&r->dev); in regulator_resolve_supply()
2057 ret = -EPROBE_DEFER; in regulator_resolve_supply()
2065 put_device(&r->dev); in regulator_resolve_supply()
2070 * Recheck rdev->supply with rdev->mutex lock held to avoid a race in regulator_resolve_supply()
2071 * between rdev->supply null check and setting rdev->supply in in regulator_resolve_supply()
2077 if (rdev->supply) { in regulator_resolve_supply()
2079 put_device(&r->dev); in regulator_resolve_supply()
2086 put_device(&r->dev); in regulator_resolve_supply()
2097 if (rdev->use_count) { in regulator_resolve_supply()
2098 ret = regulator_enable(rdev->supply); in regulator_resolve_supply()
2100 _regulator_put(rdev->supply); in regulator_resolve_supply()
2101 rdev->supply = NULL; in regulator_resolve_supply()
2110 /* common pre-checks for regulator requests */
2116 return -EINVAL; in _regulator_get_common_check()
2121 return -EINVAL; in _regulator_get_common_check()
2128 * _regulator_get_common - Common code for regulator requests
2152 * than -ENODEV our job here is done, we simply return it. in _regulator_get_common()
2154 if (ret != -ENODEV) in _regulator_get_common()
2160 return ERR_PTR(-ENODEV); in _regulator_get_common()
2172 get_device(&rdev->dev); in _regulator_get_common()
2181 return ERR_PTR(-ENODEV); in _regulator_get_common()
2185 if (rdev->exclusive) { in _regulator_get_common()
2186 regulator = ERR_PTR(-EPERM); in _regulator_get_common()
2187 put_device(&rdev->dev); in _regulator_get_common()
2191 if (get_type == EXCLUSIVE_GET && rdev->open_count) { in _regulator_get_common()
2192 regulator = ERR_PTR(-EBUSY); in _regulator_get_common()
2193 put_device(&rdev->dev); in _regulator_get_common()
2198 ret = (rdev->coupling_desc.n_resolved != rdev->coupling_desc.n_coupled); in _regulator_get_common()
2202 regulator = ERR_PTR(-EPROBE_DEFER); in _regulator_get_common()
2203 put_device(&rdev->dev); in _regulator_get_common()
2210 put_device(&rdev->dev); in _regulator_get_common()
2214 if (!try_module_get(rdev->owner)) { in _regulator_get_common()
2215 regulator = ERR_PTR(-EPROBE_DEFER); in _regulator_get_common()
2216 put_device(&rdev->dev); in _regulator_get_common()
2224 regulator = ERR_PTR(-ENOMEM); in _regulator_get_common()
2225 module_put(rdev->owner); in _regulator_get_common()
2226 put_device(&rdev->dev); in _regulator_get_common()
2230 rdev->open_count++; in _regulator_get_common()
2232 rdev->exclusive = 1; in _regulator_get_common()
2236 rdev->use_count = 1; in _regulator_get_common()
2237 regulator->enable_count = 1; in _regulator_get_common()
2240 if (rdev->supply) { in _regulator_get_common()
2241 ret = regulator_enable(rdev->supply); in _regulator_get_common()
2244 module_put(rdev->owner); in _regulator_get_common()
2245 put_device(&rdev->dev); in _regulator_get_common()
2250 rdev->use_count = 0; in _regulator_get_common()
2251 regulator->enable_count = 0; in _regulator_get_common()
2255 link = device_link_add(dev, &rdev->dev, DL_FLAG_STATELESS); in _regulator_get_common()
2257 regulator->device_link = true; in _regulator_get_common()
2278 * regulator_get - lookup and obtain a reference to a regulator.
2297 * regulator_get_exclusive - obtain exclusive access to a regulator.
2325 * regulator_get_optional - obtain optional access to a regulator.
2352 struct regulator_dev *rdev = regulator->rdev; in destroy_regulator()
2354 debugfs_remove_recursive(regulator->debugfs); in destroy_regulator()
2356 if (regulator->dev) { in destroy_regulator()
2357 if (regulator->device_link) in destroy_regulator()
2358 device_link_remove(regulator->dev, &rdev->dev); in destroy_regulator()
2361 sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name); in destroy_regulator()
2365 list_del(®ulator->list); in destroy_regulator()
2367 rdev->open_count--; in destroy_regulator()
2368 rdev->exclusive = 0; in destroy_regulator()
2371 kfree_const(regulator->supply_name); in destroy_regulator()
2386 WARN_ON(regulator->enable_count); in _regulator_put()
2388 rdev = regulator->rdev; in _regulator_put()
2392 module_put(rdev->owner); in _regulator_put()
2393 put_device(&rdev->dev); in _regulator_put()
2397 * regulator_put - "free" the regulator source
2413 * regulator_register_supply_alias - Provide device alias for supply lookup
2434 return -EEXIST; in regulator_register_supply_alias()
2438 return -ENOMEM; in regulator_register_supply_alias()
2440 map->src_dev = dev; in regulator_register_supply_alias()
2441 map->src_supply = id; in regulator_register_supply_alias()
2442 map->alias_dev = alias_dev; in regulator_register_supply_alias()
2443 map->alias_supply = alias_id; in regulator_register_supply_alias()
2445 list_add(&map->list, ®ulator_supply_alias_list); in regulator_register_supply_alias()
2447 pr_info("Adding alias for supply %s,%s -> %s,%s\n", in regulator_register_supply_alias()
2455 * regulator_unregister_supply_alias - Remove device alias
2468 list_del(&map->list); in regulator_unregister_supply_alias()
2475 * regulator_bulk_register_supply_alias - register multiple aliases
2511 "Failed to create supply alias %s,%s -> %s,%s\n", in regulator_bulk_register_supply_alias()
2514 while (--i >= 0) in regulator_bulk_register_supply_alias()
2522 * regulator_bulk_unregister_supply_alias - unregister multiple aliases
2550 gpiod = config->ena_gpiod; in regulator_ena_gpio_request()
2556 if (pin->gpiod == gpiod) { in regulator_ena_gpio_request()
2564 return -ENOMEM; in regulator_ena_gpio_request()
2570 pin->gpiod = gpiod; in regulator_ena_gpio_request()
2571 list_add(&pin->list, ®ulator_ena_gpio_list); in regulator_ena_gpio_request()
2574 pin->request_count++; in regulator_ena_gpio_request()
2575 rdev->ena_pin = pin; in regulator_ena_gpio_request()
2587 if (!rdev->ena_pin) in regulator_ena_gpio_free()
2592 if (pin != rdev->ena_pin) in regulator_ena_gpio_free()
2595 if (--pin->request_count) in regulator_ena_gpio_free()
2598 gpiod_put(pin->gpiod); in regulator_ena_gpio_free()
2599 list_del(&pin->list); in regulator_ena_gpio_free()
2604 rdev->ena_pin = NULL; in regulator_ena_gpio_free()
2608 * regulator_ena_gpio_ctrl - balance enable_count of each GPIO and actual GPIO pin control
2619 struct regulator_enable_gpio *pin = rdev->ena_pin; in regulator_ena_gpio_ctrl()
2622 return -EINVAL; in regulator_ena_gpio_ctrl()
2626 if (pin->enable_count == 0) in regulator_ena_gpio_ctrl()
2627 gpiod_set_value_cansleep(pin->gpiod, 1); in regulator_ena_gpio_ctrl()
2629 pin->enable_count++; in regulator_ena_gpio_ctrl()
2631 if (pin->enable_count > 1) { in regulator_ena_gpio_ctrl()
2632 pin->enable_count--; in regulator_ena_gpio_ctrl()
2637 if (pin->enable_count <= 1) { in regulator_ena_gpio_ctrl()
2638 gpiod_set_value_cansleep(pin->gpiod, 0); in regulator_ena_gpio_ctrl()
2639 pin->enable_count = 0; in regulator_ena_gpio_ctrl()
2647 * _regulator_check_status_enabled - check if regulator status can be
2652 * * 1 - if status shows regulator is in enabled state
2653 * * 0 - if not enabled state
2654 * * Error Value - as received from ops->get_status()
2658 int ret = rdev->desc->ops->get_status(rdev); in _regulator_check_status_enabled()
2690 if (rdev->desc->off_on_delay) { in _regulator_do_enable()
2694 ktime_t end = ktime_add_us(rdev->last_off, rdev->desc->off_on_delay); in _regulator_do_enable()
2701 if (rdev->ena_pin) { in _regulator_do_enable()
2702 if (!rdev->ena_gpio_state) { in _regulator_do_enable()
2706 rdev->ena_gpio_state = 1; in _regulator_do_enable()
2708 } else if (rdev->desc->ops->enable) { in _regulator_do_enable()
2709 ret = rdev->desc->ops->enable(rdev); in _regulator_do_enable()
2713 return -EINVAL; in _regulator_do_enable()
2726 * return -ETIMEDOUT. in _regulator_do_enable()
2728 if (rdev->desc->poll_enabled_time) { in _regulator_do_enable()
2732 fsleep(rdev->desc->poll_enabled_time); in _regulator_do_enable()
2734 if (rdev->desc->ops->get_status) { in _regulator_do_enable()
2740 } else if (rdev->desc->ops->is_enabled(rdev)) in _regulator_do_enable()
2743 time_remaining -= rdev->desc->poll_enabled_time; in _regulator_do_enable()
2748 return -ETIMEDOUT; in _regulator_do_enable()
2760 * _regulator_handle_consumer_enable - handle that a consumer enabled
2782 struct regulator_dev *rdev = regulator->rdev; in _regulator_handle_consumer_enable()
2784 lockdep_assert_held_once(&rdev->mutex.base); in _regulator_handle_consumer_enable()
2786 regulator->enable_count++; in _regulator_handle_consumer_enable()
2787 if (regulator->uA_load && regulator->enable_count == 1) { in _regulator_handle_consumer_enable()
2790 regulator->enable_count--; in _regulator_handle_consumer_enable()
2798 * _regulator_handle_consumer_disable - handle that a consumer disabled
2807 struct regulator_dev *rdev = regulator->rdev; in _regulator_handle_consumer_disable()
2809 lockdep_assert_held_once(&rdev->mutex.base); in _regulator_handle_consumer_disable()
2811 if (!regulator->enable_count) { in _regulator_handle_consumer_disable()
2813 return -EINVAL; in _regulator_handle_consumer_disable()
2816 regulator->enable_count--; in _regulator_handle_consumer_disable()
2817 if (regulator->uA_load && regulator->enable_count == 0) in _regulator_handle_consumer_disable()
2826 struct regulator_dev *rdev = regulator->rdev; in _regulator_enable()
2829 lockdep_assert_held_once(&rdev->mutex.base); in _regulator_enable()
2831 if (rdev->use_count == 0 && rdev->supply) { in _regulator_enable()
2832 ret = _regulator_enable(rdev->supply); in _regulator_enable()
2838 if (rdev->coupling_desc.n_coupled > 1) { in _regulator_enable()
2848 if (rdev->use_count == 0) { in _regulator_enable()
2854 if (ret == -EINVAL || ret == 0) { in _regulator_enable()
2857 ret = -EPERM; in _regulator_enable()
2871 /* Fallthrough on positive return values - already enabled */ in _regulator_enable()
2874 if (regulator->enable_count == 1) in _regulator_enable()
2875 rdev->use_count++; in _regulator_enable()
2883 if (rdev->use_count == 0 && rdev->supply) in _regulator_enable()
2884 _regulator_disable(rdev->supply); in _regulator_enable()
2890 * regulator_enable - enable regulator output
2904 struct regulator_dev *rdev = regulator->rdev; in regulator_enable()
2922 if (rdev->ena_pin) { in _regulator_do_disable()
2923 if (rdev->ena_gpio_state) { in _regulator_do_disable()
2927 rdev->ena_gpio_state = 0; in _regulator_do_disable()
2930 } else if (rdev->desc->ops->disable) { in _regulator_do_disable()
2931 ret = rdev->desc->ops->disable(rdev); in _regulator_do_disable()
2936 if (rdev->desc->off_on_delay) in _regulator_do_disable()
2937 rdev->last_off = ktime_get_boottime(); in _regulator_do_disable()
2947 struct regulator_dev *rdev = regulator->rdev; in _regulator_disable()
2950 lockdep_assert_held_once(&rdev->mutex.base); in _regulator_disable()
2952 if (WARN(regulator->enable_count == 0, in _regulator_disable()
2954 return -EIO; in _regulator_disable()
2956 if (regulator->enable_count == 1) { in _regulator_disable()
2959 if (rdev->use_count == 1 && in _regulator_disable()
2960 (rdev->constraints && !rdev->constraints->always_on)) { in _regulator_disable()
2968 return -EINVAL; in _regulator_disable()
2982 rdev->use_count = 0; in _regulator_disable()
2983 } else if (rdev->use_count > 1) { in _regulator_disable()
2984 rdev->use_count--; in _regulator_disable()
2991 if (ret == 0 && rdev->coupling_desc.n_coupled > 1) in _regulator_disable()
2994 if (ret == 0 && rdev->use_count == 0 && rdev->supply) in _regulator_disable()
2995 ret = _regulator_disable(rdev->supply); in _regulator_disable()
3001 * regulator_disable - disable regulator output
3016 struct regulator_dev *rdev = regulator->rdev; in regulator_disable()
3033 lockdep_assert_held_once(&rdev->mutex.base); in _regulator_force_disable()
3038 return -EINVAL; in _regulator_force_disable()
3055 * regulator_force_disable - force disable regulator output
3067 struct regulator_dev *rdev = regulator->rdev; in regulator_force_disable()
3073 ret = _regulator_force_disable(regulator->rdev); in regulator_force_disable()
3075 if (rdev->coupling_desc.n_coupled > 1) in regulator_force_disable()
3078 if (regulator->uA_load) { in regulator_force_disable()
3079 regulator->uA_load = 0; in regulator_force_disable()
3083 if (rdev->use_count != 0 && rdev->supply) in regulator_force_disable()
3084 _regulator_disable(rdev->supply); in regulator_force_disable()
3109 cancel_delayed_work(&rdev->disable_work); in regulator_disable_work()
3111 list_for_each_entry(regulator, &rdev->consumer_list, list) { in regulator_disable_work()
3112 count = regulator->deferred_disables; in regulator_disable_work()
3118 regulator->deferred_disables = 0; in regulator_disable_work()
3129 if (rdev->coupling_desc.n_coupled > 1) in regulator_disable_work()
3136 * regulator_disable_deferred - disable regulator output with delay
3151 struct regulator_dev *rdev = regulator->rdev; in regulator_disable_deferred()
3157 regulator->deferred_disables++; in regulator_disable_deferred()
3158 mod_delayed_work(system_power_efficient_wq, &rdev->disable_work, in regulator_disable_deferred()
3169 if (rdev->ena_pin) in _regulator_is_enabled()
3170 return rdev->ena_gpio_state; in _regulator_is_enabled()
3173 if (!rdev->desc->ops->is_enabled) in _regulator_is_enabled()
3176 return rdev->desc->ops->is_enabled(rdev); in _regulator_is_enabled()
3182 const struct regulator_ops *ops = rdev->desc->ops; in _regulator_list_voltage()
3185 if (rdev->desc->fixed_uV && rdev->desc->n_voltages == 1 && !selector) in _regulator_list_voltage()
3186 return rdev->desc->fixed_uV; in _regulator_list_voltage()
3188 if (ops->list_voltage) { in _regulator_list_voltage()
3189 if (selector >= rdev->desc->n_voltages) in _regulator_list_voltage()
3190 return -EINVAL; in _regulator_list_voltage()
3191 if (selector < rdev->desc->linear_min_sel) in _regulator_list_voltage()
3195 ret = ops->list_voltage(rdev, selector); in _regulator_list_voltage()
3198 } else if (rdev->is_switch && rdev->supply) { in _regulator_list_voltage()
3199 ret = _regulator_list_voltage(rdev->supply->rdev, in _regulator_list_voltage()
3202 return -EINVAL; in _regulator_list_voltage()
3206 if (ret < rdev->constraints->min_uV) in _regulator_list_voltage()
3208 else if (ret > rdev->constraints->max_uV) in _regulator_list_voltage()
3216 * regulator_is_enabled - is the regulator output enabled
3231 if (regulator->always_on) in regulator_is_enabled()
3234 regulator_lock(regulator->rdev); in regulator_is_enabled()
3235 ret = _regulator_is_enabled(regulator->rdev); in regulator_is_enabled()
3236 regulator_unlock(regulator->rdev); in regulator_is_enabled()
3243 * regulator_count_voltages - count regulator_list_voltage() selectors
3253 struct regulator_dev *rdev = regulator->rdev; in regulator_count_voltages()
3255 if (rdev->desc->n_voltages) in regulator_count_voltages()
3256 return rdev->desc->n_voltages; in regulator_count_voltages()
3258 if (!rdev->is_switch || !rdev->supply) in regulator_count_voltages()
3259 return -EINVAL; in regulator_count_voltages()
3261 return regulator_count_voltages(rdev->supply); in regulator_count_voltages()
3266 * regulator_list_voltage - enumerate supported voltages
3277 return _regulator_list_voltage(regulator->rdev, selector, 1); in regulator_list_voltage()
3282 * regulator_get_regmap - get the regulator's register map
3286 * encoded -%EOPNOTSUPP if @regulator doesn't use regmap.
3290 struct regmap *map = regulator->rdev->regmap; in regulator_get_regmap()
3292 return map ? map : ERR_PTR(-EOPNOTSUPP); in regulator_get_regmap()
3297 * regulator_get_hardware_vsel_register - get the HW voltage selector register
3303 * regulator voltage. This might be useful when configuring voltage-scaling
3307 * Return: 0 on success, or -%EOPNOTSUPP if the regulator does not support
3317 struct regulator_dev *rdev = regulator->rdev; in regulator_get_hardware_vsel_register()
3318 const struct regulator_ops *ops = rdev->desc->ops; in regulator_get_hardware_vsel_register()
3320 if (ops->set_voltage_sel != regulator_set_voltage_sel_regmap) in regulator_get_hardware_vsel_register()
3321 return -EOPNOTSUPP; in regulator_get_hardware_vsel_register()
3323 *vsel_reg = rdev->desc->vsel_reg; in regulator_get_hardware_vsel_register()
3324 *vsel_mask = rdev->desc->vsel_mask; in regulator_get_hardware_vsel_register()
3331 * regulator_list_hardware_vsel - get the HW-specific register value for a selector
3335 * Converts the selector to a hardware-specific voltage selector that can be
3339 * Return: 0 on success, -%EINVAL if the selector is outside the supported
3340 * range, or -%EOPNOTSUPP if the regulator does not support voltage
3346 struct regulator_dev *rdev = regulator->rdev; in regulator_list_hardware_vsel()
3347 const struct regulator_ops *ops = rdev->desc->ops; in regulator_list_hardware_vsel()
3349 if (selector >= rdev->desc->n_voltages) in regulator_list_hardware_vsel()
3350 return -EINVAL; in regulator_list_hardware_vsel()
3351 if (selector < rdev->desc->linear_min_sel) in regulator_list_hardware_vsel()
3353 if (ops->set_voltage_sel != regulator_set_voltage_sel_regmap) in regulator_list_hardware_vsel()
3354 return -EOPNOTSUPP; in regulator_list_hardware_vsel()
3361 * regulator_hardware_enable - access the HW for enable/disable regulator
3372 struct regulator_dev *rdev = regulator->rdev; in regulator_hardware_enable()
3373 const struct regulator_ops *ops = rdev->desc->ops; in regulator_hardware_enable()
3374 int ret = -EOPNOTSUPP; in regulator_hardware_enable()
3376 if (!rdev->exclusive || !ops || !ops->enable || !ops->disable) in regulator_hardware_enable()
3380 ret = ops->enable(rdev); in regulator_hardware_enable()
3382 ret = ops->disable(rdev); in regulator_hardware_enable()
3389 * regulator_get_linear_step - return the voltage step size between VSEL values
3397 struct regulator_dev *rdev = regulator->rdev; in regulator_get_linear_step()
3399 return rdev->desc->uV_step; in regulator_get_linear_step()
3404 * regulator_is_supported_voltage - check if a voltage range can be supported
3407 * @min_uV: Minimum required voltage in uV.
3408 * @max_uV: Maximum required voltage in uV.
3417 struct regulator_dev *rdev = regulator->rdev; in regulator_is_supported_voltage()
3430 if (rdev->desc->continuous_voltage_range) in regulator_is_supported_voltage()
3431 return min_uV >= rdev->constraints->min_uV && in regulator_is_supported_voltage()
3432 max_uV <= rdev->constraints->max_uV; in regulator_is_supported_voltage()
3453 const struct regulator_desc *desc = rdev->desc; in regulator_map_voltage()
3455 if (desc->ops->map_voltage) in regulator_map_voltage()
3456 return desc->ops->map_voltage(rdev, min_uV, max_uV); in regulator_map_voltage()
3458 if (desc->ops->list_voltage == regulator_list_voltage_linear) in regulator_map_voltage()
3461 if (desc->ops->list_voltage == regulator_list_voltage_linear_range) in regulator_map_voltage()
3464 if (desc->ops->list_voltage == in regulator_map_voltage()
3485 return -EINVAL; in _regulator_call_set_voltage()
3487 ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV, selector); in _regulator_call_set_voltage()
3498 int uV, unsigned selector) in _regulator_call_set_voltage_sel() argument
3504 data.min_uV = uV; in _regulator_call_set_voltage_sel()
3505 data.max_uV = uV; in _regulator_call_set_voltage_sel()
3509 return -EINVAL; in _regulator_call_set_voltage_sel()
3511 ret = rdev->desc->ops->set_voltage_sel(rdev, selector); in _regulator_call_set_voltage_sel()
3522 int uV, int new_selector) in _regulator_set_voltage_sel_step() argument
3524 const struct regulator_ops *ops = rdev->desc->ops; in _regulator_set_voltage_sel_step()
3531 if (!ops->get_voltage_sel) in _regulator_set_voltage_sel_step()
3532 return -EINVAL; in _regulator_set_voltage_sel_step()
3534 old_sel = ops->get_voltage_sel(rdev); in _regulator_set_voltage_sel_step()
3538 diff = new_selector - old_sel; in _regulator_set_voltage_sel_step()
3544 for (curr_sel = old_sel + rdev->desc->vsel_step; in _regulator_set_voltage_sel_step()
3546 curr_sel += rdev->desc->vsel_step) { in _regulator_set_voltage_sel_step()
3553 ret = ops->set_voltage_sel(rdev, curr_sel); in _regulator_set_voltage_sel_step()
3559 for (curr_sel = old_sel - rdev->desc->vsel_step; in _regulator_set_voltage_sel_step()
3561 curr_sel -= rdev->desc->vsel_step) { in _regulator_set_voltage_sel_step()
3562 ret = ops->set_voltage_sel(rdev, curr_sel); in _regulator_set_voltage_sel_step()
3570 return _regulator_call_set_voltage_sel(rdev, uV, new_selector); in _regulator_set_voltage_sel_step()
3577 (void)ops->set_voltage_sel(rdev, old_sel); in _regulator_set_voltage_sel_step()
3586 if (rdev->constraints->ramp_delay) in _regulator_set_voltage_time()
3587 ramp_delay = rdev->constraints->ramp_delay; in _regulator_set_voltage_time()
3588 else if (rdev->desc->ramp_delay) in _regulator_set_voltage_time()
3589 ramp_delay = rdev->desc->ramp_delay; in _regulator_set_voltage_time()
3590 else if (rdev->constraints->settling_time) in _regulator_set_voltage_time()
3591 return rdev->constraints->settling_time; in _regulator_set_voltage_time()
3592 else if (rdev->constraints->settling_time_up && in _regulator_set_voltage_time()
3594 return rdev->constraints->settling_time_up; in _regulator_set_voltage_time()
3595 else if (rdev->constraints->settling_time_down && in _regulator_set_voltage_time()
3597 return rdev->constraints->settling_time_down; in _regulator_set_voltage_time()
3602 return DIV_ROUND_UP(abs(new_uV - old_uV), ramp_delay); in _regulator_set_voltage_time()
3612 int old_selector = -1; in _regulator_do_set_voltage()
3613 const struct regulator_ops *ops = rdev->desc->ops; in _regulator_do_set_voltage()
3618 min_uV += rdev->constraints->uV_offset; in _regulator_do_set_voltage()
3619 max_uV += rdev->constraints->uV_offset; in _regulator_do_set_voltage()
3626 ops->set_voltage_time_sel && ops->get_voltage_sel) { in _regulator_do_set_voltage()
3627 old_selector = ops->get_voltage_sel(rdev); in _regulator_do_set_voltage()
3632 if (ops->set_voltage) { in _regulator_do_set_voltage()
3637 if (ops->list_voltage) in _regulator_do_set_voltage()
3638 best_val = ops->list_voltage(rdev, in _regulator_do_set_voltage()
3644 } else if (ops->set_voltage_sel) { in _regulator_do_set_voltage()
3647 best_val = ops->list_voltage(rdev, ret); in _regulator_do_set_voltage()
3652 else if (rdev->desc->vsel_step) in _regulator_do_set_voltage()
3659 ret = -EINVAL; in _regulator_do_set_voltage()
3663 ret = -EINVAL; in _regulator_do_set_voltage()
3669 if (ops->set_voltage_time_sel) { in _regulator_do_set_voltage()
3675 delay = ops->set_voltage_time_sel(rdev, old_selector, in _regulator_do_set_voltage()
3679 if (ops->set_voltage_time) in _regulator_do_set_voltage()
3680 delay = ops->set_voltage_time(rdev, old_uV, in _regulator_do_set_voltage()
3714 int uV, sel; in _regulator_do_set_suspend_voltage() local
3718 return -EINVAL; in _regulator_do_set_suspend_voltage()
3720 if (min_uV < rstate->min_uV) in _regulator_do_set_suspend_voltage()
3721 min_uV = rstate->min_uV; in _regulator_do_set_suspend_voltage()
3722 if (max_uV > rstate->max_uV) in _regulator_do_set_suspend_voltage()
3723 max_uV = rstate->max_uV; in _regulator_do_set_suspend_voltage()
3729 uV = rdev->desc->ops->list_voltage(rdev, sel); in _regulator_do_set_suspend_voltage()
3730 if (uV >= min_uV && uV <= max_uV) in _regulator_do_set_suspend_voltage()
3731 rstate->uV = uV; in _regulator_do_set_suspend_voltage()
3740 struct regulator_dev *rdev = regulator->rdev; in regulator_set_voltage_unlocked()
3741 struct regulator_voltage *voltage = ®ulator->voltage[state]; in regulator_set_voltage_unlocked()
3750 if (voltage->min_uV == min_uV && voltage->max_uV == max_uV) in regulator_set_voltage_unlocked()
3760 voltage->min_uV = min_uV; in regulator_set_voltage_unlocked()
3761 voltage->max_uV = max_uV; in regulator_set_voltage_unlocked()
3767 if (!rdev->desc->ops->set_voltage && in regulator_set_voltage_unlocked()
3768 !rdev->desc->ops->set_voltage_sel) { in regulator_set_voltage_unlocked()
3769 ret = -EINVAL; in regulator_set_voltage_unlocked()
3779 old_min_uV = voltage->min_uV; in regulator_set_voltage_unlocked()
3780 old_max_uV = voltage->max_uV; in regulator_set_voltage_unlocked()
3781 voltage->min_uV = min_uV; in regulator_set_voltage_unlocked()
3782 voltage->max_uV = max_uV; in regulator_set_voltage_unlocked()
3787 voltage->min_uV = old_min_uV; in regulator_set_voltage_unlocked()
3788 voltage->max_uV = old_max_uV; in regulator_set_voltage_unlocked()
3802 if (rdev->supply && in regulator_set_voltage_rdev()
3803 regulator_ops_is_valid(rdev->supply->rdev, in regulator_set_voltage_rdev()
3805 (rdev->desc->min_dropout_uV || !(rdev->desc->ops->get_voltage || in regulator_set_voltage_rdev()
3806 rdev->desc->ops->get_voltage_sel))) { in regulator_set_voltage_rdev()
3822 best_supply_uV += rdev->desc->min_dropout_uV; in regulator_set_voltage_rdev()
3824 current_supply_uV = regulator_get_voltage_rdev(rdev->supply->rdev); in regulator_set_voltage_rdev()
3830 supply_change_uV = best_supply_uV - current_supply_uV; in regulator_set_voltage_rdev()
3834 ret = regulator_set_voltage_unlocked(rdev->supply, in regulator_set_voltage_rdev()
3837 dev_err(&rdev->dev, "Failed to increase supply voltage: %pe\n", in regulator_set_voltage_rdev()
3852 ret = regulator_set_voltage_unlocked(rdev->supply, in regulator_set_voltage_rdev()
3855 dev_warn(&rdev->dev, "Failed to decrease supply voltage: %pe\n", in regulator_set_voltage_rdev()
3869 struct regulation_constraints *constraints = rdev->constraints; in regulator_limit_voltage_step()
3872 if (!constraints->max_uV_step || !_regulator_is_enabled(rdev)) in regulator_limit_voltage_step()
3882 if (abs(*current_uV - *min_uV) <= constraints->max_uV_step) in regulator_limit_voltage_step()
3887 *min_uV = min(*current_uV + constraints->max_uV_step, in regulator_limit_voltage_step()
3890 *min_uV = max(*current_uV - constraints->max_uV_step, in regulator_limit_voltage_step()
3902 struct coupling_desc *c_desc = &rdev->coupling_desc; in regulator_get_optimal_voltage()
3903 struct regulator_dev **c_rdevs = c_desc->coupled_rdevs; in regulator_get_optimal_voltage()
3904 struct regulation_constraints *constraints = rdev->constraints; in regulator_get_optimal_voltage()
3911 *current_uV = -1; in regulator_get_optimal_voltage()
3922 desired_min_uV = constraints->min_uV; in regulator_get_optimal_voltage()
3923 desired_max_uV = constraints->max_uV; in regulator_get_optimal_voltage()
3941 lockdep_assert_held_once(&c_rdevs[i]->mutex.base); in regulator_get_optimal_voltage()
3961 max_spread = constraints->max_spread[0]; in regulator_get_optimal_voltage()
3968 target_uV = max(desired_min_uV, highest_min_uV - max_spread); in regulator_get_optimal_voltage()
3996 possible_uV = max(target_uV, max_current_uV - max_spread); in regulator_get_optimal_voltage()
4001 return -EINVAL; in regulator_get_optimal_voltage()
4019 if (n_coupled > 1 && *current_uV == -1) { in regulator_get_optimal_voltage()
4043 struct coupling_desc *c_desc = &rdev->coupling_desc; in regulator_do_balance_voltage()
4049 c_rdevs = c_desc->coupled_rdevs; in regulator_do_balance_voltage()
4050 n_coupled = skip_coupled ? 1 : c_desc->n_coupled; in regulator_do_balance_voltage()
4071 * i-th regulator at the moment without violating in regulator_do_balance_voltage()
4088 delta = abs(optimal_uV - current_uV); in regulator_do_balance_voltage()
4124 struct coupling_desc *c_desc = &rdev->coupling_desc; in regulator_balance_voltage()
4125 struct regulator_coupler *coupler = c_desc->coupler; in regulator_balance_voltage()
4135 if (c_desc->n_resolved < c_desc->n_coupled) { in regulator_balance_voltage()
4137 return -EPERM; in regulator_balance_voltage()
4141 if (coupler && coupler->balance_voltage) in regulator_balance_voltage()
4142 return coupler->balance_voltage(coupler, rdev, state); in regulator_balance_voltage()
4148 * regulator_set_voltage - set regulator output voltage
4150 * @min_uV: Minimum required voltage in uV
4151 * @max_uV: Maximum acceptable voltage in uV
4172 regulator_lock_dependent(regulator->rdev, &ww_ctx); in regulator_set_voltage()
4177 regulator_unlock_dependent(regulator->rdev, &ww_ctx); in regulator_set_voltage()
4190 return -EINVAL; in regulator_suspend_toggle()
4192 if (!rstate->changeable) in regulator_suspend_toggle()
4193 return -EPERM; in regulator_suspend_toggle()
4195 rstate->enabled = (en) ? ENABLE_IN_SUSPEND : DISABLE_IN_SUSPEND; in regulator_suspend_toggle()
4217 list_for_each_entry(regulator, &rdev->consumer_list, list) { in regulator_suspend_disable()
4218 voltage = ®ulator->voltage[state]; in regulator_suspend_disable()
4219 if (voltage->min_uV || voltage->max_uV) in regulator_suspend_disable()
4231 struct regulator_dev *rdev = regulator->rdev; in _regulator_set_suspend_voltage()
4236 return -EINVAL; in _regulator_set_suspend_voltage()
4238 if (rstate->min_uV == rstate->max_uV) { in _regulator_set_suspend_voltage()
4240 return -EPERM; in _regulator_set_suspend_voltage()
4254 return -EINVAL; in regulator_set_suspend_voltage()
4256 regulator_lock_dependent(regulator->rdev, &ww_ctx); in regulator_set_suspend_voltage()
4261 regulator_unlock_dependent(regulator->rdev, &ww_ctx); in regulator_set_suspend_voltage()
4268 * regulator_set_voltage_time - get raise/fall time
4282 struct regulator_dev *rdev = regulator->rdev; in regulator_set_voltage_time()
4283 const struct regulator_ops *ops = rdev->desc->ops; in regulator_set_voltage_time()
4284 int old_sel = -1; in regulator_set_voltage_time()
4285 int new_sel = -1; in regulator_set_voltage_time()
4289 if (ops->set_voltage_time) in regulator_set_voltage_time()
4290 return ops->set_voltage_time(rdev, old_uV, new_uV); in regulator_set_voltage_time()
4291 else if (!ops->set_voltage_time_sel) in regulator_set_voltage_time()
4295 if (!ops->list_voltage || !rdev->desc->n_voltages) in regulator_set_voltage_time()
4296 return -EINVAL; in regulator_set_voltage_time()
4298 for (i = 0; i < rdev->desc->n_voltages; i++) { in regulator_set_voltage_time()
4300 if (i < rdev->desc->linear_min_sel) in regulator_set_voltage_time()
4308 return -EINVAL; in regulator_set_voltage_time()
4318 return -EINVAL; in regulator_set_voltage_time()
4320 return ops->set_voltage_time_sel(rdev, old_sel, new_sel); in regulator_set_voltage_time()
4325 * regulator_set_voltage_time_sel - get raise/fall time
4345 if (!rdev->desc->ops->list_voltage) in regulator_set_voltage_time_sel()
4346 return -EINVAL; in regulator_set_voltage_time_sel()
4348 old_volt = rdev->desc->ops->list_voltage(rdev, old_selector); in regulator_set_voltage_time_sel()
4349 new_volt = rdev->desc->ops->list_voltage(rdev, new_selector); in regulator_set_voltage_time_sel()
4351 if (rdev->desc->ops->set_voltage_time) in regulator_set_voltage_time_sel()
4352 return rdev->desc->ops->set_voltage_time(rdev, old_volt, in regulator_set_voltage_time_sel()
4365 if (!rdev->desc->ops->set_voltage && in regulator_sync_voltage_rdev()
4366 !rdev->desc->ops->set_voltage_sel) { in regulator_sync_voltage_rdev()
4367 ret = -EINVAL; in regulator_sync_voltage_rdev()
4372 if (rdev->coupling_desc.n_coupled > 1) in regulator_sync_voltage_rdev()
4375 ret = -EOPNOTSUPP; in regulator_sync_voltage_rdev()
4383 * regulator_sync_voltage - re-apply last regulator output voltage
4386 * Re-apply the last configured voltage. This is intended to be used
4394 struct regulator_dev *rdev = regulator->rdev; in regulator_sync_voltage()
4395 struct regulator_voltage *voltage = ®ulator->voltage[PM_SUSPEND_ON]; in regulator_sync_voltage()
4403 if (!rdev->desc->ops->set_voltage && in regulator_sync_voltage()
4404 !rdev->desc->ops->set_voltage_sel) { in regulator_sync_voltage()
4405 ret = -EINVAL; in regulator_sync_voltage()
4410 if (!voltage->min_uV && !voltage->max_uV) { in regulator_sync_voltage()
4411 ret = -EINVAL; in regulator_sync_voltage()
4415 min_uV = voltage->min_uV; in regulator_sync_voltage()
4416 max_uV = voltage->max_uV; in regulator_sync_voltage()
4428 if (rdev->coupling_desc.n_coupled > 1) in regulator_sync_voltage()
4444 if (rdev->desc->ops->get_bypass) { in regulator_get_voltage_rdev()
4445 ret = rdev->desc->ops->get_bypass(rdev, &bypassed); in regulator_get_voltage_rdev()
4450 if (!rdev->supply) { in regulator_get_voltage_rdev()
4453 return -EPROBE_DEFER; in regulator_get_voltage_rdev()
4456 return regulator_get_voltage_rdev(rdev->supply->rdev); in regulator_get_voltage_rdev()
4460 if (rdev->desc->ops->get_voltage_sel) { in regulator_get_voltage_rdev()
4461 sel = rdev->desc->ops->get_voltage_sel(rdev); in regulator_get_voltage_rdev()
4464 ret = rdev->desc->ops->list_voltage(rdev, sel); in regulator_get_voltage_rdev()
4465 } else if (rdev->desc->ops->get_voltage) { in regulator_get_voltage_rdev()
4466 ret = rdev->desc->ops->get_voltage(rdev); in regulator_get_voltage_rdev()
4467 } else if (rdev->desc->ops->list_voltage) { in regulator_get_voltage_rdev()
4468 ret = rdev->desc->ops->list_voltage(rdev, 0); in regulator_get_voltage_rdev()
4469 } else if (rdev->desc->fixed_uV && (rdev->desc->n_voltages == 1)) { in regulator_get_voltage_rdev()
4470 ret = rdev->desc->fixed_uV; in regulator_get_voltage_rdev()
4471 } else if (rdev->supply) { in regulator_get_voltage_rdev()
4472 ret = regulator_get_voltage_rdev(rdev->supply->rdev); in regulator_get_voltage_rdev()
4473 } else if (rdev->supply_name) { in regulator_get_voltage_rdev()
4474 return -EPROBE_DEFER; in regulator_get_voltage_rdev()
4476 return -EINVAL; in regulator_get_voltage_rdev()
4481 return ret - rdev->constraints->uV_offset; in regulator_get_voltage_rdev()
4486 * regulator_get_voltage - get regulator output voltage
4489 * Return: Current regulator voltage in uV, or a negative error number on failure.
4499 regulator_lock_dependent(regulator->rdev, &ww_ctx); in regulator_get_voltage()
4500 ret = regulator_get_voltage_rdev(regulator->rdev); in regulator_get_voltage()
4501 regulator_unlock_dependent(regulator->rdev, &ww_ctx); in regulator_get_voltage()
4508 * regulator_set_current_limit - set regulator output current limit
4528 struct regulator_dev *rdev = regulator->rdev; in regulator_set_current_limit()
4534 if (!rdev->desc->ops->set_current_limit) { in regulator_set_current_limit()
4535 ret = -EINVAL; in regulator_set_current_limit()
4544 ret = rdev->desc->ops->set_current_limit(rdev, min_uA, max_uA); in regulator_set_current_limit()
4554 if (!rdev->desc->ops->get_current_limit) in _regulator_get_current_limit_unlocked()
4555 return -EINVAL; in _regulator_get_current_limit_unlocked()
4557 return rdev->desc->ops->get_current_limit(rdev); in _regulator_get_current_limit_unlocked()
4572 * regulator_get_current_limit - get regulator output current
4583 return _regulator_get_current_limit(regulator->rdev); in regulator_get_current_limit()
4588 * regulator_set_mode - set regulator operating mode
4590 * @mode: operating mode - one of the REGULATOR_MODE constants
4602 struct regulator_dev *rdev = regulator->rdev; in regulator_set_mode()
4609 if (!rdev->desc->ops->set_mode) { in regulator_set_mode()
4610 ret = -EINVAL; in regulator_set_mode()
4615 if (rdev->desc->ops->get_mode) { in regulator_set_mode()
4616 regulator_curr_mode = rdev->desc->ops->get_mode(rdev); in regulator_set_mode()
4628 ret = rdev->desc->ops->set_mode(rdev, mode); in regulator_set_mode()
4638 if (!rdev->desc->ops->get_mode) in _regulator_get_mode_unlocked()
4639 return -EINVAL; in _regulator_get_mode_unlocked()
4641 return rdev->desc->ops->get_mode(rdev); in _regulator_get_mode_unlocked()
4656 * regulator_get_mode - get regulator operating mode
4666 return _regulator_get_mode(regulator->rdev); in regulator_get_mode()
4674 if (rdev->use_cached_err) { in rdev_get_cached_err_flags()
4675 spin_lock(&rdev->err_lock); in rdev_get_cached_err_flags()
4676 ret = rdev->cached_err; in rdev_get_cached_err_flags()
4677 spin_unlock(&rdev->err_lock); in rdev_get_cached_err_flags()
4691 if (rdev->desc->ops->get_error_flags) in _regulator_get_error_flags()
4692 ret = rdev->desc->ops->get_error_flags(rdev, flags); in _regulator_get_error_flags()
4693 else if (!rdev->use_cached_err) in _regulator_get_error_flags()
4694 ret = -EINVAL; in _regulator_get_error_flags()
4704 * regulator_get_error_flags - get regulator error information
4715 return _regulator_get_error_flags(regulator->rdev, flags); in regulator_get_error_flags()
4720 * regulator_set_load - set regulator load
4732 * consumption are :-
4745 * toward the total requested load. If the regulator is re-enabled
4748 * If a regulator is an always-on regulator then an individual consumer's
4755 struct regulator_dev *rdev = regulator->rdev; in regulator_set_load()
4760 old_uA_load = regulator->uA_load; in regulator_set_load()
4761 regulator->uA_load = uA_load; in regulator_set_load()
4762 if (regulator->enable_count && old_uA_load != uA_load) { in regulator_set_load()
4765 regulator->uA_load = old_uA_load; in regulator_set_load()
4774 * regulator_allow_bypass - allow the regulator to go into bypass mode
4789 struct regulator_dev *rdev = regulator->rdev; in regulator_allow_bypass()
4793 if (!rdev->desc->ops->set_bypass) in regulator_allow_bypass()
4801 if (enable && !regulator->bypass) { in regulator_allow_bypass()
4802 rdev->bypass_count++; in regulator_allow_bypass()
4804 if (rdev->bypass_count == rdev->open_count) { in regulator_allow_bypass()
4807 ret = rdev->desc->ops->set_bypass(rdev, enable); in regulator_allow_bypass()
4809 rdev->bypass_count--; in regulator_allow_bypass()
4814 } else if (!enable && regulator->bypass) { in regulator_allow_bypass()
4815 rdev->bypass_count--; in regulator_allow_bypass()
4817 if (rdev->bypass_count != rdev->open_count) { in regulator_allow_bypass()
4820 ret = rdev->desc->ops->set_bypass(rdev, enable); in regulator_allow_bypass()
4822 rdev->bypass_count++; in regulator_allow_bypass()
4829 regulator->bypass = enable; in regulator_allow_bypass()
4838 * regulator_register_notifier - register regulator event notifier
4849 return blocking_notifier_chain_register(®ulator->rdev->notifier, in regulator_register_notifier()
4855 * regulator_unregister_notifier - unregister regulator event notifier
4866 return blocking_notifier_chain_unregister(®ulator->rdev->notifier, in regulator_unregister_notifier()
4878 int ret = blocking_notifier_call_chain(&rdev->notifier, event, data); in _notifier_call_chain()
4881 struct device *parent = rdev->dev.parent; in _notifier_call_chain()
4886 if (parent && rname == rdev->desc->name) { in _notifier_call_chain()
4887 snprintf(name, sizeof(name), "%s-%s", dev_name(parent), in _notifier_call_chain()
4930 while (--i >= 0) in _regulator_bulk_get()
4937 * regulator_bulk_get - get multiple regulator consumers
4961 bulk->ret = regulator_enable(bulk->consumer); in regulator_bulk_enable_async()
4965 * regulator_bulk_enable - enable multiple regulator consumers
5015 * regulator_bulk_disable - disable multiple regulator consumers
5033 for (i = num_consumers - 1; i >= 0; --i) { in regulator_bulk_disable()
5046 pr_err("Failed to re-enable %s: %pe\n", in regulator_bulk_disable()
5055 * regulator_bulk_force_disable - force disable multiple regulator consumers
5089 * regulator_bulk_free - free multiple regulator consumers
5110 * regulator_handle_critical - Handle events for system-critical regulators.
5114 * This function handles critical events such as under-voltage, over-current,
5115 * and unknown errors for regulators deemed system-critical. On detecting such
5116 * events, it triggers a hardware protection shutdown with a defined timeout.
5123 if (!rdev->constraints->system_critical) in regulator_handle_critical()
5131 reason = "System critical regulator: over-current detected"; in regulator_handle_critical()
5141 rdev->constraints->uv_less_critical_window_ms); in regulator_handle_critical()
5145 * regulator_notifier_call_chain - call regulator event notifier
5148 * @data: callback-specific data.
5167 * regulator_mode_to_status - convert a regulator mode into a status
5237 const struct regulator_ops *ops = rdev->desc->ops; in regulator_attr_is_visible()
5238 umode_t mode = attr->mode; in regulator_attr_is_visible()
5248 if ((ops->get_voltage && ops->get_voltage(rdev) >= 0) || in regulator_attr_is_visible()
5249 (ops->get_voltage_sel && ops->get_voltage_sel(rdev) >= 0) || in regulator_attr_is_visible()
5250 (ops->list_voltage && ops->list_voltage(rdev, 0) >= 0) || in regulator_attr_is_visible()
5251 (rdev->desc->fixed_uV && rdev->desc->n_voltages == 1)) in regulator_attr_is_visible()
5257 return ops->get_current_limit ? mode : 0; in regulator_attr_is_visible()
5260 return ops->get_mode ? mode : 0; in regulator_attr_is_visible()
5263 return (rdev->ena_pin || ops->is_enabled) ? mode : 0; in regulator_attr_is_visible()
5266 return ops->get_status ? mode : 0; in regulator_attr_is_visible()
5269 return ops->get_bypass ? mode : 0; in regulator_attr_is_visible()
5280 return ops->get_error_flags ? mode : 0; in regulator_attr_is_visible()
5285 return (ops->set_voltage || ops->set_voltage_sel) ? mode : 0; in regulator_attr_is_visible()
5289 return ops->set_current_limit ? mode : 0; in regulator_attr_is_visible()
5299 return ops->set_suspend_voltage ? mode : 0; in regulator_attr_is_visible()
5304 return ops->set_suspend_mode ? mode : 0; in regulator_attr_is_visible()
5323 debugfs_remove_recursive(rdev->debugfs); in regulator_dev_release()
5324 kfree(rdev->constraints); in regulator_dev_release()
5325 of_node_put(rdev->dev.of_node); in regulator_dev_release()
5331 struct device *parent = rdev->dev.parent; in rdev_init_debugfs()
5336 if (parent && rname == rdev->desc->name) { in rdev_init_debugfs()
5337 snprintf(name, sizeof(name), "%s-%s", dev_name(parent), in rdev_init_debugfs()
5342 rdev->debugfs = debugfs_create_dir(rname, debugfs_root); in rdev_init_debugfs()
5343 if (IS_ERR(rdev->debugfs)) in rdev_init_debugfs()
5346 debugfs_create_u32("use_count", 0444, rdev->debugfs, in rdev_init_debugfs()
5347 &rdev->use_count); in rdev_init_debugfs()
5348 debugfs_create_u32("open_count", 0444, rdev->debugfs, in rdev_init_debugfs()
5349 &rdev->open_count); in rdev_init_debugfs()
5350 debugfs_create_u32("bypass_count", 0444, rdev->debugfs, in rdev_init_debugfs()
5351 &rdev->bypass_count); in rdev_init_debugfs()
5367 list_add_tail(&coupler->list, ®ulator_coupler_list); in regulator_coupler_register()
5385 err = coupler->attach_regulator(coupler, rdev); in regulator_find_coupler()
5387 if (!coupler->balance_voltage && in regulator_find_coupler()
5388 rdev->coupling_desc.n_coupled > 2) in regulator_find_coupler()
5403 return ERR_PTR(-EINVAL); in regulator_find_coupler()
5406 if (coupler->detach_regulator) in regulator_find_coupler()
5407 coupler->detach_regulator(coupler, rdev); in regulator_find_coupler()
5412 return ERR_PTR(-EPERM); in regulator_find_coupler()
5417 struct regulator_coupler *coupler = rdev->coupling_desc.coupler; in regulator_resolve_coupling()
5418 struct coupling_desc *c_desc = &rdev->coupling_desc; in regulator_resolve_coupling()
5419 int n_coupled = c_desc->n_coupled; in regulator_resolve_coupling()
5425 if (c_desc->coupled_rdevs[i]) in regulator_resolve_coupling()
5428 c_rdev = of_parse_coupled_regulator(rdev, i - 1); in regulator_resolve_coupling()
5433 if (c_rdev->coupling_desc.coupler != coupler) { in regulator_resolve_coupling()
5439 c_desc->coupled_rdevs[i] = c_rdev; in regulator_resolve_coupling()
5440 c_desc->n_resolved++; in regulator_resolve_coupling()
5448 struct regulator_coupler *coupler = rdev->coupling_desc.coupler; in regulator_remove_coupling()
5449 struct coupling_desc *__c_desc, *c_desc = &rdev->coupling_desc; in regulator_remove_coupling()
5455 n_coupled = c_desc->n_coupled; in regulator_remove_coupling()
5458 c_rdev = c_desc->coupled_rdevs[i]; in regulator_remove_coupling()
5465 __c_desc = &c_rdev->coupling_desc; in regulator_remove_coupling()
5466 __n_coupled = __c_desc->n_coupled; in regulator_remove_coupling()
5469 __c_rdev = __c_desc->coupled_rdevs[k]; in regulator_remove_coupling()
5472 __c_desc->coupled_rdevs[k] = NULL; in regulator_remove_coupling()
5473 __c_desc->n_resolved--; in regulator_remove_coupling()
5480 c_desc->coupled_rdevs[i] = NULL; in regulator_remove_coupling()
5481 c_desc->n_resolved--; in regulator_remove_coupling()
5484 if (coupler && coupler->detach_regulator) { in regulator_remove_coupling()
5485 err = coupler->detach_regulator(coupler, rdev); in regulator_remove_coupling()
5491 kfree(rdev->coupling_desc.coupled_rdevs); in regulator_remove_coupling()
5492 rdev->coupling_desc.coupled_rdevs = NULL; in regulator_remove_coupling()
5507 return -ENOMEM; in regulator_init_coupling()
5509 rdev->coupling_desc.coupled_rdevs = coupled; in regulator_init_coupling()
5515 rdev->coupling_desc.coupled_rdevs[0] = rdev; in regulator_init_coupling()
5516 rdev->coupling_desc.n_coupled = n_phandles + 1; in regulator_init_coupling()
5517 rdev->coupling_desc.n_resolved++; in regulator_init_coupling()
5524 return -EPERM; in regulator_init_coupling()
5527 rdev->coupling_desc.coupler = regulator_find_coupler(rdev); in regulator_init_coupling()
5530 if (IS_ERR(rdev->coupling_desc.coupler)) { in regulator_init_coupling()
5531 err = PTR_ERR(rdev->coupling_desc.coupler); in regulator_init_coupling()
5542 if (rdev->coupling_desc.n_coupled > 2) { in generic_coupler_attach()
5545 return -EPERM; in generic_coupler_attach()
5548 if (!rdev->constraints->always_on) { in generic_coupler_attach()
5550 "Coupling of a non always-on regulator is unimplemented\n"); in generic_coupler_attach()
5551 return -ENOTSUPP; in generic_coupler_attach()
5562 * regulator_register - register regulator
5579 static atomic_t regulator_no = ATOMIC_INIT(-1); in regulator_register()
5587 return ERR_PTR(-EINVAL); in regulator_register()
5588 if (cfg->ena_gpiod) in regulator_register()
5591 ret = -EINVAL; in regulator_register()
5595 WARN_ON(!dev || !cfg->dev); in regulator_register()
5597 if (regulator_desc->name == NULL || regulator_desc->ops == NULL) { in regulator_register()
5598 ret = -EINVAL; in regulator_register()
5602 if (regulator_desc->type != REGULATOR_VOLTAGE && in regulator_register()
5603 regulator_desc->type != REGULATOR_CURRENT) { in regulator_register()
5604 ret = -EINVAL; in regulator_register()
5609 WARN_ON(regulator_desc->ops->get_voltage && in regulator_register()
5610 regulator_desc->ops->get_voltage_sel); in regulator_register()
5611 WARN_ON(regulator_desc->ops->set_voltage && in regulator_register()
5612 regulator_desc->ops->set_voltage_sel); in regulator_register()
5615 if (regulator_desc->ops->get_voltage_sel && in regulator_register()
5616 !regulator_desc->ops->list_voltage) { in regulator_register()
5617 ret = -EINVAL; in regulator_register()
5620 if (regulator_desc->ops->set_voltage_sel && in regulator_register()
5621 !regulator_desc->ops->list_voltage) { in regulator_register()
5622 ret = -EINVAL; in regulator_register()
5628 ret = -ENOMEM; in regulator_register()
5631 device_initialize(&rdev->dev); in regulator_register()
5632 dev_set_drvdata(&rdev->dev, rdev); in regulator_register()
5633 rdev->dev.class = ®ulator_class; in regulator_register()
5634 spin_lock_init(&rdev->err_lock); in regulator_register()
5642 ret = -ENOMEM; in regulator_register()
5646 if (config->init_data) { in regulator_register()
5652 if (regulator_desc->of_match) in regulator_register()
5653 dev_warn(dev, "Using provided init data - OF match ignored\n"); in regulator_register()
5655 init_data = config->init_data; in regulator_register()
5656 rdev->dev.of_node = of_node_get(config->of_node); in regulator_register()
5661 &rdev->dev.of_node); in regulator_register()
5668 if (PTR_ERR(init_data) == -EPROBE_DEFER) { in regulator_register()
5669 ret = -EPROBE_DEFER; in regulator_register()
5681 if (!cfg->ena_gpiod && config->ena_gpiod) in regulator_register()
5685 ww_mutex_init(&rdev->mutex, ®ulator_ww_class); in regulator_register()
5686 rdev->reg_data = config->driver_data; in regulator_register()
5687 rdev->owner = regulator_desc->owner; in regulator_register()
5688 rdev->desc = regulator_desc; in regulator_register()
5689 if (config->regmap) in regulator_register()
5690 rdev->regmap = config->regmap; in regulator_register()
5692 rdev->regmap = dev_get_regmap(dev, NULL); in regulator_register()
5693 else if (dev->parent) in regulator_register()
5694 rdev->regmap = dev_get_regmap(dev->parent, NULL); in regulator_register()
5695 INIT_LIST_HEAD(&rdev->consumer_list); in regulator_register()
5696 INIT_LIST_HEAD(&rdev->list); in regulator_register()
5697 BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier); in regulator_register()
5698 INIT_DELAYED_WORK(&rdev->disable_work, regulator_disable_work); in regulator_register()
5700 if (init_data && init_data->supply_regulator) in regulator_register()
5701 rdev->supply_name = init_data->supply_regulator; in regulator_register()
5702 else if (regulator_desc->supply_name) in regulator_register()
5703 rdev->supply_name = regulator_desc->supply_name; in regulator_register()
5706 rdev->dev.parent = config->dev; in regulator_register()
5707 dev_set_name(&rdev->dev, "regulator.%lu", in regulator_register()
5712 rdev->constraints = kmemdup(&init_data->constraints, in regulator_register()
5713 sizeof(*rdev->constraints), in regulator_register()
5716 rdev->constraints = kzalloc(sizeof(*rdev->constraints), in regulator_register()
5718 if (!rdev->constraints) { in regulator_register()
5719 ret = -ENOMEM; in regulator_register()
5723 if (regulator_desc->init_cb) { in regulator_register()
5724 ret = regulator_desc->init_cb(rdev, config); in regulator_register()
5729 if ((rdev->supply_name && !rdev->supply) && in regulator_register()
5730 (rdev->constraints->always_on || in regulator_register()
5731 rdev->constraints->boot_on)) { in regulator_register()
5740 if (config->ena_gpiod) { in regulator_register()
5753 if (ret == -EPROBE_DEFER && !resolved_early) { in regulator_register()
5757 /* FIXME: this currently triggers a chicken-and-egg problem in regulator_register()
5758 * when creating -SUPPLY symlink in sysfs to a regulator in regulator_register()
5762 rdev->supply_name); in regulator_register()
5779 for (i = 0; i < init_data->num_consumer_supplies; i++) { in regulator_register()
5781 init_data->consumer_supplies[i].dev_name, in regulator_register()
5782 init_data->consumer_supplies[i].supply); in regulator_register()
5785 init_data->consumer_supplies[i].supply); in regulator_register()
5791 if (!rdev->desc->ops->get_voltage && in regulator_register()
5792 !rdev->desc->ops->list_voltage && in regulator_register()
5793 !rdev->desc->fixed_uV) in regulator_register()
5794 rdev->is_switch = true; in regulator_register()
5796 ret = device_add(&rdev->dev); in regulator_register()
5819 regulator_put(rdev->supply); in regulator_register()
5820 kfree(rdev->coupling_desc.coupled_rdevs); in regulator_register()
5826 gpiod_put(config->ena_gpiod); in regulator_register()
5828 put_device(&rdev->dev); in regulator_register()
5831 gpiod_put(cfg->ena_gpiod); in regulator_register()
5837 * regulator_unregister - unregister regulator
5847 if (rdev->supply) { in regulator_unregister()
5848 while (rdev->use_count--) in regulator_unregister()
5849 regulator_disable(rdev->supply); in regulator_unregister()
5850 regulator_put(rdev->supply); in regulator_unregister()
5853 flush_work(&rdev->disable_work.work); in regulator_unregister()
5857 WARN_ON(rdev->open_count); in regulator_unregister()
5860 list_del(&rdev->list); in regulator_unregister()
5862 device_unregister(&rdev->dev); in regulator_unregister()
5870 * regulator_suspend - prepare regulators for system wide suspend
5907 if (!rdev->desc->ops->resume) in regulator_resume()
5912 if (rstate->enabled == ENABLE_IN_SUSPEND || in regulator_resume()
5913 rstate->enabled == DISABLE_IN_SUSPEND) in regulator_resume()
5914 ret = rdev->desc->ops->resume(rdev); in regulator_resume()
5943 * regulator_has_full_constraints - the system has fully specified constraints
5960 * rdev_get_drvdata - get rdev regulator driver data
5970 return rdev->reg_data; in rdev_get_drvdata()
5975 * regulator_get_drvdata - get regulator driver data
5985 return regulator->rdev->reg_data; in regulator_get_drvdata()
5990 * regulator_set_drvdata - set regulator driver data
5996 regulator->rdev->reg_data = data; in regulator_set_drvdata()
6001 * rdev_get_id - get regulator ID
6008 return rdev->desc->id; in rdev_get_id()
6014 return &rdev->dev; in rdev_get_dev()
6020 return rdev->regmap; in rdev_get_regmap()
6026 return reg_init_data->driver_data; in regulator_get_init_drvdata()
6036 seq_printf(sf, "%s -> %s.%s\n", in supply_map_show()
6037 rdev_get_name(map->regulator), map->dev_name, in supply_map_show()
6038 map->supply); in supply_map_show()
6060 if (rdev->supply && rdev->supply->rdev == summary_data->parent) in regulator_summary_show_children()
6061 regulator_summary_show_subtree(summary_data->s, rdev, in regulator_summary_show_children()
6062 summary_data->level + 1); in regulator_summary_show_children()
6080 seq_printf(s, "%*s%-*s %3d %4d %6d %7s ", in regulator_summary_show_subtree()
6082 30 - level * 3, rdev_get_name(rdev), in regulator_summary_show_subtree()
6083 rdev->use_count, rdev->open_count, rdev->bypass_count, in regulator_summary_show_subtree()
6090 c = rdev->constraints; in regulator_summary_show_subtree()
6092 switch (rdev->desc->type) { in regulator_summary_show_subtree()
6095 c->min_uV / 1000, c->max_uV / 1000); in regulator_summary_show_subtree()
6099 c->min_uA / 1000, c->max_uA / 1000); in regulator_summary_show_subtree()
6106 list_for_each_entry(consumer, &rdev->consumer_list, list) { in regulator_summary_show_subtree()
6107 if (consumer->dev && consumer->dev->class == ®ulator_class) in regulator_summary_show_subtree()
6110 seq_printf(s, "%*s%-*s ", in regulator_summary_show_subtree()
6112 30 - (level + 1) * 3, in regulator_summary_show_subtree()
6113 consumer->supply_name ? consumer->supply_name : in regulator_summary_show_subtree()
6114 consumer->dev ? dev_name(consumer->dev) : "deviceless"); in regulator_summary_show_subtree()
6116 switch (rdev->desc->type) { in regulator_summary_show_subtree()
6119 consumer->enable_count, in regulator_summary_show_subtree()
6120 consumer->uA_load / 1000, in regulator_summary_show_subtree()
6121 consumer->uA_load && !consumer->enable_count ? in regulator_summary_show_subtree()
6123 consumer->voltage[PM_SUSPEND_ON].min_uV / 1000, in regulator_summary_show_subtree()
6124 consumer->voltage[PM_SUSPEND_ON].max_uV / 1000); in regulator_summary_show_subtree()
6153 if (rdev != *lock_data->old_contended_rdev) { in regulator_summary_lock_one()
6154 ret = regulator_lock_nested(rdev, lock_data->ww_ctx); in regulator_summary_lock_one()
6156 if (ret == -EDEADLK) in regulator_summary_lock_one()
6157 *lock_data->new_contended_rdev = rdev; in regulator_summary_lock_one()
6161 *lock_data->old_contended_rdev = NULL; in regulator_summary_lock_one()
6173 if (rdev == *lock_data->new_contended_rdev) in regulator_summary_unlock_one()
6174 return -EDEADLK; in regulator_summary_unlock_one()
6214 ww_mutex_lock_slow(&new_contended_rdev->mutex, ww_ctx); in regulator_summary_lock()
6216 old_contended_rdev->ref_cnt++; in regulator_summary_lock()
6217 old_contended_rdev->mutex_owner = current; in regulator_summary_lock()
6227 } while (err == -EDEADLK); in regulator_summary_lock()
6246 if (!rdev->supply) in regulator_summary_show_roots()
6257 …seq_puts(s, "-------------------------------------------------------------------------------------… in regulator_summary_show()
6301 struct regulation_constraints *c = rdev->constraints; in regulator_late_cleanup()
6304 if (c && c->always_on) in regulator_late_cleanup()
6312 if (rdev->use_count) in regulator_late_cleanup()