2 * core.c -- Voltage/Current Regulator framework.
4 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
5 * Copyright 2008 SlimLogic Ltd.
7 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/device.h>
19 #include <linux/slab.h>
20 #include <linux/err.h>
21 #include <linux/mutex.h>
22 #include <linux/suspend.h>
23 #include <linux/delay.h>
24 #include <linux/regulator/consumer.h>
25 #include <linux/regulator/driver.h>
26 #include <linux/regulator/machine.h>
27 #ifdef CONFIG_DEBUG_FS
28 #include <linux/debugfs.h>
33 #define REGULATOR_VERSION "0.5"
35 static DEFINE_MUTEX(regulator_list_mutex);
36 static LIST_HEAD(regulator_list);
37 static LIST_HEAD(regulator_map_list);
38 static int has_full_constraints;
41 * struct regulator_map
43 * Used to provide symbolic supply names to devices.
45 struct regulator_map {
46 struct list_head list;
47 const char *dev_name; /* The dev_name() for the consumer */
49 struct regulator_dev *regulator;
55 * One for each consumer device.
59 struct list_head list;
64 struct device_attribute dev_attr;
65 struct regulator_dev *rdev;
68 static int _regulator_is_enabled(struct regulator_dev *rdev);
69 static int _regulator_disable(struct regulator_dev *rdev);
70 static int _regulator_get_voltage(struct regulator_dev *rdev);
71 static int _regulator_get_current_limit(struct regulator_dev *rdev);
72 static unsigned int _regulator_get_mode(struct regulator_dev *rdev);
73 static void _notifier_call_chain(struct regulator_dev *rdev,
74 unsigned long event, void *data);
76 static const char *rdev_get_name(struct regulator_dev *rdev)
78 if (rdev->constraints && rdev->constraints->name)
79 return rdev->constraints->name;
80 else if (rdev->desc->name)
81 return rdev->desc->name;
86 /* gets the regulator for a given consumer device */
87 static struct regulator *get_device_regulator(struct device *dev)
89 struct regulator *regulator = NULL;
90 struct regulator_dev *rdev;
92 mutex_lock(®ulator_list_mutex);
93 list_for_each_entry(rdev, ®ulator_list, list) {
94 mutex_lock(&rdev->mutex);
95 list_for_each_entry(regulator, &rdev->consumer_list, list) {
96 if (regulator->dev == dev) {
97 mutex_unlock(&rdev->mutex);
98 mutex_unlock(®ulator_list_mutex);
102 mutex_unlock(&rdev->mutex);
104 mutex_unlock(®ulator_list_mutex);
108 /* Platform voltage constraint check */
109 static int regulator_check_voltage(struct regulator_dev *rdev,
110 int *min_uV, int *max_uV)
112 BUG_ON(*min_uV > *max_uV);
114 if (!rdev->constraints) {
115 printk(KERN_ERR "%s: no constraints for %s\n", __func__,
116 rdev_get_name(rdev));
119 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) {
120 printk(KERN_ERR "%s: operation not allowed for %s\n",
121 __func__, rdev_get_name(rdev));
125 if (*max_uV > rdev->constraints->max_uV)
126 *max_uV = rdev->constraints->max_uV;
127 if (*min_uV < rdev->constraints->min_uV)
128 *min_uV = rdev->constraints->min_uV;
130 if (*min_uV > *max_uV)
136 /* current constraint check */
137 static int regulator_check_current_limit(struct regulator_dev *rdev,
138 int *min_uA, int *max_uA)
140 BUG_ON(*min_uA > *max_uA);
142 if (!rdev->constraints) {
143 printk(KERN_ERR "%s: no constraints for %s\n", __func__,
144 rdev_get_name(rdev));
147 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) {
148 printk(KERN_ERR "%s: operation not allowed for %s\n",
149 __func__, rdev_get_name(rdev));
153 if (*max_uA > rdev->constraints->max_uA)
154 *max_uA = rdev->constraints->max_uA;
155 if (*min_uA < rdev->constraints->min_uA)
156 *min_uA = rdev->constraints->min_uA;
158 if (*min_uA > *max_uA)
164 /* operating mode constraint check */
165 static int regulator_check_mode(struct regulator_dev *rdev, int mode)
168 case REGULATOR_MODE_FAST:
169 case REGULATOR_MODE_NORMAL:
170 case REGULATOR_MODE_IDLE:
171 case REGULATOR_MODE_STANDBY:
177 if (!rdev->constraints) {
178 printk(KERN_ERR "%s: no constraints for %s\n", __func__,
179 rdev_get_name(rdev));
182 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) {
183 printk(KERN_ERR "%s: operation not allowed for %s\n",
184 __func__, rdev_get_name(rdev));
187 if (!(rdev->constraints->valid_modes_mask & mode)) {
188 printk(KERN_ERR "%s: invalid mode %x for %s\n",
189 __func__, mode, rdev_get_name(rdev));
195 /* dynamic regulator mode switching constraint check */
196 static int regulator_check_drms(struct regulator_dev *rdev)
198 if (!rdev->constraints) {
199 printk(KERN_ERR "%s: no constraints for %s\n", __func__,
200 rdev_get_name(rdev));
203 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) {
204 printk(KERN_ERR "%s: operation not allowed for %s\n",
205 __func__, rdev_get_name(rdev));
211 static ssize_t device_requested_uA_show(struct device *dev,
212 struct device_attribute *attr, char *buf)
214 struct regulator *regulator;
216 regulator = get_device_regulator(dev);
217 if (regulator == NULL)
220 return sprintf(buf, "%d\n", regulator->uA_load);
223 static ssize_t regulator_uV_show(struct device *dev,
224 struct device_attribute *attr, char *buf)
226 struct regulator_dev *rdev = dev_get_drvdata(dev);
229 mutex_lock(&rdev->mutex);
230 ret = sprintf(buf, "%d\n", _regulator_get_voltage(rdev));
231 mutex_unlock(&rdev->mutex);
235 static DEVICE_ATTR(microvolts, 0444, regulator_uV_show, NULL);
237 static ssize_t regulator_uA_show(struct device *dev,
238 struct device_attribute *attr, char *buf)
240 struct regulator_dev *rdev = dev_get_drvdata(dev);
242 return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev));
244 static DEVICE_ATTR(microamps, 0444, regulator_uA_show, NULL);
246 static ssize_t regulator_name_show(struct device *dev,
247 struct device_attribute *attr, char *buf)
249 struct regulator_dev *rdev = dev_get_drvdata(dev);
251 return sprintf(buf, "%s\n", rdev_get_name(rdev));
254 static ssize_t regulator_print_opmode(char *buf, int mode)
257 case REGULATOR_MODE_FAST:
258 return sprintf(buf, "fast\n");
259 case REGULATOR_MODE_NORMAL:
260 return sprintf(buf, "normal\n");
261 case REGULATOR_MODE_IDLE:
262 return sprintf(buf, "idle\n");
263 case REGULATOR_MODE_STANDBY:
264 return sprintf(buf, "standby\n");
266 return sprintf(buf, "unknown\n");
269 static ssize_t regulator_opmode_show(struct device *dev,
270 struct device_attribute *attr, char *buf)
272 struct regulator_dev *rdev = dev_get_drvdata(dev);
274 return regulator_print_opmode(buf, _regulator_get_mode(rdev));
276 static DEVICE_ATTR(opmode, 0444, regulator_opmode_show, NULL);
278 static ssize_t regulator_print_state(char *buf, int state)
281 return sprintf(buf, "enabled\n");
283 return sprintf(buf, "disabled\n");
285 return sprintf(buf, "unknown\n");
288 static ssize_t regulator_state_show(struct device *dev,
289 struct device_attribute *attr, char *buf)
291 struct regulator_dev *rdev = dev_get_drvdata(dev);
294 mutex_lock(&rdev->mutex);
295 ret = regulator_print_state(buf, _regulator_is_enabled(rdev));
296 mutex_unlock(&rdev->mutex);
300 static DEVICE_ATTR(state, 0444, regulator_state_show, NULL);
302 static ssize_t regulator_status_show(struct device *dev,
303 struct device_attribute *attr, char *buf)
305 struct regulator_dev *rdev = dev_get_drvdata(dev);
309 status = rdev->desc->ops->get_status(rdev);
314 case REGULATOR_STATUS_OFF:
317 case REGULATOR_STATUS_ON:
320 case REGULATOR_STATUS_ERROR:
323 case REGULATOR_STATUS_FAST:
326 case REGULATOR_STATUS_NORMAL:
329 case REGULATOR_STATUS_IDLE:
332 case REGULATOR_STATUS_STANDBY:
339 return sprintf(buf, "%s\n", label);
341 static DEVICE_ATTR(status, 0444, regulator_status_show, NULL);
343 static ssize_t regulator_min_uA_show(struct device *dev,
344 struct device_attribute *attr, char *buf)
346 struct regulator_dev *rdev = dev_get_drvdata(dev);
348 if (!rdev->constraints)
349 return sprintf(buf, "constraint not defined\n");
351 return sprintf(buf, "%d\n", rdev->constraints->min_uA);
353 static DEVICE_ATTR(min_microamps, 0444, regulator_min_uA_show, NULL);
355 static ssize_t regulator_max_uA_show(struct device *dev,
356 struct device_attribute *attr, char *buf)
358 struct regulator_dev *rdev = dev_get_drvdata(dev);
360 if (!rdev->constraints)
361 return sprintf(buf, "constraint not defined\n");
363 return sprintf(buf, "%d\n", rdev->constraints->max_uA);
365 static DEVICE_ATTR(max_microamps, 0444, regulator_max_uA_show, NULL);
367 static ssize_t regulator_min_uV_show(struct device *dev,
368 struct device_attribute *attr, char *buf)
370 struct regulator_dev *rdev = dev_get_drvdata(dev);
372 if (!rdev->constraints)
373 return sprintf(buf, "constraint not defined\n");
375 return sprintf(buf, "%d\n", rdev->constraints->min_uV);
377 static DEVICE_ATTR(min_microvolts, 0444, regulator_min_uV_show, NULL);
379 static ssize_t regulator_max_uV_show(struct device *dev,
380 struct device_attribute *attr, char *buf)
382 struct regulator_dev *rdev = dev_get_drvdata(dev);
384 if (!rdev->constraints)
385 return sprintf(buf, "constraint not defined\n");
387 return sprintf(buf, "%d\n", rdev->constraints->max_uV);
389 static DEVICE_ATTR(max_microvolts, 0444, regulator_max_uV_show, NULL);
391 static ssize_t regulator_total_uA_show(struct device *dev,
392 struct device_attribute *attr, char *buf)
394 struct regulator_dev *rdev = dev_get_drvdata(dev);
395 struct regulator *regulator;
398 mutex_lock(&rdev->mutex);
399 list_for_each_entry(regulator, &rdev->consumer_list, list)
400 uA += regulator->uA_load;
401 mutex_unlock(&rdev->mutex);
402 return sprintf(buf, "%d\n", uA);
404 static DEVICE_ATTR(requested_microamps, 0444, regulator_total_uA_show, NULL);
406 static ssize_t regulator_num_users_show(struct device *dev,
407 struct device_attribute *attr, char *buf)
409 struct regulator_dev *rdev = dev_get_drvdata(dev);
410 return sprintf(buf, "%d\n", rdev->use_count);
413 static ssize_t regulator_type_show(struct device *dev,
414 struct device_attribute *attr, char *buf)
416 struct regulator_dev *rdev = dev_get_drvdata(dev);
418 switch (rdev->desc->type) {
419 case REGULATOR_VOLTAGE:
420 return sprintf(buf, "voltage\n");
421 case REGULATOR_CURRENT:
422 return sprintf(buf, "current\n");
424 return sprintf(buf, "unknown\n");
427 static ssize_t regulator_suspend_mem_uV_show(struct device *dev,
428 struct device_attribute *attr, char *buf)
430 struct regulator_dev *rdev = dev_get_drvdata(dev);
432 return sprintf(buf, "%d\n", rdev->constraints->state_mem.uV);
434 static DEVICE_ATTR(suspend_mem_microvolts, 0444,
435 regulator_suspend_mem_uV_show, NULL);
437 static ssize_t regulator_suspend_disk_uV_show(struct device *dev,
438 struct device_attribute *attr, char *buf)
440 struct regulator_dev *rdev = dev_get_drvdata(dev);
442 return sprintf(buf, "%d\n", rdev->constraints->state_disk.uV);
444 static DEVICE_ATTR(suspend_disk_microvolts, 0444,
445 regulator_suspend_disk_uV_show, NULL);
447 static ssize_t regulator_suspend_standby_uV_show(struct device *dev,
448 struct device_attribute *attr, char *buf)
450 struct regulator_dev *rdev = dev_get_drvdata(dev);
452 return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV);
454 static DEVICE_ATTR(suspend_standby_microvolts, 0444,
455 regulator_suspend_standby_uV_show, NULL);
457 static ssize_t regulator_suspend_mem_mode_show(struct device *dev,
458 struct device_attribute *attr, char *buf)
460 struct regulator_dev *rdev = dev_get_drvdata(dev);
462 return regulator_print_opmode(buf,
463 rdev->constraints->state_mem.mode);
465 static DEVICE_ATTR(suspend_mem_mode, 0444,
466 regulator_suspend_mem_mode_show, NULL);
468 static ssize_t regulator_suspend_disk_mode_show(struct device *dev,
469 struct device_attribute *attr, char *buf)
471 struct regulator_dev *rdev = dev_get_drvdata(dev);
473 return regulator_print_opmode(buf,
474 rdev->constraints->state_disk.mode);
476 static DEVICE_ATTR(suspend_disk_mode, 0444,
477 regulator_suspend_disk_mode_show, NULL);
479 static ssize_t regulator_suspend_standby_mode_show(struct device *dev,
480 struct device_attribute *attr, char *buf)
482 struct regulator_dev *rdev = dev_get_drvdata(dev);
484 return regulator_print_opmode(buf,
485 rdev->constraints->state_standby.mode);
487 static DEVICE_ATTR(suspend_standby_mode, 0444,
488 regulator_suspend_standby_mode_show, NULL);
490 static ssize_t regulator_suspend_mem_state_show(struct device *dev,
491 struct device_attribute *attr, char *buf)
493 struct regulator_dev *rdev = dev_get_drvdata(dev);
495 return regulator_print_state(buf,
496 rdev->constraints->state_mem.enabled);
498 static DEVICE_ATTR(suspend_mem_state, 0444,
499 regulator_suspend_mem_state_show, NULL);
501 static ssize_t regulator_suspend_disk_state_show(struct device *dev,
502 struct device_attribute *attr, char *buf)
504 struct regulator_dev *rdev = dev_get_drvdata(dev);
506 return regulator_print_state(buf,
507 rdev->constraints->state_disk.enabled);
509 static DEVICE_ATTR(suspend_disk_state, 0444,
510 regulator_suspend_disk_state_show, NULL);
512 static ssize_t regulator_suspend_standby_state_show(struct device *dev,
513 struct device_attribute *attr, char *buf)
515 struct regulator_dev *rdev = dev_get_drvdata(dev);
517 return regulator_print_state(buf,
518 rdev->constraints->state_standby.enabled);
520 static DEVICE_ATTR(suspend_standby_state, 0444,
521 regulator_suspend_standby_state_show, NULL);
525 * These are the only attributes are present for all regulators.
526 * Other attributes are a function of regulator functionality.
528 static struct device_attribute regulator_dev_attrs[] = {
529 __ATTR(name, 0444, regulator_name_show, NULL),
530 __ATTR(num_users, 0444, regulator_num_users_show, NULL),
531 __ATTR(type, 0444, regulator_type_show, NULL),
535 static void regulator_dev_release(struct device *dev)
537 struct regulator_dev *rdev = dev_get_drvdata(dev);
541 static struct class regulator_class = {
543 .dev_release = regulator_dev_release,
544 .dev_attrs = regulator_dev_attrs,
547 /* Calculate the new optimum regulator operating mode based on the new total
548 * consumer load. All locks held by caller */
549 static void drms_uA_update(struct regulator_dev *rdev)
551 struct regulator *sibling;
552 int current_uA = 0, output_uV, input_uV, err;
555 err = regulator_check_drms(rdev);
556 if (err < 0 || !rdev->desc->ops->get_optimum_mode ||
557 !rdev->desc->ops->get_voltage || !rdev->desc->ops->set_mode)
560 /* get output voltage */
561 output_uV = rdev->desc->ops->get_voltage(rdev);
565 /* get input voltage */
566 if (rdev->supply && rdev->supply->desc->ops->get_voltage)
567 input_uV = rdev->supply->desc->ops->get_voltage(rdev->supply);
569 input_uV = rdev->constraints->input_uV;
573 /* calc total requested load */
574 list_for_each_entry(sibling, &rdev->consumer_list, list)
575 current_uA += sibling->uA_load;
577 /* now get the optimum mode for our new total regulator load */
578 mode = rdev->desc->ops->get_optimum_mode(rdev, input_uV,
579 output_uV, current_uA);
581 /* check the new mode is allowed */
582 err = regulator_check_mode(rdev, mode);
584 rdev->desc->ops->set_mode(rdev, mode);
587 static int suspend_set_state(struct regulator_dev *rdev,
588 struct regulator_state *rstate)
593 can_set_state = rdev->desc->ops->set_suspend_enable &&
594 rdev->desc->ops->set_suspend_disable;
596 /* If we have no suspend mode configration don't set anything;
597 * only warn if the driver actually makes the suspend mode
600 if (!rstate->enabled && !rstate->disabled) {
602 printk(KERN_WARNING "%s: No configuration for %s\n",
603 __func__, rdev_get_name(rdev));
607 if (rstate->enabled && rstate->disabled) {
608 printk(KERN_ERR "%s: invalid configuration for %s\n",
609 __func__, rdev_get_name(rdev));
613 if (!can_set_state) {
614 printk(KERN_ERR "%s: no way to set suspend state\n",
620 ret = rdev->desc->ops->set_suspend_enable(rdev);
623 if (rdev->use_count > 0)
624 printk(KERN_ERR "%s: is still enabled.. please turn it"
625 " off before entering suspend (use_count"
626 " = %d)\n", rdev->desc->name,
628 ret = rdev->desc->ops->set_suspend_disable(rdev);
631 printk(KERN_ERR "%s: failed to enabled/disable\n", __func__);
635 if (rdev->desc->ops->set_suspend_voltage && rstate->uV > 0) {
636 ret = rdev->desc->ops->set_suspend_voltage(rdev, rstate->uV);
638 printk(KERN_ERR "%s: failed to set voltage\n",
644 if (rdev->desc->ops->set_suspend_mode && rstate->mode > 0) {
645 ret = rdev->desc->ops->set_suspend_mode(rdev, rstate->mode);
647 printk(KERN_ERR "%s: failed to set mode\n", __func__);
654 /* locks held by caller */
655 static int suspend_prepare(struct regulator_dev *rdev, suspend_state_t state)
657 if (!rdev->constraints)
661 case PM_SUSPEND_STANDBY:
662 return suspend_set_state(rdev,
663 &rdev->constraints->state_standby);
665 return suspend_set_state(rdev,
666 &rdev->constraints->state_mem);
668 return suspend_set_state(rdev,
669 &rdev->constraints->state_disk);
675 static void print_constraints(struct regulator_dev *rdev)
677 struct regulation_constraints *constraints = rdev->constraints;
682 if (constraints->min_uV && constraints->max_uV) {
683 if (constraints->min_uV == constraints->max_uV)
684 count += sprintf(buf + count, "%d mV ",
685 constraints->min_uV / 1000);
687 count += sprintf(buf + count, "%d <--> %d mV ",
688 constraints->min_uV / 1000,
689 constraints->max_uV / 1000);
692 if (!constraints->min_uV ||
693 constraints->min_uV != constraints->max_uV) {
694 ret = _regulator_get_voltage(rdev);
696 count += sprintf(buf + count, "at %d mV ", ret / 1000);
699 if (constraints->min_uA && constraints->max_uA) {
700 if (constraints->min_uA == constraints->max_uA)
701 count += sprintf(buf + count, "%d mA ",
702 constraints->min_uA / 1000);
704 count += sprintf(buf + count, "%d <--> %d mA ",
705 constraints->min_uA / 1000,
706 constraints->max_uA / 1000);
709 if (!constraints->min_uA ||
710 constraints->min_uA != constraints->max_uA) {
711 ret = _regulator_get_current_limit(rdev);
713 count += sprintf(buf + count, "at %d mA ", ret / 1000);
716 if (constraints->valid_modes_mask & REGULATOR_MODE_FAST)
717 count += sprintf(buf + count, "fast ");
718 if (constraints->valid_modes_mask & REGULATOR_MODE_NORMAL)
719 count += sprintf(buf + count, "normal ");
720 if (constraints->valid_modes_mask & REGULATOR_MODE_IDLE)
721 count += sprintf(buf + count, "idle ");
722 if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY)
723 count += sprintf(buf + count, "standby");
725 printk(KERN_INFO "regulator: %s: %s\n", rdev_get_name(rdev), buf);
728 static int machine_constraints_voltage(struct regulator_dev *rdev,
729 struct regulation_constraints *constraints)
731 struct regulator_ops *ops = rdev->desc->ops;
732 const char *name = rdev_get_name(rdev);
735 /* do we need to apply the constraint voltage */
736 if (rdev->constraints->apply_uV &&
737 rdev->constraints->min_uV == rdev->constraints->max_uV &&
739 ret = ops->set_voltage(rdev,
740 rdev->constraints->min_uV, rdev->constraints->max_uV);
742 printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n",
744 rdev->constraints->min_uV, name);
745 rdev->constraints = NULL;
750 /* constrain machine-level voltage specs to fit
751 * the actual range supported by this regulator.
753 if (ops->list_voltage && rdev->desc->n_voltages) {
754 int count = rdev->desc->n_voltages;
756 int min_uV = INT_MAX;
757 int max_uV = INT_MIN;
758 int cmin = constraints->min_uV;
759 int cmax = constraints->max_uV;
761 /* it's safe to autoconfigure fixed-voltage supplies
762 and the constraints are used by list_voltage. */
763 if (count == 1 && !cmin) {
766 constraints->min_uV = cmin;
767 constraints->max_uV = cmax;
770 /* voltage constraints are optional */
771 if ((cmin == 0) && (cmax == 0))
774 /* else require explicit machine-level constraints */
775 if (cmin <= 0 || cmax <= 0 || cmax < cmin) {
776 pr_err("%s: %s '%s' voltage constraints\n",
777 __func__, "invalid", name);
781 /* initial: [cmin..cmax] valid, [min_uV..max_uV] not */
782 for (i = 0; i < count; i++) {
785 value = ops->list_voltage(rdev, i);
789 /* maybe adjust [min_uV..max_uV] */
790 if (value >= cmin && value < min_uV)
792 if (value <= cmax && value > max_uV)
796 /* final: [min_uV..max_uV] valid iff constraints valid */
797 if (max_uV < min_uV) {
798 pr_err("%s: %s '%s' voltage constraints\n",
799 __func__, "unsupportable", name);
803 /* use regulator's subset of machine constraints */
804 if (constraints->min_uV < min_uV) {
805 pr_debug("%s: override '%s' %s, %d -> %d\n",
806 __func__, name, "min_uV",
807 constraints->min_uV, min_uV);
808 constraints->min_uV = min_uV;
810 if (constraints->max_uV > max_uV) {
811 pr_debug("%s: override '%s' %s, %d -> %d\n",
812 __func__, name, "max_uV",
813 constraints->max_uV, max_uV);
814 constraints->max_uV = max_uV;
822 * set_machine_constraints - sets regulator constraints
823 * @rdev: regulator source
824 * @constraints: constraints to apply
826 * Allows platform initialisation code to define and constrain
827 * regulator circuits e.g. valid voltage/current ranges, etc. NOTE:
828 * Constraints *must* be set by platform code in order for some
829 * regulator operations to proceed i.e. set_voltage, set_current_limit,
832 static int set_machine_constraints(struct regulator_dev *rdev,
833 struct regulation_constraints *constraints)
837 struct regulator_ops *ops = rdev->desc->ops;
839 rdev->constraints = constraints;
841 name = rdev_get_name(rdev);
843 ret = machine_constraints_voltage(rdev, constraints);
847 /* do we need to setup our suspend state */
848 if (constraints->initial_state) {
849 ret = suspend_prepare(rdev, constraints->initial_state);
851 printk(KERN_ERR "%s: failed to set suspend state for %s\n",
853 rdev->constraints = NULL;
858 if (constraints->initial_mode) {
859 if (!ops->set_mode) {
860 printk(KERN_ERR "%s: no set_mode operation for %s\n",
866 ret = ops->set_mode(rdev, constraints->initial_mode);
869 "%s: failed to set initial mode for %s: %d\n",
870 __func__, name, ret);
875 /* If the constraints say the regulator should be on at this point
876 * and we have control then make sure it is enabled.
878 if ((constraints->always_on || constraints->boot_on) && ops->enable) {
879 ret = ops->enable(rdev);
881 printk(KERN_ERR "%s: failed to enable %s\n",
883 rdev->constraints = NULL;
888 print_constraints(rdev);
894 * set_supply - set regulator supply regulator
895 * @rdev: regulator name
896 * @supply_rdev: supply regulator name
898 * Called by platform initialisation code to set the supply regulator for this
899 * regulator. This ensures that a regulators supply will also be enabled by the
900 * core if it's child is enabled.
902 static int set_supply(struct regulator_dev *rdev,
903 struct regulator_dev *supply_rdev)
907 err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj,
911 "%s: could not add device link %s err %d\n",
912 __func__, supply_rdev->dev.kobj.name, err);
915 rdev->supply = supply_rdev;
916 list_add(&rdev->slist, &supply_rdev->supply_list);
922 * set_consumer_device_supply: Bind a regulator to a symbolic supply
923 * @rdev: regulator source
924 * @consumer_dev: device the supply applies to
925 * @consumer_dev_name: dev_name() string for device supply applies to
926 * @supply: symbolic name for supply
928 * Allows platform initialisation code to map physical regulator
929 * sources to symbolic names for supplies for use by devices. Devices
930 * should use these symbolic names to request regulators, avoiding the
931 * need to provide board-specific regulator names as platform data.
933 * Only one of consumer_dev and consumer_dev_name may be specified.
935 static int set_consumer_device_supply(struct regulator_dev *rdev,
936 struct device *consumer_dev, const char *consumer_dev_name,
939 struct regulator_map *node;
942 if (consumer_dev && consumer_dev_name)
945 if (!consumer_dev_name && consumer_dev)
946 consumer_dev_name = dev_name(consumer_dev);
951 if (consumer_dev_name != NULL)
956 list_for_each_entry(node, ®ulator_map_list, list) {
957 if (node->dev_name && consumer_dev_name) {
958 if (strcmp(node->dev_name, consumer_dev_name) != 0)
960 } else if (node->dev_name || consumer_dev_name) {
964 if (strcmp(node->supply, supply) != 0)
967 dev_dbg(consumer_dev, "%s/%s is '%s' supply; fail %s/%s\n",
968 dev_name(&node->regulator->dev),
969 node->regulator->desc->name,
971 dev_name(&rdev->dev), rdev_get_name(rdev));
975 node = kzalloc(sizeof(struct regulator_map), GFP_KERNEL);
979 node->regulator = rdev;
980 node->supply = supply;
983 node->dev_name = kstrdup(consumer_dev_name, GFP_KERNEL);
984 if (node->dev_name == NULL) {
990 list_add(&node->list, ®ulator_map_list);
994 static void unset_regulator_supplies(struct regulator_dev *rdev)
996 struct regulator_map *node, *n;
998 list_for_each_entry_safe(node, n, ®ulator_map_list, list) {
999 if (rdev == node->regulator) {
1000 list_del(&node->list);
1001 kfree(node->dev_name);
1007 #define REG_STR_SIZE 32
1009 static struct regulator *create_regulator(struct regulator_dev *rdev,
1011 const char *supply_name)
1013 struct regulator *regulator;
1014 char buf[REG_STR_SIZE];
1017 regulator = kzalloc(sizeof(*regulator), GFP_KERNEL);
1018 if (regulator == NULL)
1021 mutex_lock(&rdev->mutex);
1022 regulator->rdev = rdev;
1023 list_add(®ulator->list, &rdev->consumer_list);
1026 /* create a 'requested_microamps_name' sysfs entry */
1027 size = scnprintf(buf, REG_STR_SIZE, "microamps_requested_%s",
1029 if (size >= REG_STR_SIZE)
1032 regulator->dev = dev;
1033 sysfs_attr_init(®ulator->dev_attr.attr);
1034 regulator->dev_attr.attr.name = kstrdup(buf, GFP_KERNEL);
1035 if (regulator->dev_attr.attr.name == NULL)
1038 regulator->dev_attr.attr.mode = 0444;
1039 regulator->dev_attr.show = device_requested_uA_show;
1040 err = device_create_file(dev, ®ulator->dev_attr);
1042 printk(KERN_WARNING "%s: could not add regulator_dev"
1043 " load sysfs\n", __func__);
1047 /* also add a link to the device sysfs entry */
1048 size = scnprintf(buf, REG_STR_SIZE, "%s-%s",
1049 dev->kobj.name, supply_name);
1050 if (size >= REG_STR_SIZE)
1053 regulator->supply_name = kstrdup(buf, GFP_KERNEL);
1054 if (regulator->supply_name == NULL)
1057 err = sysfs_create_link(&rdev->dev.kobj, &dev->kobj,
1061 "%s: could not add device link %s err %d\n",
1062 __func__, dev->kobj.name, err);
1063 device_remove_file(dev, ®ulator->dev_attr);
1067 mutex_unlock(&rdev->mutex);
1070 kfree(regulator->supply_name);
1072 device_remove_file(regulator->dev, ®ulator->dev_attr);
1074 kfree(regulator->dev_attr.attr.name);
1076 list_del(®ulator->list);
1078 mutex_unlock(&rdev->mutex);
1082 static int _regulator_get_enable_time(struct regulator_dev *rdev)
1084 if (!rdev->desc->ops->enable_time)
1086 return rdev->desc->ops->enable_time(rdev);
1089 /* Internal regulator request function */
1090 static struct regulator *_regulator_get(struct device *dev, const char *id,
1093 struct regulator_dev *rdev;
1094 struct regulator_map *map;
1095 struct regulator *regulator = ERR_PTR(-ENODEV);
1096 const char *devname = NULL;
1100 printk(KERN_ERR "regulator: get() with no identifier\n");
1105 devname = dev_name(dev);
1107 mutex_lock(®ulator_list_mutex);
1109 list_for_each_entry(map, ®ulator_map_list, list) {
1110 /* If the mapping has a device set up it must match */
1111 if (map->dev_name &&
1112 (!devname || strcmp(map->dev_name, devname)))
1115 if (strcmp(map->supply, id) == 0) {
1116 rdev = map->regulator;
1121 #ifdef CONFIG_REGULATOR_DUMMY
1123 devname = "deviceless";
1125 /* If the board didn't flag that it was fully constrained then
1126 * substitute in a dummy regulator so consumers can continue.
1128 if (!has_full_constraints) {
1129 pr_warning("%s supply %s not found, using dummy regulator\n",
1131 rdev = dummy_regulator_rdev;
1136 mutex_unlock(®ulator_list_mutex);
1140 if (rdev->exclusive) {
1141 regulator = ERR_PTR(-EPERM);
1145 if (exclusive && rdev->open_count) {
1146 regulator = ERR_PTR(-EBUSY);
1150 if (!try_module_get(rdev->owner))
1153 regulator = create_regulator(rdev, dev, id);
1154 if (regulator == NULL) {
1155 regulator = ERR_PTR(-ENOMEM);
1156 module_put(rdev->owner);
1161 rdev->exclusive = 1;
1163 ret = _regulator_is_enabled(rdev);
1165 rdev->use_count = 1;
1167 rdev->use_count = 0;
1171 mutex_unlock(®ulator_list_mutex);
1177 * regulator_get - lookup and obtain a reference to a regulator.
1178 * @dev: device for regulator "consumer"
1179 * @id: Supply name or regulator ID.
1181 * Returns a struct regulator corresponding to the regulator producer,
1182 * or IS_ERR() condition containing errno.
1184 * Use of supply names configured via regulator_set_device_supply() is
1185 * strongly encouraged. It is recommended that the supply name used
1186 * should match the name used for the supply and/or the relevant
1187 * device pins in the datasheet.
1189 struct regulator *regulator_get(struct device *dev, const char *id)
1191 return _regulator_get(dev, id, 0);
1193 EXPORT_SYMBOL_GPL(regulator_get);
1196 * regulator_get_exclusive - obtain exclusive access to a regulator.
1197 * @dev: device for regulator "consumer"
1198 * @id: Supply name or regulator ID.
1200 * Returns a struct regulator corresponding to the regulator producer,
1201 * or IS_ERR() condition containing errno. Other consumers will be
1202 * unable to obtain this reference is held and the use count for the
1203 * regulator will be initialised to reflect the current state of the
1206 * This is intended for use by consumers which cannot tolerate shared
1207 * use of the regulator such as those which need to force the
1208 * regulator off for correct operation of the hardware they are
1211 * Use of supply names configured via regulator_set_device_supply() is
1212 * strongly encouraged. It is recommended that the supply name used
1213 * should match the name used for the supply and/or the relevant
1214 * device pins in the datasheet.
1216 struct regulator *regulator_get_exclusive(struct device *dev, const char *id)
1218 return _regulator_get(dev, id, 1);
1220 EXPORT_SYMBOL_GPL(regulator_get_exclusive);
1223 * regulator_put - "free" the regulator source
1224 * @regulator: regulator source
1226 * Note: drivers must ensure that all regulator_enable calls made on this
1227 * regulator source are balanced by regulator_disable calls prior to calling
1230 void regulator_put(struct regulator *regulator)
1232 struct regulator_dev *rdev;
1234 if (regulator == NULL || IS_ERR(regulator))
1237 mutex_lock(®ulator_list_mutex);
1238 rdev = regulator->rdev;
1240 /* remove any sysfs entries */
1241 if (regulator->dev) {
1242 sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name);
1243 kfree(regulator->supply_name);
1244 device_remove_file(regulator->dev, ®ulator->dev_attr);
1245 kfree(regulator->dev_attr.attr.name);
1247 list_del(®ulator->list);
1251 rdev->exclusive = 0;
1253 module_put(rdev->owner);
1254 mutex_unlock(®ulator_list_mutex);
1256 EXPORT_SYMBOL_GPL(regulator_put);
1258 static int _regulator_can_change_status(struct regulator_dev *rdev)
1260 if (!rdev->constraints)
1263 if (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_STATUS)
1269 /* locks held by regulator_enable() */
1270 static int _regulator_enable(struct regulator_dev *rdev)
1274 /* do we need to enable the supply regulator first */
1276 ret = _regulator_enable(rdev->supply);
1278 printk(KERN_ERR "%s: failed to enable %s: %d\n",
1279 __func__, rdev_get_name(rdev), ret);
1284 /* check voltage and requested load before enabling */
1285 if (rdev->constraints &&
1286 (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS))
1287 drms_uA_update(rdev);
1289 if (rdev->use_count == 0) {
1290 /* The regulator may on if it's not switchable or left on */
1291 ret = _regulator_is_enabled(rdev);
1292 if (ret == -EINVAL || ret == 0) {
1293 if (!_regulator_can_change_status(rdev))
1296 if (!rdev->desc->ops->enable)
1299 /* Query before enabling in case configuration
1301 ret = _regulator_get_enable_time(rdev);
1306 "%s: enable_time() failed for %s: %d\n",
1307 __func__, rdev_get_name(rdev),
1312 /* Allow the regulator to ramp; it would be useful
1313 * to extend this for bulk operations so that the
1314 * regulators can ramp together. */
1315 ret = rdev->desc->ops->enable(rdev);
1320 mdelay(delay / 1000);
1324 } else if (ret < 0) {
1325 printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n",
1326 __func__, rdev_get_name(rdev), ret);
1329 /* Fallthrough on positive return values - already enabled */
1338 * regulator_enable - enable regulator output
1339 * @regulator: regulator source
1341 * Request that the regulator be enabled with the regulator output at
1342 * the predefined voltage or current value. Calls to regulator_enable()
1343 * must be balanced with calls to regulator_disable().
1345 * NOTE: the output value can be set by other drivers, boot loader or may be
1346 * hardwired in the regulator.
1348 int regulator_enable(struct regulator *regulator)
1350 struct regulator_dev *rdev = regulator->rdev;
1353 mutex_lock(&rdev->mutex);
1354 ret = _regulator_enable(rdev);
1355 mutex_unlock(&rdev->mutex);
1358 EXPORT_SYMBOL_GPL(regulator_enable);
1360 /* locks held by regulator_disable() */
1361 static int _regulator_disable(struct regulator_dev *rdev)
1365 if (WARN(rdev->use_count <= 0,
1366 "unbalanced disables for %s\n",
1367 rdev_get_name(rdev)))
1370 /* are we the last user and permitted to disable ? */
1371 if (rdev->use_count == 1 &&
1372 (rdev->constraints && !rdev->constraints->always_on)) {
1374 /* we are last user */
1375 if (_regulator_can_change_status(rdev) &&
1376 rdev->desc->ops->disable) {
1377 ret = rdev->desc->ops->disable(rdev);
1379 printk(KERN_ERR "%s: failed to disable %s\n",
1380 __func__, rdev_get_name(rdev));
1384 _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE,
1388 /* decrease our supplies ref count and disable if required */
1390 _regulator_disable(rdev->supply);
1392 rdev->use_count = 0;
1393 } else if (rdev->use_count > 1) {
1395 if (rdev->constraints &&
1396 (rdev->constraints->valid_ops_mask &
1397 REGULATOR_CHANGE_DRMS))
1398 drms_uA_update(rdev);
1406 * regulator_disable - disable regulator output
1407 * @regulator: regulator source
1409 * Disable the regulator output voltage or current. Calls to
1410 * regulator_enable() must be balanced with calls to
1411 * regulator_disable().
1413 * NOTE: this will only disable the regulator output if no other consumer
1414 * devices have it enabled, the regulator device supports disabling and
1415 * machine constraints permit this operation.
1417 int regulator_disable(struct regulator *regulator)
1419 struct regulator_dev *rdev = regulator->rdev;
1422 mutex_lock(&rdev->mutex);
1423 ret = _regulator_disable(rdev);
1424 mutex_unlock(&rdev->mutex);
1427 EXPORT_SYMBOL_GPL(regulator_disable);
1429 /* locks held by regulator_force_disable() */
1430 static int _regulator_force_disable(struct regulator_dev *rdev)
1435 if (rdev->desc->ops->disable) {
1436 /* ah well, who wants to live forever... */
1437 ret = rdev->desc->ops->disable(rdev);
1439 printk(KERN_ERR "%s: failed to force disable %s\n",
1440 __func__, rdev_get_name(rdev));
1443 /* notify other consumers that power has been forced off */
1444 _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE |
1445 REGULATOR_EVENT_DISABLE, NULL);
1448 /* decrease our supplies ref count and disable if required */
1450 _regulator_disable(rdev->supply);
1452 rdev->use_count = 0;
1457 * regulator_force_disable - force disable regulator output
1458 * @regulator: regulator source
1460 * Forcibly disable the regulator output voltage or current.
1461 * NOTE: this *will* disable the regulator output even if other consumer
1462 * devices have it enabled. This should be used for situations when device
1463 * damage will likely occur if the regulator is not disabled (e.g. over temp).
1465 int regulator_force_disable(struct regulator *regulator)
1469 mutex_lock(®ulator->rdev->mutex);
1470 regulator->uA_load = 0;
1471 ret = _regulator_force_disable(regulator->rdev);
1472 mutex_unlock(®ulator->rdev->mutex);
1475 EXPORT_SYMBOL_GPL(regulator_force_disable);
1477 static int _regulator_is_enabled(struct regulator_dev *rdev)
1479 /* If we don't know then assume that the regulator is always on */
1480 if (!rdev->desc->ops->is_enabled)
1483 return rdev->desc->ops->is_enabled(rdev);
1487 * regulator_is_enabled - is the regulator output enabled
1488 * @regulator: regulator source
1490 * Returns positive if the regulator driver backing the source/client
1491 * has requested that the device be enabled, zero if it hasn't, else a
1492 * negative errno code.
1494 * Note that the device backing this regulator handle can have multiple
1495 * users, so it might be enabled even if regulator_enable() was never
1496 * called for this particular source.
1498 int regulator_is_enabled(struct regulator *regulator)
1502 mutex_lock(®ulator->rdev->mutex);
1503 ret = _regulator_is_enabled(regulator->rdev);
1504 mutex_unlock(®ulator->rdev->mutex);
1508 EXPORT_SYMBOL_GPL(regulator_is_enabled);
1511 * regulator_count_voltages - count regulator_list_voltage() selectors
1512 * @regulator: regulator source
1514 * Returns number of selectors, or negative errno. Selectors are
1515 * numbered starting at zero, and typically correspond to bitfields
1516 * in hardware registers.
1518 int regulator_count_voltages(struct regulator *regulator)
1520 struct regulator_dev *rdev = regulator->rdev;
1522 return rdev->desc->n_voltages ? : -EINVAL;
1524 EXPORT_SYMBOL_GPL(regulator_count_voltages);
1527 * regulator_list_voltage - enumerate supported voltages
1528 * @regulator: regulator source
1529 * @selector: identify voltage to list
1530 * Context: can sleep
1532 * Returns a voltage that can be passed to @regulator_set_voltage(),
1533 * zero if this selector code can't be used on this system, or a
1536 int regulator_list_voltage(struct regulator *regulator, unsigned selector)
1538 struct regulator_dev *rdev = regulator->rdev;
1539 struct regulator_ops *ops = rdev->desc->ops;
1542 if (!ops->list_voltage || selector >= rdev->desc->n_voltages)
1545 mutex_lock(&rdev->mutex);
1546 ret = ops->list_voltage(rdev, selector);
1547 mutex_unlock(&rdev->mutex);
1550 if (ret < rdev->constraints->min_uV)
1552 else if (ret > rdev->constraints->max_uV)
1558 EXPORT_SYMBOL_GPL(regulator_list_voltage);
1561 * regulator_is_supported_voltage - check if a voltage range can be supported
1563 * @regulator: Regulator to check.
1564 * @min_uV: Minimum required voltage in uV.
1565 * @max_uV: Maximum required voltage in uV.
1567 * Returns a boolean or a negative error code.
1569 int regulator_is_supported_voltage(struct regulator *regulator,
1570 int min_uV, int max_uV)
1572 int i, voltages, ret;
1574 ret = regulator_count_voltages(regulator);
1579 for (i = 0; i < voltages; i++) {
1580 ret = regulator_list_voltage(regulator, i);
1582 if (ret >= min_uV && ret <= max_uV)
1590 * regulator_set_voltage - set regulator output voltage
1591 * @regulator: regulator source
1592 * @min_uV: Minimum required voltage in uV
1593 * @max_uV: Maximum acceptable voltage in uV
1595 * Sets a voltage regulator to the desired output voltage. This can be set
1596 * during any regulator state. IOW, regulator can be disabled or enabled.
1598 * If the regulator is enabled then the voltage will change to the new value
1599 * immediately otherwise if the regulator is disabled the regulator will
1600 * output at the new voltage when enabled.
1602 * NOTE: If the regulator is shared between several devices then the lowest
1603 * request voltage that meets the system constraints will be used.
1604 * Regulator system constraints must be set for this regulator before
1605 * calling this function otherwise this call will fail.
1607 int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
1609 struct regulator_dev *rdev = regulator->rdev;
1612 mutex_lock(&rdev->mutex);
1615 if (!rdev->desc->ops->set_voltage) {
1620 /* constraints check */
1621 ret = regulator_check_voltage(rdev, &min_uV, &max_uV);
1624 regulator->min_uV = min_uV;
1625 regulator->max_uV = max_uV;
1626 ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV);
1629 _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, NULL);
1630 mutex_unlock(&rdev->mutex);
1633 EXPORT_SYMBOL_GPL(regulator_set_voltage);
1635 static int _regulator_get_voltage(struct regulator_dev *rdev)
1638 if (rdev->desc->ops->get_voltage)
1639 return rdev->desc->ops->get_voltage(rdev);
1645 * regulator_get_voltage - get regulator output voltage
1646 * @regulator: regulator source
1648 * This returns the current regulator voltage in uV.
1650 * NOTE: If the regulator is disabled it will return the voltage value. This
1651 * function should not be used to determine regulator state.
1653 int regulator_get_voltage(struct regulator *regulator)
1657 mutex_lock(®ulator->rdev->mutex);
1659 ret = _regulator_get_voltage(regulator->rdev);
1661 mutex_unlock(®ulator->rdev->mutex);
1665 EXPORT_SYMBOL_GPL(regulator_get_voltage);
1668 * regulator_set_current_limit - set regulator output current limit
1669 * @regulator: regulator source
1670 * @min_uA: Minimuum supported current in uA
1671 * @max_uA: Maximum supported current in uA
1673 * Sets current sink to the desired output current. This can be set during
1674 * any regulator state. IOW, regulator can be disabled or enabled.
1676 * If the regulator is enabled then the current will change to the new value
1677 * immediately otherwise if the regulator is disabled the regulator will
1678 * output at the new current when enabled.
1680 * NOTE: Regulator system constraints must be set for this regulator before
1681 * calling this function otherwise this call will fail.
1683 int regulator_set_current_limit(struct regulator *regulator,
1684 int min_uA, int max_uA)
1686 struct regulator_dev *rdev = regulator->rdev;
1689 mutex_lock(&rdev->mutex);
1692 if (!rdev->desc->ops->set_current_limit) {
1697 /* constraints check */
1698 ret = regulator_check_current_limit(rdev, &min_uA, &max_uA);
1702 ret = rdev->desc->ops->set_current_limit(rdev, min_uA, max_uA);
1704 mutex_unlock(&rdev->mutex);
1707 EXPORT_SYMBOL_GPL(regulator_set_current_limit);
1709 static int _regulator_get_current_limit(struct regulator_dev *rdev)
1713 mutex_lock(&rdev->mutex);
1716 if (!rdev->desc->ops->get_current_limit) {
1721 ret = rdev->desc->ops->get_current_limit(rdev);
1723 mutex_unlock(&rdev->mutex);
1728 * regulator_get_current_limit - get regulator output current
1729 * @regulator: regulator source
1731 * This returns the current supplied by the specified current sink in uA.
1733 * NOTE: If the regulator is disabled it will return the current value. This
1734 * function should not be used to determine regulator state.
1736 int regulator_get_current_limit(struct regulator *regulator)
1738 return _regulator_get_current_limit(regulator->rdev);
1740 EXPORT_SYMBOL_GPL(regulator_get_current_limit);
1743 * regulator_set_mode - set regulator operating mode
1744 * @regulator: regulator source
1745 * @mode: operating mode - one of the REGULATOR_MODE constants
1747 * Set regulator operating mode to increase regulator efficiency or improve
1748 * regulation performance.
1750 * NOTE: Regulator system constraints must be set for this regulator before
1751 * calling this function otherwise this call will fail.
1753 int regulator_set_mode(struct regulator *regulator, unsigned int mode)
1755 struct regulator_dev *rdev = regulator->rdev;
1757 int regulator_curr_mode;
1759 mutex_lock(&rdev->mutex);
1762 if (!rdev->desc->ops->set_mode) {
1767 /* return if the same mode is requested */
1768 if (rdev->desc->ops->get_mode) {
1769 regulator_curr_mode = rdev->desc->ops->get_mode(rdev);
1770 if (regulator_curr_mode == mode) {
1776 /* constraints check */
1777 ret = regulator_check_mode(rdev, mode);
1781 ret = rdev->desc->ops->set_mode(rdev, mode);
1783 mutex_unlock(&rdev->mutex);
1786 EXPORT_SYMBOL_GPL(regulator_set_mode);
1788 static unsigned int _regulator_get_mode(struct regulator_dev *rdev)
1792 mutex_lock(&rdev->mutex);
1795 if (!rdev->desc->ops->get_mode) {
1800 ret = rdev->desc->ops->get_mode(rdev);
1802 mutex_unlock(&rdev->mutex);
1807 * regulator_get_mode - get regulator operating mode
1808 * @regulator: regulator source
1810 * Get the current regulator operating mode.
1812 unsigned int regulator_get_mode(struct regulator *regulator)
1814 return _regulator_get_mode(regulator->rdev);
1816 EXPORT_SYMBOL_GPL(regulator_get_mode);
1819 * regulator_set_optimum_mode - set regulator optimum operating mode
1820 * @regulator: regulator source
1821 * @uA_load: load current
1823 * Notifies the regulator core of a new device load. This is then used by
1824 * DRMS (if enabled by constraints) to set the most efficient regulator
1825 * operating mode for the new regulator loading.
1827 * Consumer devices notify their supply regulator of the maximum power
1828 * they will require (can be taken from device datasheet in the power
1829 * consumption tables) when they change operational status and hence power
1830 * state. Examples of operational state changes that can affect power
1831 * consumption are :-
1833 * o Device is opened / closed.
1834 * o Device I/O is about to begin or has just finished.
1835 * o Device is idling in between work.
1837 * This information is also exported via sysfs to userspace.
1839 * DRMS will sum the total requested load on the regulator and change
1840 * to the most efficient operating mode if platform constraints allow.
1842 * Returns the new regulator mode or error.
1844 int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
1846 struct regulator_dev *rdev = regulator->rdev;
1847 struct regulator *consumer;
1848 int ret, output_uV, input_uV, total_uA_load = 0;
1851 mutex_lock(&rdev->mutex);
1853 regulator->uA_load = uA_load;
1854 ret = regulator_check_drms(rdev);
1860 if (!rdev->desc->ops->get_optimum_mode)
1863 /* get output voltage */
1864 output_uV = rdev->desc->ops->get_voltage(rdev);
1865 if (output_uV <= 0) {
1866 printk(KERN_ERR "%s: invalid output voltage found for %s\n",
1867 __func__, rdev_get_name(rdev));
1871 /* get input voltage */
1872 if (rdev->supply && rdev->supply->desc->ops->get_voltage)
1873 input_uV = rdev->supply->desc->ops->get_voltage(rdev->supply);
1875 input_uV = rdev->constraints->input_uV;
1876 if (input_uV <= 0) {
1877 printk(KERN_ERR "%s: invalid input voltage found for %s\n",
1878 __func__, rdev_get_name(rdev));
1882 /* calc total requested load for this regulator */
1883 list_for_each_entry(consumer, &rdev->consumer_list, list)
1884 total_uA_load += consumer->uA_load;
1886 mode = rdev->desc->ops->get_optimum_mode(rdev,
1887 input_uV, output_uV,
1889 ret = regulator_check_mode(rdev, mode);
1891 printk(KERN_ERR "%s: failed to get optimum mode for %s @"
1892 " %d uA %d -> %d uV\n", __func__, rdev_get_name(rdev),
1893 total_uA_load, input_uV, output_uV);
1897 ret = rdev->desc->ops->set_mode(rdev, mode);
1899 printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n",
1900 __func__, mode, rdev_get_name(rdev));
1905 mutex_unlock(&rdev->mutex);
1908 EXPORT_SYMBOL_GPL(regulator_set_optimum_mode);
1911 * regulator_register_notifier - register regulator event notifier
1912 * @regulator: regulator source
1913 * @nb: notifier block
1915 * Register notifier block to receive regulator events.
1917 int regulator_register_notifier(struct regulator *regulator,
1918 struct notifier_block *nb)
1920 return blocking_notifier_chain_register(®ulator->rdev->notifier,
1923 EXPORT_SYMBOL_GPL(regulator_register_notifier);
1926 * regulator_unregister_notifier - unregister regulator event notifier
1927 * @regulator: regulator source
1928 * @nb: notifier block
1930 * Unregister regulator event notifier block.
1932 int regulator_unregister_notifier(struct regulator *regulator,
1933 struct notifier_block *nb)
1935 return blocking_notifier_chain_unregister(®ulator->rdev->notifier,
1938 EXPORT_SYMBOL_GPL(regulator_unregister_notifier);
1940 /* notify regulator consumers and downstream regulator consumers.
1941 * Note mutex must be held by caller.
1943 static void _notifier_call_chain(struct regulator_dev *rdev,
1944 unsigned long event, void *data)
1946 struct regulator_dev *_rdev;
1948 /* call rdev chain first */
1949 blocking_notifier_call_chain(&rdev->notifier, event, NULL);
1951 /* now notify regulator we supply */
1952 list_for_each_entry(_rdev, &rdev->supply_list, slist) {
1953 if (_rdev->supply == rdev)
1955 mutex_lock(&_rdev->mutex);
1956 _notifier_call_chain(_rdev, event, data);
1957 mutex_unlock(&_rdev->mutex);
1962 * regulator_bulk_get - get multiple regulator consumers
1964 * @dev: Device to supply
1965 * @num_consumers: Number of consumers to register
1966 * @consumers: Configuration of consumers; clients are stored here.
1968 * @return 0 on success, an errno on failure.
1970 * This helper function allows drivers to get several regulator
1971 * consumers in one operation. If any of the regulators cannot be
1972 * acquired then any regulators that were allocated will be freed
1973 * before returning to the caller.
1975 int regulator_bulk_get(struct device *dev, int num_consumers,
1976 struct regulator_bulk_data *consumers)
1981 for (i = 0; i < num_consumers; i++)
1982 consumers[i].consumer = NULL;
1984 for (i = 0; i < num_consumers; i++) {
1985 consumers[i].consumer = regulator_get(dev,
1986 consumers[i].supply);
1987 if (IS_ERR(consumers[i].consumer)) {
1988 ret = PTR_ERR(consumers[i].consumer);
1989 dev_err(dev, "Failed to get supply '%s': %d\n",
1990 consumers[i].supply, ret);
1991 consumers[i].consumer = NULL;
1999 for (i = 0; i < num_consumers && consumers[i].consumer; i++)
2000 regulator_put(consumers[i].consumer);
2004 EXPORT_SYMBOL_GPL(regulator_bulk_get);
2007 * regulator_bulk_enable - enable multiple regulator consumers
2009 * @num_consumers: Number of consumers
2010 * @consumers: Consumer data; clients are stored here.
2011 * @return 0 on success, an errno on failure
2013 * This convenience API allows consumers to enable multiple regulator
2014 * clients in a single API call. If any consumers cannot be enabled
2015 * then any others that were enabled will be disabled again prior to
2018 int regulator_bulk_enable(int num_consumers,
2019 struct regulator_bulk_data *consumers)
2024 for (i = 0; i < num_consumers; i++) {
2025 ret = regulator_enable(consumers[i].consumer);
2033 printk(KERN_ERR "Failed to enable %s: %d\n", consumers[i].supply, ret);
2034 for (--i; i >= 0; --i)
2035 regulator_disable(consumers[i].consumer);
2039 EXPORT_SYMBOL_GPL(regulator_bulk_enable);
2042 * regulator_bulk_disable - disable multiple regulator consumers
2044 * @num_consumers: Number of consumers
2045 * @consumers: Consumer data; clients are stored here.
2046 * @return 0 on success, an errno on failure
2048 * This convenience API allows consumers to disable multiple regulator
2049 * clients in a single API call. If any consumers cannot be enabled
2050 * then any others that were disabled will be enabled again prior to
2053 int regulator_bulk_disable(int num_consumers,
2054 struct regulator_bulk_data *consumers)
2059 for (i = num_consumers - 1; i >= 0; --i) {
2060 ret = regulator_disable(consumers[i].consumer);
2068 printk(KERN_ERR "Failed to disable %s: %d\n", consumers[i].supply,
2070 for (++i; i < num_consumers; ++i)
2071 regulator_enable(consumers[i].consumer);
2075 EXPORT_SYMBOL_GPL(regulator_bulk_disable);
2078 * regulator_bulk_free - free multiple regulator consumers
2080 * @num_consumers: Number of consumers
2081 * @consumers: Consumer data; clients are stored here.
2083 * This convenience API allows consumers to free multiple regulator
2084 * clients in a single API call.
2086 void regulator_bulk_free(int num_consumers,
2087 struct regulator_bulk_data *consumers)
2091 for (i = 0; i < num_consumers; i++) {
2092 regulator_put(consumers[i].consumer);
2093 consumers[i].consumer = NULL;
2096 EXPORT_SYMBOL_GPL(regulator_bulk_free);
2099 * regulator_notifier_call_chain - call regulator event notifier
2100 * @rdev: regulator source
2101 * @event: notifier block
2102 * @data: callback-specific data.
2104 * Called by regulator drivers to notify clients a regulator event has
2105 * occurred. We also notify regulator clients downstream.
2106 * Note lock must be held by caller.
2108 int regulator_notifier_call_chain(struct regulator_dev *rdev,
2109 unsigned long event, void *data)
2111 _notifier_call_chain(rdev, event, data);
2115 EXPORT_SYMBOL_GPL(regulator_notifier_call_chain);
2118 * regulator_mode_to_status - convert a regulator mode into a status
2120 * @mode: Mode to convert
2122 * Convert a regulator mode into a status.
2124 int regulator_mode_to_status(unsigned int mode)
2127 case REGULATOR_MODE_FAST:
2128 return REGULATOR_STATUS_FAST;
2129 case REGULATOR_MODE_NORMAL:
2130 return REGULATOR_STATUS_NORMAL;
2131 case REGULATOR_MODE_IDLE:
2132 return REGULATOR_STATUS_IDLE;
2133 case REGULATOR_STATUS_STANDBY:
2134 return REGULATOR_STATUS_STANDBY;
2139 EXPORT_SYMBOL_GPL(regulator_mode_to_status);
2142 * To avoid cluttering sysfs (and memory) with useless state, only
2143 * create attributes that can be meaningfully displayed.
2145 static int add_regulator_attributes(struct regulator_dev *rdev)
2147 struct device *dev = &rdev->dev;
2148 struct regulator_ops *ops = rdev->desc->ops;
2151 /* some attributes need specific methods to be displayed */
2152 if (ops->get_voltage) {
2153 status = device_create_file(dev, &dev_attr_microvolts);
2157 if (ops->get_current_limit) {
2158 status = device_create_file(dev, &dev_attr_microamps);
2162 if (ops->get_mode) {
2163 status = device_create_file(dev, &dev_attr_opmode);
2167 if (ops->is_enabled) {
2168 status = device_create_file(dev, &dev_attr_state);
2172 if (ops->get_status) {
2173 status = device_create_file(dev, &dev_attr_status);
2178 /* some attributes are type-specific */
2179 if (rdev->desc->type == REGULATOR_CURRENT) {
2180 status = device_create_file(dev, &dev_attr_requested_microamps);
2185 /* all the other attributes exist to support constraints;
2186 * don't show them if there are no constraints, or if the
2187 * relevant supporting methods are missing.
2189 if (!rdev->constraints)
2192 /* constraints need specific supporting methods */
2193 if (ops->set_voltage) {
2194 status = device_create_file(dev, &dev_attr_min_microvolts);
2197 status = device_create_file(dev, &dev_attr_max_microvolts);
2201 if (ops->set_current_limit) {
2202 status = device_create_file(dev, &dev_attr_min_microamps);
2205 status = device_create_file(dev, &dev_attr_max_microamps);
2210 /* suspend mode constraints need multiple supporting methods */
2211 if (!(ops->set_suspend_enable && ops->set_suspend_disable))
2214 status = device_create_file(dev, &dev_attr_suspend_standby_state);
2217 status = device_create_file(dev, &dev_attr_suspend_mem_state);
2220 status = device_create_file(dev, &dev_attr_suspend_disk_state);
2224 if (ops->set_suspend_voltage) {
2225 status = device_create_file(dev,
2226 &dev_attr_suspend_standby_microvolts);
2229 status = device_create_file(dev,
2230 &dev_attr_suspend_mem_microvolts);
2233 status = device_create_file(dev,
2234 &dev_attr_suspend_disk_microvolts);
2239 if (ops->set_suspend_mode) {
2240 status = device_create_file(dev,
2241 &dev_attr_suspend_standby_mode);
2244 status = device_create_file(dev,
2245 &dev_attr_suspend_mem_mode);
2248 status = device_create_file(dev,
2249 &dev_attr_suspend_disk_mode);
2258 * regulator_register - register regulator
2259 * @regulator_desc: regulator to register
2260 * @dev: struct device for the regulator
2261 * @init_data: platform provided init data, passed through by driver
2262 * @driver_data: private regulator data
2264 * Called by regulator drivers to register a regulator.
2265 * Returns 0 on success.
2267 struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
2268 struct device *dev, struct regulator_init_data *init_data,
2271 static atomic_t regulator_no = ATOMIC_INIT(0);
2272 struct regulator_dev *rdev;
2275 if (regulator_desc == NULL)
2276 return ERR_PTR(-EINVAL);
2278 if (regulator_desc->name == NULL || regulator_desc->ops == NULL)
2279 return ERR_PTR(-EINVAL);
2281 if (regulator_desc->type != REGULATOR_VOLTAGE &&
2282 regulator_desc->type != REGULATOR_CURRENT)
2283 return ERR_PTR(-EINVAL);
2286 return ERR_PTR(-EINVAL);
2288 rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL);
2290 return ERR_PTR(-ENOMEM);
2292 mutex_lock(®ulator_list_mutex);
2294 mutex_init(&rdev->mutex);
2295 rdev->reg_data = driver_data;
2296 rdev->owner = regulator_desc->owner;
2297 rdev->desc = regulator_desc;
2298 INIT_LIST_HEAD(&rdev->consumer_list);
2299 INIT_LIST_HEAD(&rdev->supply_list);
2300 INIT_LIST_HEAD(&rdev->list);
2301 INIT_LIST_HEAD(&rdev->slist);
2302 BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier);
2304 /* preform any regulator specific init */
2305 if (init_data->regulator_init) {
2306 ret = init_data->regulator_init(rdev->reg_data);
2311 /* register with sysfs */
2312 rdev->dev.class = ®ulator_class;
2313 rdev->dev.parent = dev;
2314 dev_set_name(&rdev->dev, "regulator.%d",
2315 atomic_inc_return(®ulator_no) - 1);
2316 ret = device_register(&rdev->dev);
2318 put_device(&rdev->dev);
2322 dev_set_drvdata(&rdev->dev, rdev);
2324 /* set regulator constraints */
2325 ret = set_machine_constraints(rdev, &init_data->constraints);
2329 /* add attributes supported by this regulator */
2330 ret = add_regulator_attributes(rdev);
2334 /* set supply regulator if it exists */
2335 if (init_data->supply_regulator && init_data->supply_regulator_dev) {
2337 "Supply regulator specified by both name and dev\n");
2341 if (init_data->supply_regulator) {
2342 struct regulator_dev *r;
2345 list_for_each_entry(r, ®ulator_list, list) {
2346 if (strcmp(rdev_get_name(r),
2347 init_data->supply_regulator) == 0) {
2354 dev_err(dev, "Failed to find supply %s\n",
2355 init_data->supply_regulator);
2359 ret = set_supply(rdev, r);
2364 if (init_data->supply_regulator_dev) {
2365 dev_warn(dev, "Uses supply_regulator_dev instead of regulator_supply\n");
2366 ret = set_supply(rdev,
2367 dev_get_drvdata(init_data->supply_regulator_dev));
2372 /* add consumers devices */
2373 for (i = 0; i < init_data->num_consumer_supplies; i++) {
2374 ret = set_consumer_device_supply(rdev,
2375 init_data->consumer_supplies[i].dev,
2376 init_data->consumer_supplies[i].dev_name,
2377 init_data->consumer_supplies[i].supply);
2379 goto unset_supplies;
2382 list_add(&rdev->list, ®ulator_list);
2384 mutex_unlock(®ulator_list_mutex);
2388 unset_regulator_supplies(rdev);
2391 device_unregister(&rdev->dev);
2392 /* device core frees rdev */
2393 rdev = ERR_PTR(ret);
2398 rdev = ERR_PTR(ret);
2401 EXPORT_SYMBOL_GPL(regulator_register);
2404 * regulator_unregister - unregister regulator
2405 * @rdev: regulator to unregister
2407 * Called by regulator drivers to unregister a regulator.
2409 void regulator_unregister(struct regulator_dev *rdev)
2414 mutex_lock(®ulator_list_mutex);
2415 WARN_ON(rdev->open_count);
2416 unset_regulator_supplies(rdev);
2417 list_del(&rdev->list);
2419 sysfs_remove_link(&rdev->dev.kobj, "supply");
2420 device_unregister(&rdev->dev);
2421 mutex_unlock(®ulator_list_mutex);
2423 EXPORT_SYMBOL_GPL(regulator_unregister);
2425 static suspend_state_t last_suspend_attempt;
2427 * regulator_suspend_prepare - prepare regulators for system wide suspend
2428 * @state: system suspend state
2430 * Configure each regulator with it's suspend operating parameters for state.
2431 * This will usually be called by machine suspend code prior to supending.
2433 int regulator_suspend_prepare(suspend_state_t state)
2435 struct regulator_dev *rdev;
2438 last_suspend_attempt = state;
2440 /* ON is handled by regulator active state */
2441 if (state == PM_SUSPEND_ON)
2444 mutex_lock(®ulator_list_mutex);
2445 list_for_each_entry(rdev, ®ulator_list, list) {
2447 mutex_lock(&rdev->mutex);
2448 ret = suspend_prepare(rdev, state);
2449 mutex_unlock(&rdev->mutex);
2452 printk(KERN_ERR "%s: failed to prepare %s\n",
2453 __func__, rdev_get_name(rdev));
2458 mutex_unlock(®ulator_list_mutex);
2461 EXPORT_SYMBOL_GPL(regulator_suspend_prepare);
2464 * regulator_suspend_finish - resume regulators from system wide suspend
2466 * Turn on regulators that might be turned off by regulator_suspend_prepare
2467 * and that should be turned on according to the regulators properties.
2469 int regulator_suspend_finish(void)
2471 struct regulator_dev *rdev;
2474 mutex_lock(®ulator_list_mutex);
2475 list_for_each_entry(rdev, ®ulator_list, list) {
2476 struct regulator_ops *ops = rdev->desc->ops;
2477 struct regulator_state *rstate;
2479 mutex_lock(&rdev->mutex);
2480 if (rdev->use_count > 0 ||
2481 (rdev->constraints && rdev->constraints->always_on)) {
2483 switch (last_suspend_attempt) {
2484 case PM_SUSPEND_STANDBY:
2485 rstate = &rdev->constraints->state_standby;
2487 case PM_SUSPEND_MEM:
2488 rstate = &rdev->constraints->state_mem;
2490 case PM_SUSPEND_MAX:
2491 rstate = &rdev->constraints->state_disk;
2497 if (ops->enable && rdev->constraints && rstate &&
2498 rstate->disabled && ops->set_suspend_disable &&
2499 ops->set_suspend_enable) {
2500 error = ops->enable(rdev);
2505 if (!has_full_constraints)
2509 if (ops->is_enabled && !ops->is_enabled(rdev))
2512 error = ops->disable(rdev);
2517 mutex_unlock(&rdev->mutex);
2519 mutex_unlock(®ulator_list_mutex);
2522 EXPORT_SYMBOL_GPL(regulator_suspend_finish);
2525 * regulator_has_full_constraints - the system has fully specified constraints
2527 * Calling this function will cause the regulator API to disable all
2528 * regulators which have a zero use count and don't have an always_on
2529 * constraint in a late_initcall.
2531 * The intention is that this will become the default behaviour in a
2532 * future kernel release so users are encouraged to use this facility
2535 void regulator_has_full_constraints(void)
2537 has_full_constraints = 1;
2539 EXPORT_SYMBOL_GPL(regulator_has_full_constraints);
2542 * rdev_get_drvdata - get rdev regulator driver data
2545 * Get rdev regulator driver private data. This call can be used in the
2546 * regulator driver context.
2548 void *rdev_get_drvdata(struct regulator_dev *rdev)
2550 return rdev->reg_data;
2552 EXPORT_SYMBOL_GPL(rdev_get_drvdata);
2555 * regulator_get_drvdata - get regulator driver data
2556 * @regulator: regulator
2558 * Get regulator driver private data. This call can be used in the consumer
2559 * driver context when non API regulator specific functions need to be called.
2561 void *regulator_get_drvdata(struct regulator *regulator)
2563 return regulator->rdev->reg_data;
2565 EXPORT_SYMBOL_GPL(regulator_get_drvdata);
2568 * regulator_set_drvdata - set regulator driver data
2569 * @regulator: regulator
2572 void regulator_set_drvdata(struct regulator *regulator, void *data)
2574 regulator->rdev->reg_data = data;
2576 EXPORT_SYMBOL_GPL(regulator_set_drvdata);
2579 * regulator_get_id - get regulator ID
2582 int rdev_get_id(struct regulator_dev *rdev)
2584 return rdev->desc->id;
2586 EXPORT_SYMBOL_GPL(rdev_get_id);
2588 struct device *rdev_get_dev(struct regulator_dev *rdev)
2592 EXPORT_SYMBOL_GPL(rdev_get_dev);
2594 void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data)
2596 return reg_init_data->driver_data;
2598 EXPORT_SYMBOL_GPL(regulator_get_init_drvdata);
2600 static int __init regulator_init(void)
2604 printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION);
2606 ret = class_register(®ulator_class);
2608 regulator_dummy_init();
2613 /* init early to allow our consumers to complete system booting */
2614 core_initcall(regulator_init);
2616 #ifdef CONFIG_REGULATOR_RESUME
2617 int regulator_init_complete(void)
2619 static int __init regulator_init_complete(void)
2622 struct regulator_dev *rdev;
2623 struct regulator_ops *ops;
2624 struct regulation_constraints *c;
2628 mutex_lock(®ulator_list_mutex);
2630 /* If we have a full configuration then disable any regulators
2631 * which are not in use or always_on. This will become the
2632 * default behaviour in the future.
2634 list_for_each_entry(rdev, ®ulator_list, list) {
2635 ops = rdev->desc->ops;
2636 c = rdev->constraints;
2638 name = rdev_get_name(rdev);
2640 if (!ops->disable || (c && c->always_on))
2643 mutex_lock(&rdev->mutex);
2645 if (rdev->use_count)
2648 /* If we can't read the status assume it's on. */
2649 if (ops->is_enabled)
2650 enabled = ops->is_enabled(rdev);
2657 if (has_full_constraints) {
2658 /* We log since this may kill the system if it
2660 printk(KERN_INFO "%s: disabling %s\n",
2662 ret = ops->disable(rdev);
2665 "%s: couldn't disable %s: %d\n",
2666 __func__, name, ret);
2669 /* The intention is that in future we will
2670 * assume that full constraints are provided
2671 * so warn even if we aren't going to do
2675 "%s: incomplete constraints, leaving %s on\n",
2680 mutex_unlock(&rdev->mutex);
2683 mutex_unlock(®ulator_list_mutex);
2687 late_initcall(regulator_init_complete);
2689 #ifdef CONFIG_DEBUG_FS
2691 * debugfs support to trace regulator tree hierachy and attributes
2693 static struct dentry *regulator_debugfs_root;
2695 static int regulator_debugfs_register_one(struct regulator_dev *rdev)
2698 struct dentry *d, *child, *child_tmp;
2699 struct regulator_dev *pa = rdev->supply;
2703 p += sprintf(p, "%s", rdev->desc->name);
2704 d = debugfs_create_dir(s, pa ? pa->dent : regulator_debugfs_root);
2709 d = debugfs_create_u32("use_count", S_IRUGO, rdev->dent, (u32 *)&rdev->use_count);
2714 d = debugfs_create_u32("open_count", S_IRUGO, rdev->dent, (u32 *)&rdev->open_count);
2723 list_for_each_entry_safe(child, child_tmp, &d->d_subdirs, d_u.d_child)
2724 debugfs_remove(child);
2725 debugfs_remove(rdev->dent);
2729 static int regulator_debugfs_register(struct regulator_dev *rdev)
2732 struct regulator_dev *pa = rdev->supply;
2734 if (pa && !pa->dent) {
2735 err = regulator_debugfs_register(pa);
2737 pr_err("ERROR registering parent %s(%d)\n",
2738 pa->desc->name, err);
2744 err = regulator_debugfs_register_one(rdev);
2746 pr_err("ERROR registering %s(%d)\n",
2747 rdev->desc->name, err);
2754 static int __init regulator_debugfs_init(void)
2756 struct regulator_dev *rdev;
2760 d = debugfs_create_dir("regulator", NULL);
2763 regulator_debugfs_root = d;
2765 list_for_each_entry(rdev, ®ulator_list, list) {
2766 err = regulator_debugfs_register(rdev);
2772 debugfs_remove_recursive(regulator_debugfs_root);
2775 late_initcall_sync(regulator_debugfs_init);
2777 #endif /* CONFIG_DEBUG_FS */