Lines Matching refs:rdev
42 #define rdev_crit(rdev, fmt, ...) \ argument
43 pr_crit("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
44 #define rdev_err(rdev, fmt, ...) \ argument
45 pr_err("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
46 #define rdev_warn(rdev, fmt, ...) \ argument
47 pr_warn("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
48 #define rdev_info(rdev, fmt, ...) \ argument
49 pr_info("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
50 #define rdev_dbg(rdev, fmt, ...) \ argument
51 pr_debug("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
100 static int _regulator_is_enabled(struct regulator_dev *rdev);
101 static int _regulator_disable(struct regulator_dev *rdev);
102 static int _regulator_get_voltage(struct regulator_dev *rdev);
103 static int _regulator_get_current_limit(struct regulator_dev *rdev);
104 static unsigned int _regulator_get_mode(struct regulator_dev *rdev);
105 static int _notifier_call_chain(struct regulator_dev *rdev,
107 static int _regulator_do_set_voltage(struct regulator_dev *rdev,
109 static struct regulator *create_regulator(struct regulator_dev *rdev,
118 static const char *rdev_get_name(struct regulator_dev *rdev) in rdev_get_name() argument
120 if (rdev->constraints && rdev->constraints->name) in rdev_get_name()
121 return rdev->constraints->name; in rdev_get_name()
122 else if (rdev->desc->name) in rdev_get_name()
123 return rdev->desc->name; in rdev_get_name()
160 static int _regulator_can_change_status(struct regulator_dev *rdev) in _regulator_can_change_status() argument
162 if (!rdev->constraints) in _regulator_can_change_status()
165 if (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_STATUS) in _regulator_can_change_status()
172 static int regulator_check_voltage(struct regulator_dev *rdev, in regulator_check_voltage() argument
177 if (!rdev->constraints) { in regulator_check_voltage()
178 rdev_err(rdev, "no constraints\n"); in regulator_check_voltage()
181 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { in regulator_check_voltage()
182 rdev_err(rdev, "operation not allowed\n"); in regulator_check_voltage()
186 if (*max_uV > rdev->constraints->max_uV) in regulator_check_voltage()
187 *max_uV = rdev->constraints->max_uV; in regulator_check_voltage()
188 if (*min_uV < rdev->constraints->min_uV) in regulator_check_voltage()
189 *min_uV = rdev->constraints->min_uV; in regulator_check_voltage()
192 rdev_err(rdev, "unsupportable voltage range: %d-%duV\n", in regulator_check_voltage()
203 static int regulator_check_consumers(struct regulator_dev *rdev, in regulator_check_consumers() argument
208 list_for_each_entry(regulator, &rdev->consumer_list, list) { in regulator_check_consumers()
223 rdev_err(rdev, "Restricting voltage, %u-%uuV\n", in regulator_check_consumers()
232 static int regulator_check_current_limit(struct regulator_dev *rdev, in regulator_check_current_limit() argument
237 if (!rdev->constraints) { in regulator_check_current_limit()
238 rdev_err(rdev, "no constraints\n"); in regulator_check_current_limit()
241 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) { in regulator_check_current_limit()
242 rdev_err(rdev, "operation not allowed\n"); in regulator_check_current_limit()
246 if (*max_uA > rdev->constraints->max_uA) in regulator_check_current_limit()
247 *max_uA = rdev->constraints->max_uA; in regulator_check_current_limit()
248 if (*min_uA < rdev->constraints->min_uA) in regulator_check_current_limit()
249 *min_uA = rdev->constraints->min_uA; in regulator_check_current_limit()
252 rdev_err(rdev, "unsupportable current range: %d-%duA\n", in regulator_check_current_limit()
261 static int regulator_mode_constrain(struct regulator_dev *rdev, int *mode) in regulator_mode_constrain() argument
270 rdev_err(rdev, "invalid mode %x specified\n", *mode); in regulator_mode_constrain()
274 if (!rdev->constraints) { in regulator_mode_constrain()
275 rdev_err(rdev, "no constraints\n"); in regulator_mode_constrain()
278 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) { in regulator_mode_constrain()
279 rdev_err(rdev, "operation not allowed\n"); in regulator_mode_constrain()
287 if (rdev->constraints->valid_modes_mask & *mode) in regulator_mode_constrain()
296 static int regulator_check_drms(struct regulator_dev *rdev) in regulator_check_drms() argument
298 if (!rdev->constraints) { in regulator_check_drms()
299 rdev_err(rdev, "no constraints\n"); in regulator_check_drms()
302 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) { in regulator_check_drms()
303 rdev_err(rdev, "operation not allowed\n"); in regulator_check_drms()
312 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_uV_show() local
315 mutex_lock(&rdev->mutex); in regulator_uV_show()
316 ret = sprintf(buf, "%d\n", _regulator_get_voltage(rdev)); in regulator_uV_show()
317 mutex_unlock(&rdev->mutex); in regulator_uV_show()
326 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_uA_show() local
328 return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev)); in regulator_uA_show()
335 struct regulator_dev *rdev = dev_get_drvdata(dev); in name_show() local
337 return sprintf(buf, "%s\n", rdev_get_name(rdev)); in name_show()
359 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_opmode_show() local
361 return regulator_print_opmode(buf, _regulator_get_mode(rdev)); in regulator_opmode_show()
378 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_state_show() local
381 mutex_lock(&rdev->mutex); in regulator_state_show()
382 ret = regulator_print_state(buf, _regulator_is_enabled(rdev)); in regulator_state_show()
383 mutex_unlock(&rdev->mutex); in regulator_state_show()
392 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_status_show() local
396 status = rdev->desc->ops->get_status(rdev); in regulator_status_show()
439 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_min_uA_show() local
441 if (!rdev->constraints) in regulator_min_uA_show()
444 return sprintf(buf, "%d\n", rdev->constraints->min_uA); in regulator_min_uA_show()
451 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_max_uA_show() local
453 if (!rdev->constraints) in regulator_max_uA_show()
456 return sprintf(buf, "%d\n", rdev->constraints->max_uA); in regulator_max_uA_show()
463 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_min_uV_show() local
465 if (!rdev->constraints) in regulator_min_uV_show()
468 return sprintf(buf, "%d\n", rdev->constraints->min_uV); in regulator_min_uV_show()
475 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_max_uV_show() local
477 if (!rdev->constraints) in regulator_max_uV_show()
480 return sprintf(buf, "%d\n", rdev->constraints->max_uV); in regulator_max_uV_show()
487 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_total_uA_show() local
491 mutex_lock(&rdev->mutex); in regulator_total_uA_show()
492 list_for_each_entry(regulator, &rdev->consumer_list, list) in regulator_total_uA_show()
494 mutex_unlock(&rdev->mutex); in regulator_total_uA_show()
502 struct regulator_dev *rdev = dev_get_drvdata(dev); in num_users_show() local
503 return sprintf(buf, "%d\n", rdev->use_count); in num_users_show()
510 struct regulator_dev *rdev = dev_get_drvdata(dev); in type_show() local
512 switch (rdev->desc->type) { in type_show()
525 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_suspend_mem_uV_show() local
527 return sprintf(buf, "%d\n", rdev->constraints->state_mem.uV); in regulator_suspend_mem_uV_show()
535 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_suspend_disk_uV_show() local
537 return sprintf(buf, "%d\n", rdev->constraints->state_disk.uV); in regulator_suspend_disk_uV_show()
545 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_suspend_standby_uV_show() local
547 return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV); in regulator_suspend_standby_uV_show()
555 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_suspend_mem_mode_show() local
558 rdev->constraints->state_mem.mode); in regulator_suspend_mem_mode_show()
566 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_suspend_disk_mode_show() local
569 rdev->constraints->state_disk.mode); in regulator_suspend_disk_mode_show()
577 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_suspend_standby_mode_show() local
580 rdev->constraints->state_standby.mode); in regulator_suspend_standby_mode_show()
588 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_suspend_mem_state_show() local
591 rdev->constraints->state_mem.enabled); in regulator_suspend_mem_state_show()
599 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_suspend_disk_state_show() local
602 rdev->constraints->state_disk.enabled); in regulator_suspend_disk_state_show()
610 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_suspend_standby_state_show() local
613 rdev->constraints->state_standby.enabled); in regulator_suspend_standby_state_show()
621 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_bypass_show() local
626 ret = rdev->desc->ops->get_bypass(rdev, &bypass); in regulator_bypass_show()
642 static int drms_uA_update(struct regulator_dev *rdev) in drms_uA_update() argument
652 err = regulator_check_drms(rdev); in drms_uA_update()
656 if (!rdev->desc->ops->get_optimum_mode && in drms_uA_update()
657 !rdev->desc->ops->set_load) in drms_uA_update()
660 if (!rdev->desc->ops->set_mode && in drms_uA_update()
661 !rdev->desc->ops->set_load) in drms_uA_update()
665 output_uV = _regulator_get_voltage(rdev); in drms_uA_update()
667 rdev_err(rdev, "invalid output voltage found\n"); in drms_uA_update()
673 if (rdev->supply) in drms_uA_update()
674 input_uV = regulator_get_voltage(rdev->supply); in drms_uA_update()
676 input_uV = rdev->constraints->input_uV; in drms_uA_update()
678 rdev_err(rdev, "invalid input voltage found\n"); in drms_uA_update()
683 list_for_each_entry(sibling, &rdev->consumer_list, list) in drms_uA_update()
686 if (rdev->desc->ops->set_load) { in drms_uA_update()
688 err = rdev->desc->ops->set_load(rdev, current_uA); in drms_uA_update()
690 rdev_err(rdev, "failed to set load %d\n", current_uA); in drms_uA_update()
693 mode = rdev->desc->ops->get_optimum_mode(rdev, input_uV, in drms_uA_update()
697 err = regulator_mode_constrain(rdev, &mode); in drms_uA_update()
699 rdev_err(rdev, "failed to get optimum mode @ %d uA %d -> %d uV\n", in drms_uA_update()
704 err = rdev->desc->ops->set_mode(rdev, mode); in drms_uA_update()
706 rdev_err(rdev, "failed to set optimum mode %x\n", mode); in drms_uA_update()
712 static int suspend_set_state(struct regulator_dev *rdev, in suspend_set_state() argument
722 if (rdev->desc->ops->set_suspend_voltage || in suspend_set_state()
723 rdev->desc->ops->set_suspend_mode) in suspend_set_state()
724 rdev_warn(rdev, "No configuration\n"); in suspend_set_state()
729 rdev_err(rdev, "invalid configuration\n"); in suspend_set_state()
733 if (rstate->enabled && rdev->desc->ops->set_suspend_enable) in suspend_set_state()
734 ret = rdev->desc->ops->set_suspend_enable(rdev); in suspend_set_state()
735 else if (rstate->disabled && rdev->desc->ops->set_suspend_disable) in suspend_set_state()
736 ret = rdev->desc->ops->set_suspend_disable(rdev); in suspend_set_state()
741 rdev_err(rdev, "failed to enabled/disable\n"); in suspend_set_state()
745 if (rdev->desc->ops->set_suspend_voltage && rstate->uV > 0) { in suspend_set_state()
746 ret = rdev->desc->ops->set_suspend_voltage(rdev, rstate->uV); in suspend_set_state()
748 rdev_err(rdev, "failed to set voltage\n"); in suspend_set_state()
753 if (rdev->desc->ops->set_suspend_mode && rstate->mode > 0) { in suspend_set_state()
754 ret = rdev->desc->ops->set_suspend_mode(rdev, rstate->mode); in suspend_set_state()
756 rdev_err(rdev, "failed to set mode\n"); in suspend_set_state()
764 static int suspend_prepare(struct regulator_dev *rdev, suspend_state_t state) in suspend_prepare() argument
766 if (!rdev->constraints) in suspend_prepare()
771 return suspend_set_state(rdev, in suspend_prepare()
772 &rdev->constraints->state_standby); in suspend_prepare()
774 return suspend_set_state(rdev, in suspend_prepare()
775 &rdev->constraints->state_mem); in suspend_prepare()
777 return suspend_set_state(rdev, in suspend_prepare()
778 &rdev->constraints->state_disk); in suspend_prepare()
784 static void print_constraints(struct regulator_dev *rdev) in print_constraints() argument
786 struct regulation_constraints *constraints = rdev->constraints; in print_constraints()
803 ret = _regulator_get_voltage(rdev); in print_constraints()
824 ret = _regulator_get_current_limit(rdev); in print_constraints()
841 rdev_dbg(rdev, "%s\n", buf); in print_constraints()
845 rdev_warn(rdev, in print_constraints()
849 static int machine_constraints_voltage(struct regulator_dev *rdev, in machine_constraints_voltage() argument
852 const struct regulator_ops *ops = rdev->desc->ops; in machine_constraints_voltage()
856 if (rdev->constraints->apply_uV && in machine_constraints_voltage()
857 rdev->constraints->min_uV == rdev->constraints->max_uV) { in machine_constraints_voltage()
858 int current_uV = _regulator_get_voltage(rdev); in machine_constraints_voltage()
860 rdev_err(rdev, in machine_constraints_voltage()
865 if (current_uV < rdev->constraints->min_uV || in machine_constraints_voltage()
866 current_uV > rdev->constraints->max_uV) { in machine_constraints_voltage()
868 rdev, rdev->constraints->min_uV, in machine_constraints_voltage()
869 rdev->constraints->max_uV); in machine_constraints_voltage()
871 rdev_err(rdev, in machine_constraints_voltage()
873 rdev->constraints->min_uV, ret); in machine_constraints_voltage()
882 if (ops->list_voltage && rdev->desc->n_voltages) { in machine_constraints_voltage()
883 int count = rdev->desc->n_voltages; in machine_constraints_voltage()
905 rdev_err(rdev, "invalid voltage constraints\n"); in machine_constraints_voltage()
913 value = ops->list_voltage(rdev, i); in machine_constraints_voltage()
926 rdev_err(rdev, in machine_constraints_voltage()
934 rdev_dbg(rdev, "override min_uV, %d -> %d\n", in machine_constraints_voltage()
939 rdev_dbg(rdev, "override max_uV, %d -> %d\n", in machine_constraints_voltage()
948 static int machine_constraints_current(struct regulator_dev *rdev, in machine_constraints_current() argument
951 const struct regulator_ops *ops = rdev->desc->ops; in machine_constraints_current()
958 rdev_err(rdev, "Invalid current constraints\n"); in machine_constraints_current()
963 rdev_warn(rdev, "Operation of current configuration missing\n"); in machine_constraints_current()
968 ret = ops->set_current_limit(rdev, constraints->min_uA, in machine_constraints_current()
971 rdev_err(rdev, "Failed to set current constraint, %d\n", ret); in machine_constraints_current()
978 static int _regulator_do_enable(struct regulator_dev *rdev);
991 static int set_machine_constraints(struct regulator_dev *rdev, in set_machine_constraints() argument
995 const struct regulator_ops *ops = rdev->desc->ops; in set_machine_constraints()
998 rdev->constraints = kmemdup(constraints, sizeof(*constraints), in set_machine_constraints()
1001 rdev->constraints = kzalloc(sizeof(*constraints), in set_machine_constraints()
1003 if (!rdev->constraints) in set_machine_constraints()
1006 ret = machine_constraints_voltage(rdev, rdev->constraints); in set_machine_constraints()
1010 ret = machine_constraints_current(rdev, rdev->constraints); in set_machine_constraints()
1015 if (rdev->constraints->initial_state) { in set_machine_constraints()
1016 ret = suspend_prepare(rdev, rdev->constraints->initial_state); in set_machine_constraints()
1018 rdev_err(rdev, "failed to set suspend state\n"); in set_machine_constraints()
1023 if (rdev->constraints->initial_mode) { in set_machine_constraints()
1025 rdev_err(rdev, "no set_mode operation\n"); in set_machine_constraints()
1030 ret = ops->set_mode(rdev, rdev->constraints->initial_mode); in set_machine_constraints()
1032 rdev_err(rdev, "failed to set initial mode: %d\n", ret); in set_machine_constraints()
1040 if (rdev->constraints->always_on || rdev->constraints->boot_on) { in set_machine_constraints()
1041 ret = _regulator_do_enable(rdev); in set_machine_constraints()
1043 rdev_err(rdev, "failed to enable\n"); in set_machine_constraints()
1048 if ((rdev->constraints->ramp_delay || rdev->constraints->ramp_disable) in set_machine_constraints()
1050 ret = ops->set_ramp_delay(rdev, rdev->constraints->ramp_delay); in set_machine_constraints()
1052 rdev_err(rdev, "failed to set ramp_delay\n"); in set_machine_constraints()
1057 print_constraints(rdev); in set_machine_constraints()
1060 kfree(rdev->constraints); in set_machine_constraints()
1061 rdev->constraints = NULL; in set_machine_constraints()
1074 static int set_supply(struct regulator_dev *rdev, in set_supply() argument
1079 rdev_info(rdev, "supplied by %s\n", rdev_get_name(supply_rdev)); in set_supply()
1081 rdev->supply = create_regulator(supply_rdev, &rdev->dev, "SUPPLY"); in set_supply()
1082 if (rdev->supply == NULL) { in set_supply()
1102 static int set_consumer_device_supply(struct regulator_dev *rdev, in set_consumer_device_supply() argument
1133 dev_name(&rdev->dev), rdev_get_name(rdev)); in set_consumer_device_supply()
1141 node->regulator = rdev; in set_consumer_device_supply()
1156 static void unset_regulator_supplies(struct regulator_dev *rdev) in unset_regulator_supplies() argument
1161 if (rdev == node->regulator) { in unset_regulator_supplies()
1171 static struct regulator *create_regulator(struct regulator_dev *rdev, in create_regulator() argument
1183 mutex_lock(&rdev->mutex); in create_regulator()
1184 regulator->rdev = rdev; in create_regulator()
1185 list_add(®ulator->list, &rdev->consumer_list); in create_regulator()
1200 err = sysfs_create_link(&rdev->dev.kobj, &dev->kobj, in create_regulator()
1203 rdev_warn(rdev, "could not add device link %s err %d\n", in create_regulator()
1214 rdev->debugfs); in create_regulator()
1216 rdev_warn(rdev, "Failed to create debugfs directory\n"); in create_regulator()
1231 if (!_regulator_can_change_status(rdev) && in create_regulator()
1232 _regulator_is_enabled(rdev)) in create_regulator()
1235 mutex_unlock(&rdev->mutex); in create_regulator()
1240 mutex_unlock(&rdev->mutex); in create_regulator()
1244 static int _regulator_get_enable_time(struct regulator_dev *rdev) in _regulator_get_enable_time() argument
1246 if (rdev->constraints && rdev->constraints->enable_time) in _regulator_get_enable_time()
1247 return rdev->constraints->enable_time; in _regulator_get_enable_time()
1248 if (!rdev->desc->ops->enable_time) in _regulator_get_enable_time()
1249 return rdev->desc->enable_time; in _regulator_get_enable_time()
1250 return rdev->desc->ops->enable_time(rdev); in _regulator_get_enable_time()
1333 static int regulator_resolve_supply(struct regulator_dev *rdev) in regulator_resolve_supply() argument
1336 struct device *dev = rdev->dev.parent; in regulator_resolve_supply()
1340 if (!rdev->supply_name) in regulator_resolve_supply()
1344 if (rdev->supply) in regulator_resolve_supply()
1347 r = regulator_dev_lookup(dev, rdev->supply_name, &ret); in regulator_resolve_supply()
1358 rdev->supply_name, rdev->desc->name); in regulator_resolve_supply()
1367 ret = set_supply(rdev, r); in regulator_resolve_supply()
1372 if (_regulator_is_enabled(rdev)) { in regulator_resolve_supply()
1373 ret = regulator_enable(rdev->supply); in regulator_resolve_supply()
1385 struct regulator_dev *rdev; in _regulator_get() local
1405 rdev = regulator_dev_lookup(dev, id, &ret); in _regulator_get()
1406 if (rdev) in _regulator_get()
1429 rdev = dummy_regulator_rdev; in _regulator_get()
1440 if (rdev->exclusive) { in _regulator_get()
1445 if (exclusive && rdev->open_count) { in _regulator_get()
1450 ret = regulator_resolve_supply(rdev); in _regulator_get()
1456 if (!try_module_get(rdev->owner)) in _regulator_get()
1459 regulator = create_regulator(rdev, dev, id); in _regulator_get()
1462 module_put(rdev->owner); in _regulator_get()
1466 rdev->open_count++; in _regulator_get()
1468 rdev->exclusive = 1; in _regulator_get()
1470 ret = _regulator_is_enabled(rdev); in _regulator_get()
1472 rdev->use_count = 1; in _regulator_get()
1474 rdev->use_count = 0; in _regulator_get()
1558 struct regulator_dev *rdev; in _regulator_put() local
1563 rdev = regulator->rdev; in _regulator_put()
1569 sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name); in _regulator_put()
1570 mutex_lock(&rdev->mutex); in _regulator_put()
1575 rdev->open_count--; in _regulator_put()
1576 rdev->exclusive = 0; in _regulator_put()
1577 mutex_unlock(&rdev->mutex); in _regulator_put()
1579 module_put(rdev->owner); in _regulator_put()
1728 static int regulator_ena_gpio_request(struct regulator_dev *rdev, in regulator_ena_gpio_request() argument
1739 rdev_dbg(rdev, "GPIO %d is already used\n", in regulator_ena_gpio_request()
1747 rdev_get_name(rdev)); in regulator_ena_gpio_request()
1763 rdev->ena_pin = pin; in regulator_ena_gpio_request()
1767 static void regulator_ena_gpio_free(struct regulator_dev *rdev) in regulator_ena_gpio_free() argument
1771 if (!rdev->ena_pin) in regulator_ena_gpio_free()
1776 if (pin->gpiod == rdev->ena_pin->gpiod) { in regulator_ena_gpio_free()
1782 rdev->ena_pin = NULL; in regulator_ena_gpio_free()
1799 static int regulator_ena_gpio_ctrl(struct regulator_dev *rdev, bool enable) in regulator_ena_gpio_ctrl() argument
1801 struct regulator_enable_gpio *pin = rdev->ena_pin; in regulator_ena_gpio_ctrl()
1869 static int _regulator_do_enable(struct regulator_dev *rdev) in _regulator_do_enable() argument
1874 ret = _regulator_get_enable_time(rdev); in _regulator_do_enable()
1878 rdev_warn(rdev, "enable_time() failed: %d\n", ret); in _regulator_do_enable()
1882 trace_regulator_enable(rdev_get_name(rdev)); in _regulator_do_enable()
1884 if (rdev->desc->off_on_delay) { in _regulator_do_enable()
1891 max_delay = usecs_to_jiffies(rdev->desc->off_on_delay); in _regulator_do_enable()
1892 intended = rdev->last_off_jiffy + max_delay; in _regulator_do_enable()
1909 if (rdev->ena_pin) { in _regulator_do_enable()
1910 if (!rdev->ena_gpio_state) { in _regulator_do_enable()
1911 ret = regulator_ena_gpio_ctrl(rdev, true); in _regulator_do_enable()
1914 rdev->ena_gpio_state = 1; in _regulator_do_enable()
1916 } else if (rdev->desc->ops->enable) { in _regulator_do_enable()
1917 ret = rdev->desc->ops->enable(rdev); in _regulator_do_enable()
1927 trace_regulator_enable_delay(rdev_get_name(rdev)); in _regulator_do_enable()
1931 trace_regulator_enable_complete(rdev_get_name(rdev)); in _regulator_do_enable()
1937 static int _regulator_enable(struct regulator_dev *rdev) in _regulator_enable() argument
1942 if (rdev->constraints && in _regulator_enable()
1943 (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) in _regulator_enable()
1944 drms_uA_update(rdev); in _regulator_enable()
1946 if (rdev->use_count == 0) { in _regulator_enable()
1948 ret = _regulator_is_enabled(rdev); in _regulator_enable()
1950 if (!_regulator_can_change_status(rdev)) in _regulator_enable()
1953 ret = _regulator_do_enable(rdev); in _regulator_enable()
1958 rdev_err(rdev, "is_enabled() failed: %d\n", ret); in _regulator_enable()
1964 rdev->use_count++; in _regulator_enable()
1982 struct regulator_dev *rdev = regulator->rdev; in regulator_enable() local
1988 if (rdev->supply) { in regulator_enable()
1989 ret = regulator_enable(rdev->supply); in regulator_enable()
1994 mutex_lock(&rdev->mutex); in regulator_enable()
1995 ret = _regulator_enable(rdev); in regulator_enable()
1996 mutex_unlock(&rdev->mutex); in regulator_enable()
1998 if (ret != 0 && rdev->supply) in regulator_enable()
1999 regulator_disable(rdev->supply); in regulator_enable()
2005 static int _regulator_do_disable(struct regulator_dev *rdev) in _regulator_do_disable() argument
2009 trace_regulator_disable(rdev_get_name(rdev)); in _regulator_do_disable()
2011 if (rdev->ena_pin) { in _regulator_do_disable()
2012 if (rdev->ena_gpio_state) { in _regulator_do_disable()
2013 ret = regulator_ena_gpio_ctrl(rdev, false); in _regulator_do_disable()
2016 rdev->ena_gpio_state = 0; in _regulator_do_disable()
2019 } else if (rdev->desc->ops->disable) { in _regulator_do_disable()
2020 ret = rdev->desc->ops->disable(rdev); in _regulator_do_disable()
2028 if (rdev->desc->off_on_delay) in _regulator_do_disable()
2029 rdev->last_off_jiffy = jiffies; in _regulator_do_disable()
2031 trace_regulator_disable_complete(rdev_get_name(rdev)); in _regulator_do_disable()
2037 static int _regulator_disable(struct regulator_dev *rdev) in _regulator_disable() argument
2041 if (WARN(rdev->use_count <= 0, in _regulator_disable()
2042 "unbalanced disables for %s\n", rdev_get_name(rdev))) in _regulator_disable()
2046 if (rdev->use_count == 1 && in _regulator_disable()
2047 (rdev->constraints && !rdev->constraints->always_on)) { in _regulator_disable()
2050 if (_regulator_can_change_status(rdev)) { in _regulator_disable()
2051 ret = _notifier_call_chain(rdev, in _regulator_disable()
2057 ret = _regulator_do_disable(rdev); in _regulator_disable()
2059 rdev_err(rdev, "failed to disable\n"); in _regulator_disable()
2060 _notifier_call_chain(rdev, in _regulator_disable()
2065 _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE, in _regulator_disable()
2069 rdev->use_count = 0; in _regulator_disable()
2070 } else if (rdev->use_count > 1) { in _regulator_disable()
2072 if (rdev->constraints && in _regulator_disable()
2073 (rdev->constraints->valid_ops_mask & in _regulator_disable()
2075 drms_uA_update(rdev); in _regulator_disable()
2077 rdev->use_count--; in _regulator_disable()
2097 struct regulator_dev *rdev = regulator->rdev; in regulator_disable() local
2103 mutex_lock(&rdev->mutex); in regulator_disable()
2104 ret = _regulator_disable(rdev); in regulator_disable()
2105 mutex_unlock(&rdev->mutex); in regulator_disable()
2107 if (ret == 0 && rdev->supply) in regulator_disable()
2108 regulator_disable(rdev->supply); in regulator_disable()
2115 static int _regulator_force_disable(struct regulator_dev *rdev) in _regulator_force_disable() argument
2119 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE | in _regulator_force_disable()
2124 ret = _regulator_do_disable(rdev); in _regulator_force_disable()
2126 rdev_err(rdev, "failed to force disable\n"); in _regulator_force_disable()
2127 _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE | in _regulator_force_disable()
2132 _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE | in _regulator_force_disable()
2149 struct regulator_dev *rdev = regulator->rdev; in regulator_force_disable() local
2152 mutex_lock(&rdev->mutex); in regulator_force_disable()
2154 ret = _regulator_force_disable(regulator->rdev); in regulator_force_disable()
2155 mutex_unlock(&rdev->mutex); in regulator_force_disable()
2157 if (rdev->supply) in regulator_force_disable()
2158 while (rdev->open_count--) in regulator_force_disable()
2159 regulator_disable(rdev->supply); in regulator_force_disable()
2167 struct regulator_dev *rdev = container_of(work, struct regulator_dev, in regulator_disable_work() local
2171 mutex_lock(&rdev->mutex); in regulator_disable_work()
2173 BUG_ON(!rdev->deferred_disables); in regulator_disable_work()
2175 count = rdev->deferred_disables; in regulator_disable_work()
2176 rdev->deferred_disables = 0; in regulator_disable_work()
2179 ret = _regulator_disable(rdev); in regulator_disable_work()
2181 rdev_err(rdev, "Deferred disable failed: %d\n", ret); in regulator_disable_work()
2184 mutex_unlock(&rdev->mutex); in regulator_disable_work()
2186 if (rdev->supply) { in regulator_disable_work()
2188 ret = regulator_disable(rdev->supply); in regulator_disable_work()
2190 rdev_err(rdev, in regulator_disable_work()
2211 struct regulator_dev *rdev = regulator->rdev; in regulator_disable_deferred() local
2220 mutex_lock(&rdev->mutex); in regulator_disable_deferred()
2221 rdev->deferred_disables++; in regulator_disable_deferred()
2222 mutex_unlock(&rdev->mutex); in regulator_disable_deferred()
2225 &rdev->disable_work, in regulator_disable_deferred()
2234 static int _regulator_is_enabled(struct regulator_dev *rdev) in _regulator_is_enabled() argument
2237 if (rdev->ena_pin) in _regulator_is_enabled()
2238 return rdev->ena_gpio_state; in _regulator_is_enabled()
2241 if (!rdev->desc->ops->is_enabled) in _regulator_is_enabled()
2244 return rdev->desc->ops->is_enabled(rdev); in _regulator_is_enabled()
2266 mutex_lock(®ulator->rdev->mutex); in regulator_is_enabled()
2267 ret = _regulator_is_enabled(regulator->rdev); in regulator_is_enabled()
2268 mutex_unlock(®ulator->rdev->mutex); in regulator_is_enabled()
2285 struct regulator_dev *rdev = regulator->rdev; in regulator_can_change_voltage() local
2287 if (rdev->constraints && in regulator_can_change_voltage()
2288 (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { in regulator_can_change_voltage()
2289 if (rdev->desc->n_voltages - rdev->desc->linear_min_sel > 1) in regulator_can_change_voltage()
2292 if (rdev->desc->continuous_voltage_range && in regulator_can_change_voltage()
2293 rdev->constraints->min_uV && rdev->constraints->max_uV && in regulator_can_change_voltage()
2294 rdev->constraints->min_uV != rdev->constraints->max_uV) in regulator_can_change_voltage()
2312 struct regulator_dev *rdev = regulator->rdev; in regulator_count_voltages() local
2314 if (rdev->desc->n_voltages) in regulator_count_voltages()
2315 return rdev->desc->n_voltages; in regulator_count_voltages()
2317 if (!rdev->supply) in regulator_count_voltages()
2320 return regulator_count_voltages(rdev->supply); in regulator_count_voltages()
2336 struct regulator_dev *rdev = regulator->rdev; in regulator_list_voltage() local
2337 const struct regulator_ops *ops = rdev->desc->ops; in regulator_list_voltage()
2340 if (rdev->desc->fixed_uV && rdev->desc->n_voltages == 1 && !selector) in regulator_list_voltage()
2341 return rdev->desc->fixed_uV; in regulator_list_voltage()
2344 if (selector >= rdev->desc->n_voltages) in regulator_list_voltage()
2346 mutex_lock(&rdev->mutex); in regulator_list_voltage()
2347 ret = ops->list_voltage(rdev, selector); in regulator_list_voltage()
2348 mutex_unlock(&rdev->mutex); in regulator_list_voltage()
2349 } else if (rdev->supply) { in regulator_list_voltage()
2350 ret = regulator_list_voltage(rdev->supply, selector); in regulator_list_voltage()
2356 if (ret < rdev->constraints->min_uV) in regulator_list_voltage()
2358 else if (ret > rdev->constraints->max_uV) in regulator_list_voltage()
2375 struct regmap *map = regulator->rdev->regmap; in regulator_get_regmap()
2398 struct regulator_dev *rdev = regulator->rdev; in regulator_get_hardware_vsel_register() local
2399 const struct regulator_ops *ops = rdev->desc->ops; in regulator_get_hardware_vsel_register()
2404 *vsel_reg = rdev->desc->vsel_reg; in regulator_get_hardware_vsel_register()
2405 *vsel_mask = rdev->desc->vsel_mask; in regulator_get_hardware_vsel_register()
2425 struct regulator_dev *rdev = regulator->rdev; in regulator_list_hardware_vsel() local
2426 const struct regulator_ops *ops = rdev->desc->ops; in regulator_list_hardware_vsel()
2428 if (selector >= rdev->desc->n_voltages) in regulator_list_hardware_vsel()
2446 struct regulator_dev *rdev = regulator->rdev; in regulator_get_linear_step() local
2448 return rdev->desc->uV_step; in regulator_get_linear_step()
2464 struct regulator_dev *rdev = regulator->rdev; in regulator_is_supported_voltage() local
2468 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { in regulator_is_supported_voltage()
2477 if (rdev->desc->continuous_voltage_range) in regulator_is_supported_voltage()
2478 return min_uV >= rdev->constraints->min_uV && in regulator_is_supported_voltage()
2479 max_uV <= rdev->constraints->max_uV; in regulator_is_supported_voltage()
2497 static int _regulator_call_set_voltage(struct regulator_dev *rdev, in _regulator_call_set_voltage() argument
2504 data.old_uV = _regulator_get_voltage(rdev); in _regulator_call_set_voltage()
2507 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_PRE_VOLTAGE_CHANGE, in _regulator_call_set_voltage()
2512 ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV, selector); in _regulator_call_set_voltage()
2516 _notifier_call_chain(rdev, REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE, in _regulator_call_set_voltage()
2522 static int _regulator_call_set_voltage_sel(struct regulator_dev *rdev, in _regulator_call_set_voltage_sel() argument
2528 data.old_uV = _regulator_get_voltage(rdev); in _regulator_call_set_voltage_sel()
2531 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_PRE_VOLTAGE_CHANGE, in _regulator_call_set_voltage_sel()
2536 ret = rdev->desc->ops->set_voltage_sel(rdev, selector); in _regulator_call_set_voltage_sel()
2540 _notifier_call_chain(rdev, REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE, in _regulator_call_set_voltage_sel()
2546 static int _regulator_do_set_voltage(struct regulator_dev *rdev, in _regulator_do_set_voltage() argument
2555 trace_regulator_set_voltage(rdev_get_name(rdev), min_uV, max_uV); in _regulator_do_set_voltage()
2557 min_uV += rdev->constraints->uV_offset; in _regulator_do_set_voltage()
2558 max_uV += rdev->constraints->uV_offset; in _regulator_do_set_voltage()
2564 if (_regulator_is_enabled(rdev) && in _regulator_do_set_voltage()
2565 rdev->desc->ops->set_voltage_time_sel && in _regulator_do_set_voltage()
2566 rdev->desc->ops->get_voltage_sel) { in _regulator_do_set_voltage()
2567 old_selector = rdev->desc->ops->get_voltage_sel(rdev); in _regulator_do_set_voltage()
2572 if (rdev->desc->ops->set_voltage) { in _regulator_do_set_voltage()
2573 ret = _regulator_call_set_voltage(rdev, min_uV, max_uV, in _regulator_do_set_voltage()
2577 if (rdev->desc->ops->list_voltage) in _regulator_do_set_voltage()
2578 best_val = rdev->desc->ops->list_voltage(rdev, in _regulator_do_set_voltage()
2581 best_val = _regulator_get_voltage(rdev); in _regulator_do_set_voltage()
2584 } else if (rdev->desc->ops->set_voltage_sel) { in _regulator_do_set_voltage()
2585 if (rdev->desc->ops->map_voltage) { in _regulator_do_set_voltage()
2586 ret = rdev->desc->ops->map_voltage(rdev, min_uV, in _regulator_do_set_voltage()
2589 if (rdev->desc->ops->list_voltage == in _regulator_do_set_voltage()
2591 ret = regulator_map_voltage_linear(rdev, in _regulator_do_set_voltage()
2593 else if (rdev->desc->ops->list_voltage == in _regulator_do_set_voltage()
2595 ret = regulator_map_voltage_linear_range(rdev, in _regulator_do_set_voltage()
2598 ret = regulator_map_voltage_iterate(rdev, in _regulator_do_set_voltage()
2603 best_val = rdev->desc->ops->list_voltage(rdev, ret); in _regulator_do_set_voltage()
2610 rdev, best_val, selector); in _regulator_do_set_voltage()
2620 if (ret == 0 && !rdev->constraints->ramp_disable && old_selector >= 0 in _regulator_do_set_voltage()
2623 delay = rdev->desc->ops->set_voltage_time_sel(rdev, in _regulator_do_set_voltage()
2626 rdev_warn(rdev, "set_voltage_time_sel() failed: %d\n", in _regulator_do_set_voltage()
2643 _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, in _regulator_do_set_voltage()
2647 trace_regulator_set_voltage_complete(rdev_get_name(rdev), best_val); in _regulator_do_set_voltage()
2672 struct regulator_dev *rdev = regulator->rdev; in regulator_set_voltage() local
2677 mutex_lock(&rdev->mutex); in regulator_set_voltage()
2690 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { in regulator_set_voltage()
2691 current_uV = _regulator_get_voltage(rdev); in regulator_set_voltage()
2700 if (!rdev->desc->ops->set_voltage && in regulator_set_voltage()
2701 !rdev->desc->ops->set_voltage_sel) { in regulator_set_voltage()
2707 ret = regulator_check_voltage(rdev, &min_uV, &max_uV); in regulator_set_voltage()
2717 ret = regulator_check_consumers(rdev, &min_uV, &max_uV); in regulator_set_voltage()
2721 ret = _regulator_do_set_voltage(rdev, min_uV, max_uV); in regulator_set_voltage()
2726 mutex_unlock(&rdev->mutex); in regulator_set_voltage()
2731 mutex_unlock(&rdev->mutex); in regulator_set_voltage()
2749 struct regulator_dev *rdev = regulator->rdev; in regulator_set_voltage_time() local
2750 const struct regulator_ops *ops = rdev->desc->ops; in regulator_set_voltage_time()
2758 || !rdev->desc->n_voltages) in regulator_set_voltage_time()
2761 for (i = 0; i < rdev->desc->n_voltages; i++) { in regulator_set_voltage_time()
2777 return ops->set_voltage_time_sel(rdev, old_sel, new_sel); in regulator_set_voltage_time()
2793 int regulator_set_voltage_time_sel(struct regulator_dev *rdev, in regulator_set_voltage_time_sel() argument
2800 if (rdev->constraints->ramp_delay) in regulator_set_voltage_time_sel()
2801 ramp_delay = rdev->constraints->ramp_delay; in regulator_set_voltage_time_sel()
2802 else if (rdev->desc->ramp_delay) in regulator_set_voltage_time_sel()
2803 ramp_delay = rdev->desc->ramp_delay; in regulator_set_voltage_time_sel()
2806 rdev_warn(rdev, "ramp_delay not set\n"); in regulator_set_voltage_time_sel()
2811 if (!rdev->desc->ops->list_voltage) in regulator_set_voltage_time_sel()
2814 old_volt = rdev->desc->ops->list_voltage(rdev, old_selector); in regulator_set_voltage_time_sel()
2815 new_volt = rdev->desc->ops->list_voltage(rdev, new_selector); in regulator_set_voltage_time_sel()
2831 struct regulator_dev *rdev = regulator->rdev; in regulator_sync_voltage() local
2834 mutex_lock(&rdev->mutex); in regulator_sync_voltage()
2836 if (!rdev->desc->ops->set_voltage && in regulator_sync_voltage()
2837 !rdev->desc->ops->set_voltage_sel) { in regulator_sync_voltage()
2852 ret = regulator_check_voltage(rdev, &min_uV, &max_uV); in regulator_sync_voltage()
2856 ret = regulator_check_consumers(rdev, &min_uV, &max_uV); in regulator_sync_voltage()
2860 ret = _regulator_do_set_voltage(rdev, min_uV, max_uV); in regulator_sync_voltage()
2863 mutex_unlock(&rdev->mutex); in regulator_sync_voltage()
2868 static int _regulator_get_voltage(struct regulator_dev *rdev) in _regulator_get_voltage() argument
2872 if (rdev->desc->ops->get_voltage_sel) { in _regulator_get_voltage()
2873 sel = rdev->desc->ops->get_voltage_sel(rdev); in _regulator_get_voltage()
2876 ret = rdev->desc->ops->list_voltage(rdev, sel); in _regulator_get_voltage()
2877 } else if (rdev->desc->ops->get_voltage) { in _regulator_get_voltage()
2878 ret = rdev->desc->ops->get_voltage(rdev); in _regulator_get_voltage()
2879 } else if (rdev->desc->ops->list_voltage) { in _regulator_get_voltage()
2880 ret = rdev->desc->ops->list_voltage(rdev, 0); in _regulator_get_voltage()
2881 } else if (rdev->desc->fixed_uV && (rdev->desc->n_voltages == 1)) { in _regulator_get_voltage()
2882 ret = rdev->desc->fixed_uV; in _regulator_get_voltage()
2883 } else if (rdev->supply) { in _regulator_get_voltage()
2884 ret = regulator_get_voltage(rdev->supply); in _regulator_get_voltage()
2891 return ret - rdev->constraints->uV_offset; in _regulator_get_voltage()
2907 mutex_lock(®ulator->rdev->mutex); in regulator_get_voltage()
2909 ret = _regulator_get_voltage(regulator->rdev); in regulator_get_voltage()
2911 mutex_unlock(®ulator->rdev->mutex); in regulator_get_voltage()
2936 struct regulator_dev *rdev = regulator->rdev; in regulator_set_current_limit() local
2939 mutex_lock(&rdev->mutex); in regulator_set_current_limit()
2942 if (!rdev->desc->ops->set_current_limit) { in regulator_set_current_limit()
2948 ret = regulator_check_current_limit(rdev, &min_uA, &max_uA); in regulator_set_current_limit()
2952 ret = rdev->desc->ops->set_current_limit(rdev, min_uA, max_uA); in regulator_set_current_limit()
2954 mutex_unlock(&rdev->mutex); in regulator_set_current_limit()
2959 static int _regulator_get_current_limit(struct regulator_dev *rdev) in _regulator_get_current_limit() argument
2963 mutex_lock(&rdev->mutex); in _regulator_get_current_limit()
2966 if (!rdev->desc->ops->get_current_limit) { in _regulator_get_current_limit()
2971 ret = rdev->desc->ops->get_current_limit(rdev); in _regulator_get_current_limit()
2973 mutex_unlock(&rdev->mutex); in _regulator_get_current_limit()
2988 return _regulator_get_current_limit(regulator->rdev); in regulator_get_current_limit()
3005 struct regulator_dev *rdev = regulator->rdev; in regulator_set_mode() local
3009 mutex_lock(&rdev->mutex); in regulator_set_mode()
3012 if (!rdev->desc->ops->set_mode) { in regulator_set_mode()
3018 if (rdev->desc->ops->get_mode) { in regulator_set_mode()
3019 regulator_curr_mode = rdev->desc->ops->get_mode(rdev); in regulator_set_mode()
3027 ret = regulator_mode_constrain(rdev, &mode); in regulator_set_mode()
3031 ret = rdev->desc->ops->set_mode(rdev, mode); in regulator_set_mode()
3033 mutex_unlock(&rdev->mutex); in regulator_set_mode()
3038 static unsigned int _regulator_get_mode(struct regulator_dev *rdev) in _regulator_get_mode() argument
3042 mutex_lock(&rdev->mutex); in _regulator_get_mode()
3045 if (!rdev->desc->ops->get_mode) { in _regulator_get_mode()
3050 ret = rdev->desc->ops->get_mode(rdev); in _regulator_get_mode()
3052 mutex_unlock(&rdev->mutex); in _regulator_get_mode()
3064 return _regulator_get_mode(regulator->rdev); in regulator_get_mode()
3096 struct regulator_dev *rdev = regulator->rdev; in regulator_set_load() local
3099 mutex_lock(&rdev->mutex); in regulator_set_load()
3101 ret = drms_uA_update(rdev); in regulator_set_load()
3102 mutex_unlock(&rdev->mutex); in regulator_set_load()
3121 struct regulator_dev *rdev = regulator->rdev; in regulator_allow_bypass() local
3124 if (!rdev->desc->ops->set_bypass) in regulator_allow_bypass()
3127 if (rdev->constraints && in regulator_allow_bypass()
3128 !(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_BYPASS)) in regulator_allow_bypass()
3131 mutex_lock(&rdev->mutex); in regulator_allow_bypass()
3134 rdev->bypass_count++; in regulator_allow_bypass()
3136 if (rdev->bypass_count == rdev->open_count) { in regulator_allow_bypass()
3137 ret = rdev->desc->ops->set_bypass(rdev, enable); in regulator_allow_bypass()
3139 rdev->bypass_count--; in regulator_allow_bypass()
3143 rdev->bypass_count--; in regulator_allow_bypass()
3145 if (rdev->bypass_count != rdev->open_count) { in regulator_allow_bypass()
3146 ret = rdev->desc->ops->set_bypass(rdev, enable); in regulator_allow_bypass()
3148 rdev->bypass_count++; in regulator_allow_bypass()
3155 mutex_unlock(&rdev->mutex); in regulator_allow_bypass()
3171 return blocking_notifier_chain_register(®ulator->rdev->notifier, in regulator_register_notifier()
3186 return blocking_notifier_chain_unregister(®ulator->rdev->notifier, in regulator_unregister_notifier()
3194 static int _notifier_call_chain(struct regulator_dev *rdev, in _notifier_call_chain() argument
3198 return blocking_notifier_call_chain(&rdev->notifier, event, data); in _notifier_call_chain()
3412 int regulator_notifier_call_chain(struct regulator_dev *rdev, in regulator_notifier_call_chain() argument
3415 _notifier_call_chain(rdev, event, data); in regulator_notifier_call_chain()
3480 struct regulator_dev *rdev = container_of(dev, struct regulator_dev, dev); in regulator_attr_is_visible() local
3481 const struct regulator_ops *ops = rdev->desc->ops; in regulator_attr_is_visible()
3492 if ((ops->get_voltage && ops->get_voltage(rdev) >= 0) || in regulator_attr_is_visible()
3493 (ops->get_voltage_sel && ops->get_voltage_sel(rdev) >= 0) || in regulator_attr_is_visible()
3494 (ops->list_voltage && ops->list_voltage(rdev, 0) >= 0) || in regulator_attr_is_visible()
3495 (rdev->desc->fixed_uV && rdev->desc->n_voltages == 1)) in regulator_attr_is_visible()
3507 return (rdev->ena_pin || ops->is_enabled) ? mode : 0; in regulator_attr_is_visible()
3517 return rdev->desc->type == REGULATOR_CURRENT ? mode : 0; in regulator_attr_is_visible()
3558 struct regulator_dev *rdev = dev_get_drvdata(dev); in regulator_dev_release() local
3559 kfree(rdev); in regulator_dev_release()
3568 static void rdev_init_debugfs(struct regulator_dev *rdev) in rdev_init_debugfs() argument
3570 struct device *parent = rdev->dev.parent; in rdev_init_debugfs()
3571 const char *rname = rdev_get_name(rdev); in rdev_init_debugfs()
3575 if (parent && rname == rdev->desc->name) { in rdev_init_debugfs()
3581 rdev->debugfs = debugfs_create_dir(rname, debugfs_root); in rdev_init_debugfs()
3582 if (!rdev->debugfs) { in rdev_init_debugfs()
3583 rdev_warn(rdev, "Failed to create debugfs directory\n"); in rdev_init_debugfs()
3587 debugfs_create_u32("use_count", 0444, rdev->debugfs, in rdev_init_debugfs()
3588 &rdev->use_count); in rdev_init_debugfs()
3589 debugfs_create_u32("open_count", 0444, rdev->debugfs, in rdev_init_debugfs()
3590 &rdev->open_count); in rdev_init_debugfs()
3591 debugfs_create_u32("bypass_count", 0444, rdev->debugfs, in rdev_init_debugfs()
3592 &rdev->bypass_count); in rdev_init_debugfs()
3617 struct regulator_dev *rdev; in regulator_register() local
3650 rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); in regulator_register()
3651 if (rdev == NULL) in regulator_register()
3660 kfree(rdev); in regulator_register()
3665 &rdev->dev.of_node); in regulator_register()
3668 rdev->dev.of_node = of_node_get(config->of_node); in regulator_register()
3673 mutex_init(&rdev->mutex); in regulator_register()
3674 rdev->reg_data = config->driver_data; in regulator_register()
3675 rdev->owner = regulator_desc->owner; in regulator_register()
3676 rdev->desc = regulator_desc; in regulator_register()
3678 rdev->regmap = config->regmap; in regulator_register()
3680 rdev->regmap = dev_get_regmap(dev, NULL); in regulator_register()
3682 rdev->regmap = dev_get_regmap(dev->parent, NULL); in regulator_register()
3683 INIT_LIST_HEAD(&rdev->consumer_list); in regulator_register()
3684 INIT_LIST_HEAD(&rdev->list); in regulator_register()
3685 BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier); in regulator_register()
3686 INIT_DELAYED_WORK(&rdev->disable_work, regulator_disable_work); in regulator_register()
3690 ret = init_data->regulator_init(rdev->reg_data); in regulator_register()
3696 rdev->dev.class = ®ulator_class; in regulator_register()
3697 rdev->dev.parent = dev; in regulator_register()
3698 dev_set_name(&rdev->dev, "regulator.%lu", in regulator_register()
3700 ret = device_register(&rdev->dev); in regulator_register()
3702 put_device(&rdev->dev); in regulator_register()
3706 dev_set_drvdata(&rdev->dev, rdev); in regulator_register()
3710 ret = regulator_ena_gpio_request(rdev, config); in regulator_register()
3712 rdev_err(rdev, "Failed to request enable GPIO%d: %d\n", in regulator_register()
3722 ret = set_machine_constraints(rdev, constraints); in regulator_register()
3727 rdev->supply_name = init_data->supply_regulator; in regulator_register()
3729 rdev->supply_name = regulator_desc->supply_name; in regulator_register()
3734 ret = set_consumer_device_supply(rdev, in regulator_register()
3745 list_add(&rdev->list, ®ulator_list); in regulator_register()
3747 rdev_init_debugfs(rdev); in regulator_register()
3755 return rdev; in regulator_register()
3758 unset_regulator_supplies(rdev); in regulator_register()
3761 regulator_ena_gpio_free(rdev); in regulator_register()
3762 kfree(rdev->constraints); in regulator_register()
3764 device_unregister(&rdev->dev); in regulator_register()
3766 rdev = ERR_PTR(ret); in regulator_register()
3770 kfree(rdev); in regulator_register()
3771 rdev = ERR_PTR(ret); in regulator_register()
3782 void regulator_unregister(struct regulator_dev *rdev) in regulator_unregister() argument
3784 if (rdev == NULL) in regulator_unregister()
3787 if (rdev->supply) { in regulator_unregister()
3788 while (rdev->use_count--) in regulator_unregister()
3789 regulator_disable(rdev->supply); in regulator_unregister()
3790 regulator_put(rdev->supply); in regulator_unregister()
3793 debugfs_remove_recursive(rdev->debugfs); in regulator_unregister()
3794 flush_work(&rdev->disable_work.work); in regulator_unregister()
3795 WARN_ON(rdev->open_count); in regulator_unregister()
3796 unset_regulator_supplies(rdev); in regulator_unregister()
3797 list_del(&rdev->list); in regulator_unregister()
3798 kfree(rdev->constraints); in regulator_unregister()
3799 regulator_ena_gpio_free(rdev); in regulator_unregister()
3800 of_node_put(rdev->dev.of_node); in regulator_unregister()
3801 device_unregister(&rdev->dev); in regulator_unregister()
3815 struct regulator_dev *rdev; in regulator_suspend_prepare() local
3823 list_for_each_entry(rdev, ®ulator_list, list) { in regulator_suspend_prepare()
3825 mutex_lock(&rdev->mutex); in regulator_suspend_prepare()
3826 ret = suspend_prepare(rdev, state); in regulator_suspend_prepare()
3827 mutex_unlock(&rdev->mutex); in regulator_suspend_prepare()
3830 rdev_err(rdev, "failed to prepare\n"); in regulator_suspend_prepare()
3848 struct regulator_dev *rdev; in regulator_suspend_finish() local
3852 list_for_each_entry(rdev, ®ulator_list, list) { in regulator_suspend_finish()
3853 mutex_lock(&rdev->mutex); in regulator_suspend_finish()
3854 if (rdev->use_count > 0 || rdev->constraints->always_on) { in regulator_suspend_finish()
3855 if (!_regulator_is_enabled(rdev)) { in regulator_suspend_finish()
3856 error = _regulator_do_enable(rdev); in regulator_suspend_finish()
3863 if (!_regulator_is_enabled(rdev)) in regulator_suspend_finish()
3866 error = _regulator_do_disable(rdev); in regulator_suspend_finish()
3871 mutex_unlock(&rdev->mutex); in regulator_suspend_finish()
3902 void *rdev_get_drvdata(struct regulator_dev *rdev) in rdev_get_drvdata() argument
3904 return rdev->reg_data; in rdev_get_drvdata()
3917 return regulator->rdev->reg_data; in regulator_get_drvdata()
3928 regulator->rdev->reg_data = data; in regulator_set_drvdata()
3936 int rdev_get_id(struct regulator_dev *rdev) in rdev_get_id() argument
3938 return rdev->desc->id; in rdev_get_id()
3942 struct device *rdev_get_dev(struct regulator_dev *rdev) in rdev_get_dev() argument
3944 return &rdev->dev; in rdev_get_dev()
3995 struct regulator_dev *rdev, in regulator_summary_show_subtree() argument
4003 if (!rdev) in regulator_summary_show_subtree()
4008 30 - level * 3, rdev_get_name(rdev), in regulator_summary_show_subtree()
4009 rdev->use_count, rdev->open_count, rdev->bypass_count); in regulator_summary_show_subtree()
4011 seq_printf(s, "%5dmV ", _regulator_get_voltage(rdev) / 1000); in regulator_summary_show_subtree()
4012 seq_printf(s, "%5dmA ", _regulator_get_current_limit(rdev) / 1000); in regulator_summary_show_subtree()
4014 c = rdev->constraints; in regulator_summary_show_subtree()
4016 switch (rdev->desc->type) { in regulator_summary_show_subtree()
4030 list_for_each_entry(consumer, &rdev->consumer_list, list) { in regulator_summary_show_subtree()
4038 switch (rdev->desc->type) { in regulator_summary_show_subtree()
4053 if (!child->supply || child->supply->rdev != rdev) in regulator_summary_show_subtree()
4063 struct regulator_dev *rdev; in regulator_summary_show() local
4070 list_for_each_entry(rdev, list, list) { in regulator_summary_show()
4071 if (rdev->supply) in regulator_summary_show()
4074 regulator_summary_show_subtree(s, rdev, 0); in regulator_summary_show()
4123 struct regulator_dev *rdev = dev_to_rdev(dev); in regulator_late_cleanup() local
4124 const struct regulator_ops *ops = rdev->desc->ops; in regulator_late_cleanup()
4125 struct regulation_constraints *c = rdev->constraints; in regulator_late_cleanup()
4134 mutex_lock(&rdev->mutex); in regulator_late_cleanup()
4136 if (rdev->use_count) in regulator_late_cleanup()
4141 enabled = ops->is_enabled(rdev); in regulator_late_cleanup()
4151 rdev_info(rdev, "disabling\n"); in regulator_late_cleanup()
4152 ret = _regulator_do_disable(rdev); in regulator_late_cleanup()
4154 rdev_err(rdev, "couldn't disable: %d\n", ret); in regulator_late_cleanup()
4161 rdev_warn(rdev, "incomplete constraints, leaving on\n"); in regulator_late_cleanup()
4165 mutex_unlock(&rdev->mutex); in regulator_late_cleanup()