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/err.h>
20 #include <linux/mutex.h>
21 #include <linux/suspend.h>
22 #include <linux/regulator/consumer.h>
23 #include <linux/regulator/driver.h>
24 #include <linux/regulator/machine.h>
26 #define REGULATOR_VERSION "0.5"
28 static DEFINE_MUTEX(regulator_list_mutex
);
29 static LIST_HEAD(regulator_list
);
30 static LIST_HEAD(regulator_map_list
);
31 static int has_full_constraints
;
34 * struct regulator_map
36 * Used to provide symbolic supply names to devices.
38 struct regulator_map
{
39 struct list_head list
;
40 const char *dev_name
; /* The dev_name() for the consumer */
42 struct regulator_dev
*regulator
;
48 * One for each consumer device.
52 struct list_head list
;
57 struct device_attribute dev_attr
;
58 struct regulator_dev
*rdev
;
61 static int _regulator_is_enabled(struct regulator_dev
*rdev
);
62 static int _regulator_disable(struct regulator_dev
*rdev
);
63 static int _regulator_get_voltage(struct regulator_dev
*rdev
);
64 static int _regulator_get_current_limit(struct regulator_dev
*rdev
);
65 static unsigned int _regulator_get_mode(struct regulator_dev
*rdev
);
66 static void _notifier_call_chain(struct regulator_dev
*rdev
,
67 unsigned long event
, void *data
);
69 static const char *rdev_get_name(struct regulator_dev
*rdev
)
71 if (rdev
->constraints
&& rdev
->constraints
->name
)
72 return rdev
->constraints
->name
;
73 else if (rdev
->desc
->name
)
74 return rdev
->desc
->name
;
79 /* gets the regulator for a given consumer device */
80 static struct regulator
*get_device_regulator(struct device
*dev
)
82 struct regulator
*regulator
= NULL
;
83 struct regulator_dev
*rdev
;
85 mutex_lock(®ulator_list_mutex
);
86 list_for_each_entry(rdev
, ®ulator_list
, list
) {
87 mutex_lock(&rdev
->mutex
);
88 list_for_each_entry(regulator
, &rdev
->consumer_list
, list
) {
89 if (regulator
->dev
== dev
) {
90 mutex_unlock(&rdev
->mutex
);
91 mutex_unlock(®ulator_list_mutex
);
95 mutex_unlock(&rdev
->mutex
);
97 mutex_unlock(®ulator_list_mutex
);
101 /* Platform voltage constraint check */
102 static int regulator_check_voltage(struct regulator_dev
*rdev
,
103 int *min_uV
, int *max_uV
)
105 BUG_ON(*min_uV
> *max_uV
);
107 if (!rdev
->constraints
) {
108 printk(KERN_ERR
"%s: no constraints for %s\n", __func__
,
109 rdev_get_name(rdev
));
112 if (!(rdev
->constraints
->valid_ops_mask
& REGULATOR_CHANGE_VOLTAGE
)) {
113 printk(KERN_ERR
"%s: operation not allowed for %s\n",
114 __func__
, rdev_get_name(rdev
));
118 if (*max_uV
> rdev
->constraints
->max_uV
)
119 *max_uV
= rdev
->constraints
->max_uV
;
120 if (*min_uV
< rdev
->constraints
->min_uV
)
121 *min_uV
= rdev
->constraints
->min_uV
;
123 if (*min_uV
> *max_uV
)
129 /* current constraint check */
130 static int regulator_check_current_limit(struct regulator_dev
*rdev
,
131 int *min_uA
, int *max_uA
)
133 BUG_ON(*min_uA
> *max_uA
);
135 if (!rdev
->constraints
) {
136 printk(KERN_ERR
"%s: no constraints for %s\n", __func__
,
137 rdev_get_name(rdev
));
140 if (!(rdev
->constraints
->valid_ops_mask
& REGULATOR_CHANGE_CURRENT
)) {
141 printk(KERN_ERR
"%s: operation not allowed for %s\n",
142 __func__
, rdev_get_name(rdev
));
146 if (*max_uA
> rdev
->constraints
->max_uA
)
147 *max_uA
= rdev
->constraints
->max_uA
;
148 if (*min_uA
< rdev
->constraints
->min_uA
)
149 *min_uA
= rdev
->constraints
->min_uA
;
151 if (*min_uA
> *max_uA
)
157 /* operating mode constraint check */
158 static int regulator_check_mode(struct regulator_dev
*rdev
, int mode
)
161 case REGULATOR_MODE_FAST
:
162 case REGULATOR_MODE_NORMAL
:
163 case REGULATOR_MODE_IDLE
:
164 case REGULATOR_MODE_STANDBY
:
170 if (!rdev
->constraints
) {
171 printk(KERN_ERR
"%s: no constraints for %s\n", __func__
,
172 rdev_get_name(rdev
));
175 if (!(rdev
->constraints
->valid_ops_mask
& REGULATOR_CHANGE_MODE
)) {
176 printk(KERN_ERR
"%s: operation not allowed for %s\n",
177 __func__
, rdev_get_name(rdev
));
180 if (!(rdev
->constraints
->valid_modes_mask
& mode
)) {
181 printk(KERN_ERR
"%s: invalid mode %x for %s\n",
182 __func__
, mode
, rdev_get_name(rdev
));
188 /* dynamic regulator mode switching constraint check */
189 static int regulator_check_drms(struct regulator_dev
*rdev
)
191 if (!rdev
->constraints
) {
192 printk(KERN_ERR
"%s: no constraints for %s\n", __func__
,
193 rdev_get_name(rdev
));
196 if (!(rdev
->constraints
->valid_ops_mask
& REGULATOR_CHANGE_DRMS
)) {
197 printk(KERN_ERR
"%s: operation not allowed for %s\n",
198 __func__
, rdev_get_name(rdev
));
204 static ssize_t
device_requested_uA_show(struct device
*dev
,
205 struct device_attribute
*attr
, char *buf
)
207 struct regulator
*regulator
;
209 regulator
= get_device_regulator(dev
);
210 if (regulator
== NULL
)
213 return sprintf(buf
, "%d\n", regulator
->uA_load
);
216 static ssize_t
regulator_uV_show(struct device
*dev
,
217 struct device_attribute
*attr
, char *buf
)
219 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
222 mutex_lock(&rdev
->mutex
);
223 ret
= sprintf(buf
, "%d\n", _regulator_get_voltage(rdev
));
224 mutex_unlock(&rdev
->mutex
);
228 static DEVICE_ATTR(microvolts
, 0444, regulator_uV_show
, NULL
);
230 static ssize_t
regulator_uA_show(struct device
*dev
,
231 struct device_attribute
*attr
, char *buf
)
233 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
235 return sprintf(buf
, "%d\n", _regulator_get_current_limit(rdev
));
237 static DEVICE_ATTR(microamps
, 0444, regulator_uA_show
, NULL
);
239 static ssize_t
regulator_name_show(struct device
*dev
,
240 struct device_attribute
*attr
, char *buf
)
242 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
244 return sprintf(buf
, "%s\n", rdev_get_name(rdev
));
247 static ssize_t
regulator_print_opmode(char *buf
, int mode
)
250 case REGULATOR_MODE_FAST
:
251 return sprintf(buf
, "fast\n");
252 case REGULATOR_MODE_NORMAL
:
253 return sprintf(buf
, "normal\n");
254 case REGULATOR_MODE_IDLE
:
255 return sprintf(buf
, "idle\n");
256 case REGULATOR_MODE_STANDBY
:
257 return sprintf(buf
, "standby\n");
259 return sprintf(buf
, "unknown\n");
262 static ssize_t
regulator_opmode_show(struct device
*dev
,
263 struct device_attribute
*attr
, char *buf
)
265 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
267 return regulator_print_opmode(buf
, _regulator_get_mode(rdev
));
269 static DEVICE_ATTR(opmode
, 0444, regulator_opmode_show
, NULL
);
271 static ssize_t
regulator_print_state(char *buf
, int state
)
274 return sprintf(buf
, "enabled\n");
276 return sprintf(buf
, "disabled\n");
278 return sprintf(buf
, "unknown\n");
281 static ssize_t
regulator_state_show(struct device
*dev
,
282 struct device_attribute
*attr
, char *buf
)
284 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
287 mutex_lock(&rdev
->mutex
);
288 ret
= regulator_print_state(buf
, _regulator_is_enabled(rdev
));
289 mutex_unlock(&rdev
->mutex
);
293 static DEVICE_ATTR(state
, 0444, regulator_state_show
, NULL
);
295 static ssize_t
regulator_status_show(struct device
*dev
,
296 struct device_attribute
*attr
, char *buf
)
298 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
302 status
= rdev
->desc
->ops
->get_status(rdev
);
307 case REGULATOR_STATUS_OFF
:
310 case REGULATOR_STATUS_ON
:
313 case REGULATOR_STATUS_ERROR
:
316 case REGULATOR_STATUS_FAST
:
319 case REGULATOR_STATUS_NORMAL
:
322 case REGULATOR_STATUS_IDLE
:
325 case REGULATOR_STATUS_STANDBY
:
332 return sprintf(buf
, "%s\n", label
);
334 static DEVICE_ATTR(status
, 0444, regulator_status_show
, NULL
);
336 static ssize_t
regulator_min_uA_show(struct device
*dev
,
337 struct device_attribute
*attr
, char *buf
)
339 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
341 if (!rdev
->constraints
)
342 return sprintf(buf
, "constraint not defined\n");
344 return sprintf(buf
, "%d\n", rdev
->constraints
->min_uA
);
346 static DEVICE_ATTR(min_microamps
, 0444, regulator_min_uA_show
, NULL
);
348 static ssize_t
regulator_max_uA_show(struct device
*dev
,
349 struct device_attribute
*attr
, char *buf
)
351 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
353 if (!rdev
->constraints
)
354 return sprintf(buf
, "constraint not defined\n");
356 return sprintf(buf
, "%d\n", rdev
->constraints
->max_uA
);
358 static DEVICE_ATTR(max_microamps
, 0444, regulator_max_uA_show
, NULL
);
360 static ssize_t
regulator_min_uV_show(struct device
*dev
,
361 struct device_attribute
*attr
, char *buf
)
363 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
365 if (!rdev
->constraints
)
366 return sprintf(buf
, "constraint not defined\n");
368 return sprintf(buf
, "%d\n", rdev
->constraints
->min_uV
);
370 static DEVICE_ATTR(min_microvolts
, 0444, regulator_min_uV_show
, NULL
);
372 static ssize_t
regulator_max_uV_show(struct device
*dev
,
373 struct device_attribute
*attr
, char *buf
)
375 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
377 if (!rdev
->constraints
)
378 return sprintf(buf
, "constraint not defined\n");
380 return sprintf(buf
, "%d\n", rdev
->constraints
->max_uV
);
382 static DEVICE_ATTR(max_microvolts
, 0444, regulator_max_uV_show
, NULL
);
384 static ssize_t
regulator_total_uA_show(struct device
*dev
,
385 struct device_attribute
*attr
, char *buf
)
387 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
388 struct regulator
*regulator
;
391 mutex_lock(&rdev
->mutex
);
392 list_for_each_entry(regulator
, &rdev
->consumer_list
, list
)
393 uA
+= regulator
->uA_load
;
394 mutex_unlock(&rdev
->mutex
);
395 return sprintf(buf
, "%d\n", uA
);
397 static DEVICE_ATTR(requested_microamps
, 0444, regulator_total_uA_show
, NULL
);
399 static ssize_t
regulator_num_users_show(struct device
*dev
,
400 struct device_attribute
*attr
, char *buf
)
402 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
403 return sprintf(buf
, "%d\n", rdev
->use_count
);
406 static ssize_t
regulator_type_show(struct device
*dev
,
407 struct device_attribute
*attr
, char *buf
)
409 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
411 switch (rdev
->desc
->type
) {
412 case REGULATOR_VOLTAGE
:
413 return sprintf(buf
, "voltage\n");
414 case REGULATOR_CURRENT
:
415 return sprintf(buf
, "current\n");
417 return sprintf(buf
, "unknown\n");
420 static ssize_t
regulator_suspend_mem_uV_show(struct device
*dev
,
421 struct device_attribute
*attr
, char *buf
)
423 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
425 return sprintf(buf
, "%d\n", rdev
->constraints
->state_mem
.uV
);
427 static DEVICE_ATTR(suspend_mem_microvolts
, 0444,
428 regulator_suspend_mem_uV_show
, NULL
);
430 static ssize_t
regulator_suspend_disk_uV_show(struct device
*dev
,
431 struct device_attribute
*attr
, char *buf
)
433 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
435 return sprintf(buf
, "%d\n", rdev
->constraints
->state_disk
.uV
);
437 static DEVICE_ATTR(suspend_disk_microvolts
, 0444,
438 regulator_suspend_disk_uV_show
, NULL
);
440 static ssize_t
regulator_suspend_standby_uV_show(struct device
*dev
,
441 struct device_attribute
*attr
, char *buf
)
443 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
445 return sprintf(buf
, "%d\n", rdev
->constraints
->state_standby
.uV
);
447 static DEVICE_ATTR(suspend_standby_microvolts
, 0444,
448 regulator_suspend_standby_uV_show
, NULL
);
450 static ssize_t
regulator_suspend_mem_mode_show(struct device
*dev
,
451 struct device_attribute
*attr
, char *buf
)
453 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
455 return regulator_print_opmode(buf
,
456 rdev
->constraints
->state_mem
.mode
);
458 static DEVICE_ATTR(suspend_mem_mode
, 0444,
459 regulator_suspend_mem_mode_show
, NULL
);
461 static ssize_t
regulator_suspend_disk_mode_show(struct device
*dev
,
462 struct device_attribute
*attr
, char *buf
)
464 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
466 return regulator_print_opmode(buf
,
467 rdev
->constraints
->state_disk
.mode
);
469 static DEVICE_ATTR(suspend_disk_mode
, 0444,
470 regulator_suspend_disk_mode_show
, NULL
);
472 static ssize_t
regulator_suspend_standby_mode_show(struct device
*dev
,
473 struct device_attribute
*attr
, char *buf
)
475 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
477 return regulator_print_opmode(buf
,
478 rdev
->constraints
->state_standby
.mode
);
480 static DEVICE_ATTR(suspend_standby_mode
, 0444,
481 regulator_suspend_standby_mode_show
, NULL
);
483 static ssize_t
regulator_suspend_mem_state_show(struct device
*dev
,
484 struct device_attribute
*attr
, char *buf
)
486 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
488 return regulator_print_state(buf
,
489 rdev
->constraints
->state_mem
.enabled
);
491 static DEVICE_ATTR(suspend_mem_state
, 0444,
492 regulator_suspend_mem_state_show
, NULL
);
494 static ssize_t
regulator_suspend_disk_state_show(struct device
*dev
,
495 struct device_attribute
*attr
, char *buf
)
497 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
499 return regulator_print_state(buf
,
500 rdev
->constraints
->state_disk
.enabled
);
502 static DEVICE_ATTR(suspend_disk_state
, 0444,
503 regulator_suspend_disk_state_show
, NULL
);
505 static ssize_t
regulator_suspend_standby_state_show(struct device
*dev
,
506 struct device_attribute
*attr
, char *buf
)
508 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
510 return regulator_print_state(buf
,
511 rdev
->constraints
->state_standby
.enabled
);
513 static DEVICE_ATTR(suspend_standby_state
, 0444,
514 regulator_suspend_standby_state_show
, NULL
);
518 * These are the only attributes are present for all regulators.
519 * Other attributes are a function of regulator functionality.
521 static struct device_attribute regulator_dev_attrs
[] = {
522 __ATTR(name
, 0444, regulator_name_show
, NULL
),
523 __ATTR(num_users
, 0444, regulator_num_users_show
, NULL
),
524 __ATTR(type
, 0444, regulator_type_show
, NULL
),
528 static void regulator_dev_release(struct device
*dev
)
530 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
534 static struct class regulator_class
= {
536 .dev_release
= regulator_dev_release
,
537 .dev_attrs
= regulator_dev_attrs
,
540 /* Calculate the new optimum regulator operating mode based on the new total
541 * consumer load. All locks held by caller */
542 static void drms_uA_update(struct regulator_dev
*rdev
)
544 struct regulator
*sibling
;
545 int current_uA
= 0, output_uV
, input_uV
, err
;
548 err
= regulator_check_drms(rdev
);
549 if (err
< 0 || !rdev
->desc
->ops
->get_optimum_mode
||
550 !rdev
->desc
->ops
->get_voltage
|| !rdev
->desc
->ops
->set_mode
)
553 /* get output voltage */
554 output_uV
= rdev
->desc
->ops
->get_voltage(rdev
);
558 /* get input voltage */
559 if (rdev
->supply
&& rdev
->supply
->desc
->ops
->get_voltage
)
560 input_uV
= rdev
->supply
->desc
->ops
->get_voltage(rdev
->supply
);
562 input_uV
= rdev
->constraints
->input_uV
;
566 /* calc total requested load */
567 list_for_each_entry(sibling
, &rdev
->consumer_list
, list
)
568 current_uA
+= sibling
->uA_load
;
570 /* now get the optimum mode for our new total regulator load */
571 mode
= rdev
->desc
->ops
->get_optimum_mode(rdev
, input_uV
,
572 output_uV
, current_uA
);
574 /* check the new mode is allowed */
575 err
= regulator_check_mode(rdev
, mode
);
577 rdev
->desc
->ops
->set_mode(rdev
, mode
);
580 static int suspend_set_state(struct regulator_dev
*rdev
,
581 struct regulator_state
*rstate
)
586 can_set_state
= rdev
->desc
->ops
->set_suspend_enable
&&
587 rdev
->desc
->ops
->set_suspend_disable
;
589 /* If we have no suspend mode configration don't set anything;
590 * only warn if the driver actually makes the suspend mode
593 if (!rstate
->enabled
&& !rstate
->disabled
) {
595 printk(KERN_WARNING
"%s: No configuration for %s\n",
596 __func__
, rdev_get_name(rdev
));
600 if (rstate
->enabled
&& rstate
->disabled
) {
601 printk(KERN_ERR
"%s: invalid configuration for %s\n",
602 __func__
, rdev_get_name(rdev
));
606 if (!can_set_state
) {
607 printk(KERN_ERR
"%s: no way to set suspend state\n",
613 ret
= rdev
->desc
->ops
->set_suspend_enable(rdev
);
615 ret
= rdev
->desc
->ops
->set_suspend_disable(rdev
);
617 printk(KERN_ERR
"%s: failed to enabled/disable\n", __func__
);
621 if (rdev
->desc
->ops
->set_suspend_voltage
&& rstate
->uV
> 0) {
622 ret
= rdev
->desc
->ops
->set_suspend_voltage(rdev
, rstate
->uV
);
624 printk(KERN_ERR
"%s: failed to set voltage\n",
630 if (rdev
->desc
->ops
->set_suspend_mode
&& rstate
->mode
> 0) {
631 ret
= rdev
->desc
->ops
->set_suspend_mode(rdev
, rstate
->mode
);
633 printk(KERN_ERR
"%s: failed to set mode\n", __func__
);
640 /* locks held by caller */
641 static int suspend_prepare(struct regulator_dev
*rdev
, suspend_state_t state
)
643 if (!rdev
->constraints
)
647 case PM_SUSPEND_STANDBY
:
648 return suspend_set_state(rdev
,
649 &rdev
->constraints
->state_standby
);
651 return suspend_set_state(rdev
,
652 &rdev
->constraints
->state_mem
);
654 return suspend_set_state(rdev
,
655 &rdev
->constraints
->state_disk
);
661 static void print_constraints(struct regulator_dev
*rdev
)
663 struct regulation_constraints
*constraints
= rdev
->constraints
;
668 if (constraints
->min_uV
&& constraints
->max_uV
) {
669 if (constraints
->min_uV
== constraints
->max_uV
)
670 count
+= sprintf(buf
+ count
, "%d mV ",
671 constraints
->min_uV
/ 1000);
673 count
+= sprintf(buf
+ count
, "%d <--> %d mV ",
674 constraints
->min_uV
/ 1000,
675 constraints
->max_uV
/ 1000);
678 if (!constraints
->min_uV
||
679 constraints
->min_uV
!= constraints
->max_uV
) {
680 ret
= _regulator_get_voltage(rdev
);
682 count
+= sprintf(buf
+ count
, "at %d mV ", ret
/ 1000);
685 if (constraints
->min_uA
&& constraints
->max_uA
) {
686 if (constraints
->min_uA
== constraints
->max_uA
)
687 count
+= sprintf(buf
+ count
, "%d mA ",
688 constraints
->min_uA
/ 1000);
690 count
+= sprintf(buf
+ count
, "%d <--> %d mA ",
691 constraints
->min_uA
/ 1000,
692 constraints
->max_uA
/ 1000);
695 if (!constraints
->min_uA
||
696 constraints
->min_uA
!= constraints
->max_uA
) {
697 ret
= _regulator_get_current_limit(rdev
);
699 count
+= sprintf(buf
+ count
, "at %d uA ", ret
/ 1000);
702 if (constraints
->valid_modes_mask
& REGULATOR_MODE_FAST
)
703 count
+= sprintf(buf
+ count
, "fast ");
704 if (constraints
->valid_modes_mask
& REGULATOR_MODE_NORMAL
)
705 count
+= sprintf(buf
+ count
, "normal ");
706 if (constraints
->valid_modes_mask
& REGULATOR_MODE_IDLE
)
707 count
+= sprintf(buf
+ count
, "idle ");
708 if (constraints
->valid_modes_mask
& REGULATOR_MODE_STANDBY
)
709 count
+= sprintf(buf
+ count
, "standby");
711 printk(KERN_INFO
"regulator: %s: %s\n", rdev_get_name(rdev
), buf
);
714 static int machine_constraints_voltage(struct regulator_dev
*rdev
,
715 struct regulation_constraints
*constraints
)
717 struct regulator_ops
*ops
= rdev
->desc
->ops
;
718 const char *name
= rdev_get_name(rdev
);
721 /* do we need to apply the constraint voltage */
722 if (rdev
->constraints
->apply_uV
&&
723 rdev
->constraints
->min_uV
== rdev
->constraints
->max_uV
&&
725 ret
= ops
->set_voltage(rdev
,
726 rdev
->constraints
->min_uV
, rdev
->constraints
->max_uV
);
728 printk(KERN_ERR
"%s: failed to apply %duV constraint to %s\n",
730 rdev
->constraints
->min_uV
, name
);
731 rdev
->constraints
= NULL
;
736 /* constrain machine-level voltage specs to fit
737 * the actual range supported by this regulator.
739 if (ops
->list_voltage
&& rdev
->desc
->n_voltages
) {
740 int count
= rdev
->desc
->n_voltages
;
742 int min_uV
= INT_MAX
;
743 int max_uV
= INT_MIN
;
744 int cmin
= constraints
->min_uV
;
745 int cmax
= constraints
->max_uV
;
747 /* it's safe to autoconfigure fixed-voltage supplies
748 and the constraints are used by list_voltage. */
749 if (count
== 1 && !cmin
) {
752 constraints
->min_uV
= cmin
;
753 constraints
->max_uV
= cmax
;
756 /* voltage constraints are optional */
757 if ((cmin
== 0) && (cmax
== 0))
760 /* else require explicit machine-level constraints */
761 if (cmin
<= 0 || cmax
<= 0 || cmax
< cmin
) {
762 pr_err("%s: %s '%s' voltage constraints\n",
763 __func__
, "invalid", name
);
767 /* initial: [cmin..cmax] valid, [min_uV..max_uV] not */
768 for (i
= 0; i
< count
; i
++) {
771 value
= ops
->list_voltage(rdev
, i
);
775 /* maybe adjust [min_uV..max_uV] */
776 if (value
>= cmin
&& value
< min_uV
)
778 if (value
<= cmax
&& value
> max_uV
)
782 /* final: [min_uV..max_uV] valid iff constraints valid */
783 if (max_uV
< min_uV
) {
784 pr_err("%s: %s '%s' voltage constraints\n",
785 __func__
, "unsupportable", name
);
789 /* use regulator's subset of machine constraints */
790 if (constraints
->min_uV
< min_uV
) {
791 pr_debug("%s: override '%s' %s, %d -> %d\n",
792 __func__
, name
, "min_uV",
793 constraints
->min_uV
, min_uV
);
794 constraints
->min_uV
= min_uV
;
796 if (constraints
->max_uV
> max_uV
) {
797 pr_debug("%s: override '%s' %s, %d -> %d\n",
798 __func__
, name
, "max_uV",
799 constraints
->max_uV
, max_uV
);
800 constraints
->max_uV
= max_uV
;
808 * set_machine_constraints - sets regulator constraints
809 * @rdev: regulator source
810 * @constraints: constraints to apply
812 * Allows platform initialisation code to define and constrain
813 * regulator circuits e.g. valid voltage/current ranges, etc. NOTE:
814 * Constraints *must* be set by platform code in order for some
815 * regulator operations to proceed i.e. set_voltage, set_current_limit,
818 static int set_machine_constraints(struct regulator_dev
*rdev
,
819 struct regulation_constraints
*constraints
)
823 struct regulator_ops
*ops
= rdev
->desc
->ops
;
825 rdev
->constraints
= constraints
;
827 name
= rdev_get_name(rdev
);
829 ret
= machine_constraints_voltage(rdev
, constraints
);
833 /* do we need to setup our suspend state */
834 if (constraints
->initial_state
) {
835 ret
= suspend_prepare(rdev
, constraints
->initial_state
);
837 printk(KERN_ERR
"%s: failed to set suspend state for %s\n",
839 rdev
->constraints
= NULL
;
844 if (constraints
->initial_mode
) {
845 if (!ops
->set_mode
) {
846 printk(KERN_ERR
"%s: no set_mode operation for %s\n",
852 ret
= ops
->set_mode(rdev
, constraints
->initial_mode
);
855 "%s: failed to set initial mode for %s: %d\n",
856 __func__
, name
, ret
);
861 /* If the constraints say the regulator should be on at this point
862 * and we have control then make sure it is enabled.
864 if ((constraints
->always_on
|| constraints
->boot_on
) && ops
->enable
) {
865 ret
= ops
->enable(rdev
);
867 printk(KERN_ERR
"%s: failed to enable %s\n",
869 rdev
->constraints
= NULL
;
874 print_constraints(rdev
);
880 * set_supply - set regulator supply regulator
881 * @rdev: regulator name
882 * @supply_rdev: supply regulator name
884 * Called by platform initialisation code to set the supply regulator for this
885 * regulator. This ensures that a regulators supply will also be enabled by the
886 * core if it's child is enabled.
888 static int set_supply(struct regulator_dev
*rdev
,
889 struct regulator_dev
*supply_rdev
)
893 err
= sysfs_create_link(&rdev
->dev
.kobj
, &supply_rdev
->dev
.kobj
,
897 "%s: could not add device link %s err %d\n",
898 __func__
, supply_rdev
->dev
.kobj
.name
, err
);
901 rdev
->supply
= supply_rdev
;
902 list_add(&rdev
->slist
, &supply_rdev
->supply_list
);
908 * set_consumer_device_supply: Bind a regulator to a symbolic supply
909 * @rdev: regulator source
910 * @consumer_dev: device the supply applies to
911 * @consumer_dev_name: dev_name() string for device supply applies to
912 * @supply: symbolic name for supply
914 * Allows platform initialisation code to map physical regulator
915 * sources to symbolic names for supplies for use by devices. Devices
916 * should use these symbolic names to request regulators, avoiding the
917 * need to provide board-specific regulator names as platform data.
919 * Only one of consumer_dev and consumer_dev_name may be specified.
921 static int set_consumer_device_supply(struct regulator_dev
*rdev
,
922 struct device
*consumer_dev
, const char *consumer_dev_name
,
925 struct regulator_map
*node
;
928 if (consumer_dev
&& consumer_dev_name
)
931 if (!consumer_dev_name
&& consumer_dev
)
932 consumer_dev_name
= dev_name(consumer_dev
);
937 if (consumer_dev_name
!= NULL
)
942 list_for_each_entry(node
, ®ulator_map_list
, list
) {
943 if (consumer_dev_name
!= node
->dev_name
)
945 if (strcmp(node
->supply
, supply
) != 0)
948 dev_dbg(consumer_dev
, "%s/%s is '%s' supply; fail %s/%s\n",
949 dev_name(&node
->regulator
->dev
),
950 node
->regulator
->desc
->name
,
952 dev_name(&rdev
->dev
), rdev_get_name(rdev
));
956 node
= kzalloc(sizeof(struct regulator_map
), GFP_KERNEL
);
960 node
->regulator
= rdev
;
961 node
->supply
= supply
;
964 node
->dev_name
= kstrdup(consumer_dev_name
, GFP_KERNEL
);
965 if (node
->dev_name
== NULL
) {
971 list_add(&node
->list
, ®ulator_map_list
);
975 static void unset_consumer_device_supply(struct regulator_dev
*rdev
,
976 const char *consumer_dev_name
, struct device
*consumer_dev
)
978 struct regulator_map
*node
, *n
;
980 if (consumer_dev
&& !consumer_dev_name
)
981 consumer_dev_name
= dev_name(consumer_dev
);
983 list_for_each_entry_safe(node
, n
, ®ulator_map_list
, list
) {
984 if (rdev
!= node
->regulator
)
987 if (consumer_dev_name
&& node
->dev_name
&&
988 strcmp(consumer_dev_name
, node
->dev_name
))
991 list_del(&node
->list
);
992 kfree(node
->dev_name
);
998 static void unset_regulator_supplies(struct regulator_dev
*rdev
)
1000 struct regulator_map
*node
, *n
;
1002 list_for_each_entry_safe(node
, n
, ®ulator_map_list
, list
) {
1003 if (rdev
== node
->regulator
) {
1004 list_del(&node
->list
);
1005 kfree(node
->dev_name
);
1012 #define REG_STR_SIZE 32
1014 static struct regulator
*create_regulator(struct regulator_dev
*rdev
,
1016 const char *supply_name
)
1018 struct regulator
*regulator
;
1019 char buf
[REG_STR_SIZE
];
1022 regulator
= kzalloc(sizeof(*regulator
), GFP_KERNEL
);
1023 if (regulator
== NULL
)
1026 mutex_lock(&rdev
->mutex
);
1027 regulator
->rdev
= rdev
;
1028 list_add(®ulator
->list
, &rdev
->consumer_list
);
1031 /* create a 'requested_microamps_name' sysfs entry */
1032 size
= scnprintf(buf
, REG_STR_SIZE
, "microamps_requested_%s",
1034 if (size
>= REG_STR_SIZE
)
1037 regulator
->dev
= dev
;
1038 regulator
->dev_attr
.attr
.name
= kstrdup(buf
, GFP_KERNEL
);
1039 if (regulator
->dev_attr
.attr
.name
== NULL
)
1042 regulator
->dev_attr
.attr
.owner
= THIS_MODULE
;
1043 regulator
->dev_attr
.attr
.mode
= 0444;
1044 regulator
->dev_attr
.show
= device_requested_uA_show
;
1045 err
= device_create_file(dev
, ®ulator
->dev_attr
);
1047 printk(KERN_WARNING
"%s: could not add regulator_dev"
1048 " load sysfs\n", __func__
);
1052 /* also add a link to the device sysfs entry */
1053 size
= scnprintf(buf
, REG_STR_SIZE
, "%s-%s",
1054 dev
->kobj
.name
, supply_name
);
1055 if (size
>= REG_STR_SIZE
)
1058 regulator
->supply_name
= kstrdup(buf
, GFP_KERNEL
);
1059 if (regulator
->supply_name
== NULL
)
1062 err
= sysfs_create_link(&rdev
->dev
.kobj
, &dev
->kobj
,
1066 "%s: could not add device link %s err %d\n",
1067 __func__
, dev
->kobj
.name
, err
);
1068 device_remove_file(dev
, ®ulator
->dev_attr
);
1072 mutex_unlock(&rdev
->mutex
);
1075 kfree(regulator
->supply_name
);
1077 device_remove_file(regulator
->dev
, ®ulator
->dev_attr
);
1079 kfree(regulator
->dev_attr
.attr
.name
);
1081 list_del(®ulator
->list
);
1083 mutex_unlock(&rdev
->mutex
);
1087 /* Internal regulator request function */
1088 static struct regulator
*_regulator_get(struct device
*dev
, const char *id
,
1091 struct regulator_dev
*rdev
;
1092 struct regulator_map
*map
;
1093 struct regulator
*regulator
= ERR_PTR(-ENODEV
);
1094 const char *devname
= NULL
;
1098 printk(KERN_ERR
"regulator: get() with no identifier\n");
1103 devname
= dev_name(dev
);
1105 mutex_lock(®ulator_list_mutex
);
1107 list_for_each_entry(map
, ®ulator_map_list
, list
) {
1108 /* If the mapping has a device set up it must match */
1109 if (map
->dev_name
&&
1110 (!devname
|| strcmp(map
->dev_name
, devname
)))
1113 if (strcmp(map
->supply
, id
) == 0) {
1114 rdev
= map
->regulator
;
1118 mutex_unlock(®ulator_list_mutex
);
1122 if (rdev
->exclusive
) {
1123 regulator
= ERR_PTR(-EPERM
);
1127 if (exclusive
&& rdev
->open_count
) {
1128 regulator
= ERR_PTR(-EBUSY
);
1132 if (!try_module_get(rdev
->owner
))
1135 regulator
= create_regulator(rdev
, dev
, id
);
1136 if (regulator
== NULL
) {
1137 regulator
= ERR_PTR(-ENOMEM
);
1138 module_put(rdev
->owner
);
1143 rdev
->exclusive
= 1;
1145 ret
= _regulator_is_enabled(rdev
);
1147 rdev
->use_count
= 1;
1149 rdev
->use_count
= 0;
1153 mutex_unlock(®ulator_list_mutex
);
1159 * regulator_get - lookup and obtain a reference to a regulator.
1160 * @dev: device for regulator "consumer"
1161 * @id: Supply name or regulator ID.
1163 * Returns a struct regulator corresponding to the regulator producer,
1164 * or IS_ERR() condition containing errno.
1166 * Use of supply names configured via regulator_set_device_supply() is
1167 * strongly encouraged. It is recommended that the supply name used
1168 * should match the name used for the supply and/or the relevant
1169 * device pins in the datasheet.
1171 struct regulator
*regulator_get(struct device
*dev
, const char *id
)
1173 return _regulator_get(dev
, id
, 0);
1175 EXPORT_SYMBOL_GPL(regulator_get
);
1178 * regulator_get_exclusive - obtain exclusive access to a regulator.
1179 * @dev: device for regulator "consumer"
1180 * @id: Supply name or regulator ID.
1182 * Returns a struct regulator corresponding to the regulator producer,
1183 * or IS_ERR() condition containing errno. Other consumers will be
1184 * unable to obtain this reference is held and the use count for the
1185 * regulator will be initialised to reflect the current state of the
1188 * This is intended for use by consumers which cannot tolerate shared
1189 * use of the regulator such as those which need to force the
1190 * regulator off for correct operation of the hardware they are
1193 * Use of supply names configured via regulator_set_device_supply() is
1194 * strongly encouraged. It is recommended that the supply name used
1195 * should match the name used for the supply and/or the relevant
1196 * device pins in the datasheet.
1198 struct regulator
*regulator_get_exclusive(struct device
*dev
, const char *id
)
1200 return _regulator_get(dev
, id
, 1);
1202 EXPORT_SYMBOL_GPL(regulator_get_exclusive
);
1205 * regulator_put - "free" the regulator source
1206 * @regulator: regulator source
1208 * Note: drivers must ensure that all regulator_enable calls made on this
1209 * regulator source are balanced by regulator_disable calls prior to calling
1212 void regulator_put(struct regulator
*regulator
)
1214 struct regulator_dev
*rdev
;
1216 if (regulator
== NULL
|| IS_ERR(regulator
))
1219 mutex_lock(®ulator_list_mutex
);
1220 rdev
= regulator
->rdev
;
1222 /* remove any sysfs entries */
1223 if (regulator
->dev
) {
1224 sysfs_remove_link(&rdev
->dev
.kobj
, regulator
->supply_name
);
1225 kfree(regulator
->supply_name
);
1226 device_remove_file(regulator
->dev
, ®ulator
->dev_attr
);
1227 kfree(regulator
->dev_attr
.attr
.name
);
1229 list_del(®ulator
->list
);
1233 rdev
->exclusive
= 0;
1235 module_put(rdev
->owner
);
1236 mutex_unlock(®ulator_list_mutex
);
1238 EXPORT_SYMBOL_GPL(regulator_put
);
1240 static int _regulator_can_change_status(struct regulator_dev
*rdev
)
1242 if (!rdev
->constraints
)
1245 if (rdev
->constraints
->valid_ops_mask
& REGULATOR_CHANGE_STATUS
)
1251 /* locks held by regulator_enable() */
1252 static int _regulator_enable(struct regulator_dev
*rdev
)
1256 /* do we need to enable the supply regulator first */
1258 ret
= _regulator_enable(rdev
->supply
);
1260 printk(KERN_ERR
"%s: failed to enable %s: %d\n",
1261 __func__
, rdev_get_name(rdev
), ret
);
1266 /* check voltage and requested load before enabling */
1267 if (rdev
->constraints
&&
1268 (rdev
->constraints
->valid_ops_mask
& REGULATOR_CHANGE_DRMS
))
1269 drms_uA_update(rdev
);
1271 if (rdev
->use_count
== 0) {
1272 /* The regulator may on if it's not switchable or left on */
1273 ret
= _regulator_is_enabled(rdev
);
1274 if (ret
== -EINVAL
|| ret
== 0) {
1275 if (!_regulator_can_change_status(rdev
))
1278 if (rdev
->desc
->ops
->enable
) {
1279 ret
= rdev
->desc
->ops
->enable(rdev
);
1285 } else if (ret
< 0) {
1286 printk(KERN_ERR
"%s: is_enabled() failed for %s: %d\n",
1287 __func__
, rdev_get_name(rdev
), ret
);
1290 /* Fallthrough on positive return values - already enabled */
1299 * regulator_enable - enable regulator output
1300 * @regulator: regulator source
1302 * Request that the regulator be enabled with the regulator output at
1303 * the predefined voltage or current value. Calls to regulator_enable()
1304 * must be balanced with calls to regulator_disable().
1306 * NOTE: the output value can be set by other drivers, boot loader or may be
1307 * hardwired in the regulator.
1309 int regulator_enable(struct regulator
*regulator
)
1311 struct regulator_dev
*rdev
= regulator
->rdev
;
1314 mutex_lock(&rdev
->mutex
);
1315 ret
= _regulator_enable(rdev
);
1316 mutex_unlock(&rdev
->mutex
);
1319 EXPORT_SYMBOL_GPL(regulator_enable
);
1321 /* locks held by regulator_disable() */
1322 static int _regulator_disable(struct regulator_dev
*rdev
)
1326 if (WARN(rdev
->use_count
<= 0,
1327 "unbalanced disables for %s\n",
1328 rdev_get_name(rdev
)))
1331 /* are we the last user and permitted to disable ? */
1332 if (rdev
->use_count
== 1 &&
1333 (rdev
->constraints
&& !rdev
->constraints
->always_on
)) {
1335 /* we are last user */
1336 if (_regulator_can_change_status(rdev
) &&
1337 rdev
->desc
->ops
->disable
) {
1338 ret
= rdev
->desc
->ops
->disable(rdev
);
1340 printk(KERN_ERR
"%s: failed to disable %s\n",
1341 __func__
, rdev_get_name(rdev
));
1346 /* decrease our supplies ref count and disable if required */
1348 _regulator_disable(rdev
->supply
);
1350 rdev
->use_count
= 0;
1351 } else if (rdev
->use_count
> 1) {
1353 if (rdev
->constraints
&&
1354 (rdev
->constraints
->valid_ops_mask
&
1355 REGULATOR_CHANGE_DRMS
))
1356 drms_uA_update(rdev
);
1364 * regulator_disable - disable regulator output
1365 * @regulator: regulator source
1367 * Disable the regulator output voltage or current. Calls to
1368 * regulator_enable() must be balanced with calls to
1369 * regulator_disable().
1371 * NOTE: this will only disable the regulator output if no other consumer
1372 * devices have it enabled, the regulator device supports disabling and
1373 * machine constraints permit this operation.
1375 int regulator_disable(struct regulator
*regulator
)
1377 struct regulator_dev
*rdev
= regulator
->rdev
;
1380 mutex_lock(&rdev
->mutex
);
1381 ret
= _regulator_disable(rdev
);
1382 mutex_unlock(&rdev
->mutex
);
1385 EXPORT_SYMBOL_GPL(regulator_disable
);
1387 /* locks held by regulator_force_disable() */
1388 static int _regulator_force_disable(struct regulator_dev
*rdev
)
1393 if (rdev
->desc
->ops
->disable
) {
1394 /* ah well, who wants to live forever... */
1395 ret
= rdev
->desc
->ops
->disable(rdev
);
1397 printk(KERN_ERR
"%s: failed to force disable %s\n",
1398 __func__
, rdev_get_name(rdev
));
1401 /* notify other consumers that power has been forced off */
1402 _notifier_call_chain(rdev
, REGULATOR_EVENT_FORCE_DISABLE
,
1406 /* decrease our supplies ref count and disable if required */
1408 _regulator_disable(rdev
->supply
);
1410 rdev
->use_count
= 0;
1415 * regulator_force_disable - force disable regulator output
1416 * @regulator: regulator source
1418 * Forcibly disable the regulator output voltage or current.
1419 * NOTE: this *will* disable the regulator output even if other consumer
1420 * devices have it enabled. This should be used for situations when device
1421 * damage will likely occur if the regulator is not disabled (e.g. over temp).
1423 int regulator_force_disable(struct regulator
*regulator
)
1427 mutex_lock(®ulator
->rdev
->mutex
);
1428 regulator
->uA_load
= 0;
1429 ret
= _regulator_force_disable(regulator
->rdev
);
1430 mutex_unlock(®ulator
->rdev
->mutex
);
1433 EXPORT_SYMBOL_GPL(regulator_force_disable
);
1435 static int _regulator_is_enabled(struct regulator_dev
*rdev
)
1438 if (!rdev
->desc
->ops
->is_enabled
)
1441 return rdev
->desc
->ops
->is_enabled(rdev
);
1445 * regulator_is_enabled - is the regulator output enabled
1446 * @regulator: regulator source
1448 * Returns positive if the regulator driver backing the source/client
1449 * has requested that the device be enabled, zero if it hasn't, else a
1450 * negative errno code.
1452 * Note that the device backing this regulator handle can have multiple
1453 * users, so it might be enabled even if regulator_enable() was never
1454 * called for this particular source.
1456 int regulator_is_enabled(struct regulator
*regulator
)
1460 mutex_lock(®ulator
->rdev
->mutex
);
1461 ret
= _regulator_is_enabled(regulator
->rdev
);
1462 mutex_unlock(®ulator
->rdev
->mutex
);
1466 EXPORT_SYMBOL_GPL(regulator_is_enabled
);
1469 * regulator_count_voltages - count regulator_list_voltage() selectors
1470 * @regulator: regulator source
1472 * Returns number of selectors, or negative errno. Selectors are
1473 * numbered starting at zero, and typically correspond to bitfields
1474 * in hardware registers.
1476 int regulator_count_voltages(struct regulator
*regulator
)
1478 struct regulator_dev
*rdev
= regulator
->rdev
;
1480 return rdev
->desc
->n_voltages
? : -EINVAL
;
1482 EXPORT_SYMBOL_GPL(regulator_count_voltages
);
1485 * regulator_list_voltage - enumerate supported voltages
1486 * @regulator: regulator source
1487 * @selector: identify voltage to list
1488 * Context: can sleep
1490 * Returns a voltage that can be passed to @regulator_set_voltage(),
1491 * zero if this selector code can't be used on this sytem, or a
1494 int regulator_list_voltage(struct regulator
*regulator
, unsigned selector
)
1496 struct regulator_dev
*rdev
= regulator
->rdev
;
1497 struct regulator_ops
*ops
= rdev
->desc
->ops
;
1500 if (!ops
->list_voltage
|| selector
>= rdev
->desc
->n_voltages
)
1503 mutex_lock(&rdev
->mutex
);
1504 ret
= ops
->list_voltage(rdev
, selector
);
1505 mutex_unlock(&rdev
->mutex
);
1508 if (ret
< rdev
->constraints
->min_uV
)
1510 else if (ret
> rdev
->constraints
->max_uV
)
1516 EXPORT_SYMBOL_GPL(regulator_list_voltage
);
1519 * regulator_is_supported_voltage - check if a voltage range can be supported
1521 * @regulator: Regulator to check.
1522 * @min_uV: Minimum required voltage in uV.
1523 * @max_uV: Maximum required voltage in uV.
1525 * Returns a boolean or a negative error code.
1527 int regulator_is_supported_voltage(struct regulator
*regulator
,
1528 int min_uV
, int max_uV
)
1530 int i
, voltages
, ret
;
1532 ret
= regulator_count_voltages(regulator
);
1537 for (i
= 0; i
< voltages
; i
++) {
1538 ret
= regulator_list_voltage(regulator
, i
);
1540 if (ret
>= min_uV
&& ret
<= max_uV
)
1548 * regulator_set_voltage - set regulator output voltage
1549 * @regulator: regulator source
1550 * @min_uV: Minimum required voltage in uV
1551 * @max_uV: Maximum acceptable voltage in uV
1553 * Sets a voltage regulator to the desired output voltage. This can be set
1554 * during any regulator state. IOW, regulator can be disabled or enabled.
1556 * If the regulator is enabled then the voltage will change to the new value
1557 * immediately otherwise if the regulator is disabled the regulator will
1558 * output at the new voltage when enabled.
1560 * NOTE: If the regulator is shared between several devices then the lowest
1561 * request voltage that meets the system constraints will be used.
1562 * Regulator system constraints must be set for this regulator before
1563 * calling this function otherwise this call will fail.
1565 int regulator_set_voltage(struct regulator
*regulator
, int min_uV
, int max_uV
)
1567 struct regulator_dev
*rdev
= regulator
->rdev
;
1570 mutex_lock(&rdev
->mutex
);
1573 if (!rdev
->desc
->ops
->set_voltage
) {
1578 /* constraints check */
1579 ret
= regulator_check_voltage(rdev
, &min_uV
, &max_uV
);
1582 regulator
->min_uV
= min_uV
;
1583 regulator
->max_uV
= max_uV
;
1584 ret
= rdev
->desc
->ops
->set_voltage(rdev
, min_uV
, max_uV
);
1587 _notifier_call_chain(rdev
, REGULATOR_EVENT_VOLTAGE_CHANGE
, NULL
);
1588 mutex_unlock(&rdev
->mutex
);
1591 EXPORT_SYMBOL_GPL(regulator_set_voltage
);
1593 static int _regulator_get_voltage(struct regulator_dev
*rdev
)
1596 if (rdev
->desc
->ops
->get_voltage
)
1597 return rdev
->desc
->ops
->get_voltage(rdev
);
1603 * regulator_get_voltage - get regulator output voltage
1604 * @regulator: regulator source
1606 * This returns the current regulator voltage in uV.
1608 * NOTE: If the regulator is disabled it will return the voltage value. This
1609 * function should not be used to determine regulator state.
1611 int regulator_get_voltage(struct regulator
*regulator
)
1615 mutex_lock(®ulator
->rdev
->mutex
);
1617 ret
= _regulator_get_voltage(regulator
->rdev
);
1619 mutex_unlock(®ulator
->rdev
->mutex
);
1623 EXPORT_SYMBOL_GPL(regulator_get_voltage
);
1626 * regulator_set_current_limit - set regulator output current limit
1627 * @regulator: regulator source
1628 * @min_uA: Minimuum supported current in uA
1629 * @max_uA: Maximum supported current in uA
1631 * Sets current sink to the desired output current. This can be set during
1632 * any regulator state. IOW, regulator can be disabled or enabled.
1634 * If the regulator is enabled then the current will change to the new value
1635 * immediately otherwise if the regulator is disabled the regulator will
1636 * output at the new current when enabled.
1638 * NOTE: Regulator system constraints must be set for this regulator before
1639 * calling this function otherwise this call will fail.
1641 int regulator_set_current_limit(struct regulator
*regulator
,
1642 int min_uA
, int max_uA
)
1644 struct regulator_dev
*rdev
= regulator
->rdev
;
1647 mutex_lock(&rdev
->mutex
);
1650 if (!rdev
->desc
->ops
->set_current_limit
) {
1655 /* constraints check */
1656 ret
= regulator_check_current_limit(rdev
, &min_uA
, &max_uA
);
1660 ret
= rdev
->desc
->ops
->set_current_limit(rdev
, min_uA
, max_uA
);
1662 mutex_unlock(&rdev
->mutex
);
1665 EXPORT_SYMBOL_GPL(regulator_set_current_limit
);
1667 static int _regulator_get_current_limit(struct regulator_dev
*rdev
)
1671 mutex_lock(&rdev
->mutex
);
1674 if (!rdev
->desc
->ops
->get_current_limit
) {
1679 ret
= rdev
->desc
->ops
->get_current_limit(rdev
);
1681 mutex_unlock(&rdev
->mutex
);
1686 * regulator_get_current_limit - get regulator output current
1687 * @regulator: regulator source
1689 * This returns the current supplied by the specified current sink in uA.
1691 * NOTE: If the regulator is disabled it will return the current value. This
1692 * function should not be used to determine regulator state.
1694 int regulator_get_current_limit(struct regulator
*regulator
)
1696 return _regulator_get_current_limit(regulator
->rdev
);
1698 EXPORT_SYMBOL_GPL(regulator_get_current_limit
);
1701 * regulator_set_mode - set regulator operating mode
1702 * @regulator: regulator source
1703 * @mode: operating mode - one of the REGULATOR_MODE constants
1705 * Set regulator operating mode to increase regulator efficiency or improve
1706 * regulation performance.
1708 * NOTE: Regulator system constraints must be set for this regulator before
1709 * calling this function otherwise this call will fail.
1711 int regulator_set_mode(struct regulator
*regulator
, unsigned int mode
)
1713 struct regulator_dev
*rdev
= regulator
->rdev
;
1716 mutex_lock(&rdev
->mutex
);
1719 if (!rdev
->desc
->ops
->set_mode
) {
1724 /* constraints check */
1725 ret
= regulator_check_mode(rdev
, mode
);
1729 ret
= rdev
->desc
->ops
->set_mode(rdev
, mode
);
1731 mutex_unlock(&rdev
->mutex
);
1734 EXPORT_SYMBOL_GPL(regulator_set_mode
);
1736 static unsigned int _regulator_get_mode(struct regulator_dev
*rdev
)
1740 mutex_lock(&rdev
->mutex
);
1743 if (!rdev
->desc
->ops
->get_mode
) {
1748 ret
= rdev
->desc
->ops
->get_mode(rdev
);
1750 mutex_unlock(&rdev
->mutex
);
1755 * regulator_get_mode - get regulator operating mode
1756 * @regulator: regulator source
1758 * Get the current regulator operating mode.
1760 unsigned int regulator_get_mode(struct regulator
*regulator
)
1762 return _regulator_get_mode(regulator
->rdev
);
1764 EXPORT_SYMBOL_GPL(regulator_get_mode
);
1767 * regulator_set_optimum_mode - set regulator optimum operating mode
1768 * @regulator: regulator source
1769 * @uA_load: load current
1771 * Notifies the regulator core of a new device load. This is then used by
1772 * DRMS (if enabled by constraints) to set the most efficient regulator
1773 * operating mode for the new regulator loading.
1775 * Consumer devices notify their supply regulator of the maximum power
1776 * they will require (can be taken from device datasheet in the power
1777 * consumption tables) when they change operational status and hence power
1778 * state. Examples of operational state changes that can affect power
1779 * consumption are :-
1781 * o Device is opened / closed.
1782 * o Device I/O is about to begin or has just finished.
1783 * o Device is idling in between work.
1785 * This information is also exported via sysfs to userspace.
1787 * DRMS will sum the total requested load on the regulator and change
1788 * to the most efficient operating mode if platform constraints allow.
1790 * Returns the new regulator mode or error.
1792 int regulator_set_optimum_mode(struct regulator
*regulator
, int uA_load
)
1794 struct regulator_dev
*rdev
= regulator
->rdev
;
1795 struct regulator
*consumer
;
1796 int ret
, output_uV
, input_uV
, total_uA_load
= 0;
1799 mutex_lock(&rdev
->mutex
);
1801 regulator
->uA_load
= uA_load
;
1802 ret
= regulator_check_drms(rdev
);
1808 if (!rdev
->desc
->ops
->get_optimum_mode
)
1811 /* get output voltage */
1812 output_uV
= rdev
->desc
->ops
->get_voltage(rdev
);
1813 if (output_uV
<= 0) {
1814 printk(KERN_ERR
"%s: invalid output voltage found for %s\n",
1815 __func__
, rdev_get_name(rdev
));
1819 /* get input voltage */
1820 if (rdev
->supply
&& rdev
->supply
->desc
->ops
->get_voltage
)
1821 input_uV
= rdev
->supply
->desc
->ops
->get_voltage(rdev
->supply
);
1823 input_uV
= rdev
->constraints
->input_uV
;
1824 if (input_uV
<= 0) {
1825 printk(KERN_ERR
"%s: invalid input voltage found for %s\n",
1826 __func__
, rdev_get_name(rdev
));
1830 /* calc total requested load for this regulator */
1831 list_for_each_entry(consumer
, &rdev
->consumer_list
, list
)
1832 total_uA_load
+= consumer
->uA_load
;
1834 mode
= rdev
->desc
->ops
->get_optimum_mode(rdev
,
1835 input_uV
, output_uV
,
1837 ret
= regulator_check_mode(rdev
, mode
);
1839 printk(KERN_ERR
"%s: failed to get optimum mode for %s @"
1840 " %d uA %d -> %d uV\n", __func__
, rdev_get_name(rdev
),
1841 total_uA_load
, input_uV
, output_uV
);
1845 ret
= rdev
->desc
->ops
->set_mode(rdev
, mode
);
1847 printk(KERN_ERR
"%s: failed to set optimum mode %x for %s\n",
1848 __func__
, mode
, rdev_get_name(rdev
));
1853 mutex_unlock(&rdev
->mutex
);
1856 EXPORT_SYMBOL_GPL(regulator_set_optimum_mode
);
1859 * regulator_register_notifier - register regulator event notifier
1860 * @regulator: regulator source
1861 * @nb: notifier block
1863 * Register notifier block to receive regulator events.
1865 int regulator_register_notifier(struct regulator
*regulator
,
1866 struct notifier_block
*nb
)
1868 return blocking_notifier_chain_register(®ulator
->rdev
->notifier
,
1871 EXPORT_SYMBOL_GPL(regulator_register_notifier
);
1874 * regulator_unregister_notifier - unregister regulator event notifier
1875 * @regulator: regulator source
1876 * @nb: notifier block
1878 * Unregister regulator event notifier block.
1880 int regulator_unregister_notifier(struct regulator
*regulator
,
1881 struct notifier_block
*nb
)
1883 return blocking_notifier_chain_unregister(®ulator
->rdev
->notifier
,
1886 EXPORT_SYMBOL_GPL(regulator_unregister_notifier
);
1888 /* notify regulator consumers and downstream regulator consumers.
1889 * Note mutex must be held by caller.
1891 static void _notifier_call_chain(struct regulator_dev
*rdev
,
1892 unsigned long event
, void *data
)
1894 struct regulator_dev
*_rdev
;
1896 /* call rdev chain first */
1897 blocking_notifier_call_chain(&rdev
->notifier
, event
, NULL
);
1899 /* now notify regulator we supply */
1900 list_for_each_entry(_rdev
, &rdev
->supply_list
, slist
) {
1901 mutex_lock(&_rdev
->mutex
);
1902 _notifier_call_chain(_rdev
, event
, data
);
1903 mutex_unlock(&_rdev
->mutex
);
1908 * regulator_bulk_get - get multiple regulator consumers
1910 * @dev: Device to supply
1911 * @num_consumers: Number of consumers to register
1912 * @consumers: Configuration of consumers; clients are stored here.
1914 * @return 0 on success, an errno on failure.
1916 * This helper function allows drivers to get several regulator
1917 * consumers in one operation. If any of the regulators cannot be
1918 * acquired then any regulators that were allocated will be freed
1919 * before returning to the caller.
1921 int regulator_bulk_get(struct device
*dev
, int num_consumers
,
1922 struct regulator_bulk_data
*consumers
)
1927 for (i
= 0; i
< num_consumers
; i
++)
1928 consumers
[i
].consumer
= NULL
;
1930 for (i
= 0; i
< num_consumers
; i
++) {
1931 consumers
[i
].consumer
= regulator_get(dev
,
1932 consumers
[i
].supply
);
1933 if (IS_ERR(consumers
[i
].consumer
)) {
1934 ret
= PTR_ERR(consumers
[i
].consumer
);
1935 dev_err(dev
, "Failed to get supply '%s': %d\n",
1936 consumers
[i
].supply
, ret
);
1937 consumers
[i
].consumer
= NULL
;
1945 for (i
= 0; i
< num_consumers
&& consumers
[i
].consumer
; i
++)
1946 regulator_put(consumers
[i
].consumer
);
1950 EXPORT_SYMBOL_GPL(regulator_bulk_get
);
1953 * regulator_bulk_enable - enable multiple regulator consumers
1955 * @num_consumers: Number of consumers
1956 * @consumers: Consumer data; clients are stored here.
1957 * @return 0 on success, an errno on failure
1959 * This convenience API allows consumers to enable multiple regulator
1960 * clients in a single API call. If any consumers cannot be enabled
1961 * then any others that were enabled will be disabled again prior to
1964 int regulator_bulk_enable(int num_consumers
,
1965 struct regulator_bulk_data
*consumers
)
1970 for (i
= 0; i
< num_consumers
; i
++) {
1971 ret
= regulator_enable(consumers
[i
].consumer
);
1979 printk(KERN_ERR
"Failed to enable %s: %d\n", consumers
[i
].supply
, ret
);
1980 for (--i
; i
>= 0; --i
)
1981 regulator_disable(consumers
[i
].consumer
);
1985 EXPORT_SYMBOL_GPL(regulator_bulk_enable
);
1988 * regulator_bulk_disable - disable multiple regulator consumers
1990 * @num_consumers: Number of consumers
1991 * @consumers: Consumer data; clients are stored here.
1992 * @return 0 on success, an errno on failure
1994 * This convenience API allows consumers to disable multiple regulator
1995 * clients in a single API call. If any consumers cannot be enabled
1996 * then any others that were disabled will be disabled again prior to
1999 int regulator_bulk_disable(int num_consumers
,
2000 struct regulator_bulk_data
*consumers
)
2005 for (i
= 0; i
< num_consumers
; i
++) {
2006 ret
= regulator_disable(consumers
[i
].consumer
);
2014 printk(KERN_ERR
"Failed to disable %s: %d\n", consumers
[i
].supply
,
2016 for (--i
; i
>= 0; --i
)
2017 regulator_enable(consumers
[i
].consumer
);
2021 EXPORT_SYMBOL_GPL(regulator_bulk_disable
);
2024 * regulator_bulk_free - free multiple regulator consumers
2026 * @num_consumers: Number of consumers
2027 * @consumers: Consumer data; clients are stored here.
2029 * This convenience API allows consumers to free multiple regulator
2030 * clients in a single API call.
2032 void regulator_bulk_free(int num_consumers
,
2033 struct regulator_bulk_data
*consumers
)
2037 for (i
= 0; i
< num_consumers
; i
++) {
2038 regulator_put(consumers
[i
].consumer
);
2039 consumers
[i
].consumer
= NULL
;
2042 EXPORT_SYMBOL_GPL(regulator_bulk_free
);
2045 * regulator_notifier_call_chain - call regulator event notifier
2046 * @rdev: regulator source
2047 * @event: notifier block
2048 * @data: callback-specific data.
2050 * Called by regulator drivers to notify clients a regulator event has
2051 * occurred. We also notify regulator clients downstream.
2052 * Note lock must be held by caller.
2054 int regulator_notifier_call_chain(struct regulator_dev
*rdev
,
2055 unsigned long event
, void *data
)
2057 _notifier_call_chain(rdev
, event
, data
);
2061 EXPORT_SYMBOL_GPL(regulator_notifier_call_chain
);
2064 * regulator_mode_to_status - convert a regulator mode into a status
2066 * @mode: Mode to convert
2068 * Convert a regulator mode into a status.
2070 int regulator_mode_to_status(unsigned int mode
)
2073 case REGULATOR_MODE_FAST
:
2074 return REGULATOR_STATUS_FAST
;
2075 case REGULATOR_MODE_NORMAL
:
2076 return REGULATOR_STATUS_NORMAL
;
2077 case REGULATOR_MODE_IDLE
:
2078 return REGULATOR_STATUS_IDLE
;
2079 case REGULATOR_STATUS_STANDBY
:
2080 return REGULATOR_STATUS_STANDBY
;
2085 EXPORT_SYMBOL_GPL(regulator_mode_to_status
);
2088 * To avoid cluttering sysfs (and memory) with useless state, only
2089 * create attributes that can be meaningfully displayed.
2091 static int add_regulator_attributes(struct regulator_dev
*rdev
)
2093 struct device
*dev
= &rdev
->dev
;
2094 struct regulator_ops
*ops
= rdev
->desc
->ops
;
2097 /* some attributes need specific methods to be displayed */
2098 if (ops
->get_voltage
) {
2099 status
= device_create_file(dev
, &dev_attr_microvolts
);
2103 if (ops
->get_current_limit
) {
2104 status
= device_create_file(dev
, &dev_attr_microamps
);
2108 if (ops
->get_mode
) {
2109 status
= device_create_file(dev
, &dev_attr_opmode
);
2113 if (ops
->is_enabled
) {
2114 status
= device_create_file(dev
, &dev_attr_state
);
2118 if (ops
->get_status
) {
2119 status
= device_create_file(dev
, &dev_attr_status
);
2124 /* some attributes are type-specific */
2125 if (rdev
->desc
->type
== REGULATOR_CURRENT
) {
2126 status
= device_create_file(dev
, &dev_attr_requested_microamps
);
2131 /* all the other attributes exist to support constraints;
2132 * don't show them if there are no constraints, or if the
2133 * relevant supporting methods are missing.
2135 if (!rdev
->constraints
)
2138 /* constraints need specific supporting methods */
2139 if (ops
->set_voltage
) {
2140 status
= device_create_file(dev
, &dev_attr_min_microvolts
);
2143 status
= device_create_file(dev
, &dev_attr_max_microvolts
);
2147 if (ops
->set_current_limit
) {
2148 status
= device_create_file(dev
, &dev_attr_min_microamps
);
2151 status
= device_create_file(dev
, &dev_attr_max_microamps
);
2156 /* suspend mode constraints need multiple supporting methods */
2157 if (!(ops
->set_suspend_enable
&& ops
->set_suspend_disable
))
2160 status
= device_create_file(dev
, &dev_attr_suspend_standby_state
);
2163 status
= device_create_file(dev
, &dev_attr_suspend_mem_state
);
2166 status
= device_create_file(dev
, &dev_attr_suspend_disk_state
);
2170 if (ops
->set_suspend_voltage
) {
2171 status
= device_create_file(dev
,
2172 &dev_attr_suspend_standby_microvolts
);
2175 status
= device_create_file(dev
,
2176 &dev_attr_suspend_mem_microvolts
);
2179 status
= device_create_file(dev
,
2180 &dev_attr_suspend_disk_microvolts
);
2185 if (ops
->set_suspend_mode
) {
2186 status
= device_create_file(dev
,
2187 &dev_attr_suspend_standby_mode
);
2190 status
= device_create_file(dev
,
2191 &dev_attr_suspend_mem_mode
);
2194 status
= device_create_file(dev
,
2195 &dev_attr_suspend_disk_mode
);
2204 * regulator_register - register regulator
2205 * @regulator_desc: regulator to register
2206 * @dev: struct device for the regulator
2207 * @init_data: platform provided init data, passed through by driver
2208 * @driver_data: private regulator data
2210 * Called by regulator drivers to register a regulator.
2211 * Returns 0 on success.
2213 struct regulator_dev
*regulator_register(struct regulator_desc
*regulator_desc
,
2214 struct device
*dev
, struct regulator_init_data
*init_data
,
2217 static atomic_t regulator_no
= ATOMIC_INIT(0);
2218 struct regulator_dev
*rdev
;
2221 if (regulator_desc
== NULL
)
2222 return ERR_PTR(-EINVAL
);
2224 if (regulator_desc
->name
== NULL
|| regulator_desc
->ops
== NULL
)
2225 return ERR_PTR(-EINVAL
);
2227 if (regulator_desc
->type
!= REGULATOR_VOLTAGE
&&
2228 regulator_desc
->type
!= REGULATOR_CURRENT
)
2229 return ERR_PTR(-EINVAL
);
2232 return ERR_PTR(-EINVAL
);
2234 rdev
= kzalloc(sizeof(struct regulator_dev
), GFP_KERNEL
);
2236 return ERR_PTR(-ENOMEM
);
2238 mutex_lock(®ulator_list_mutex
);
2240 mutex_init(&rdev
->mutex
);
2241 rdev
->reg_data
= driver_data
;
2242 rdev
->owner
= regulator_desc
->owner
;
2243 rdev
->desc
= regulator_desc
;
2244 INIT_LIST_HEAD(&rdev
->consumer_list
);
2245 INIT_LIST_HEAD(&rdev
->supply_list
);
2246 INIT_LIST_HEAD(&rdev
->list
);
2247 INIT_LIST_HEAD(&rdev
->slist
);
2248 BLOCKING_INIT_NOTIFIER_HEAD(&rdev
->notifier
);
2250 /* preform any regulator specific init */
2251 if (init_data
->regulator_init
) {
2252 ret
= init_data
->regulator_init(rdev
->reg_data
);
2257 /* register with sysfs */
2258 rdev
->dev
.class = ®ulator_class
;
2259 rdev
->dev
.parent
= dev
;
2260 dev_set_name(&rdev
->dev
, "regulator.%d",
2261 atomic_inc_return(®ulator_no
) - 1);
2262 ret
= device_register(&rdev
->dev
);
2266 dev_set_drvdata(&rdev
->dev
, rdev
);
2268 /* set regulator constraints */
2269 ret
= set_machine_constraints(rdev
, &init_data
->constraints
);
2273 /* add attributes supported by this regulator */
2274 ret
= add_regulator_attributes(rdev
);
2278 /* set supply regulator if it exists */
2279 if (init_data
->supply_regulator_dev
) {
2280 ret
= set_supply(rdev
,
2281 dev_get_drvdata(init_data
->supply_regulator_dev
));
2286 /* add consumers devices */
2287 for (i
= 0; i
< init_data
->num_consumer_supplies
; i
++) {
2288 ret
= set_consumer_device_supply(rdev
,
2289 init_data
->consumer_supplies
[i
].dev
,
2290 init_data
->consumer_supplies
[i
].dev_name
,
2291 init_data
->consumer_supplies
[i
].supply
);
2293 for (--i
; i
>= 0; i
--)
2294 unset_consumer_device_supply(rdev
,
2295 init_data
->consumer_supplies
[i
].dev_name
,
2296 init_data
->consumer_supplies
[i
].dev
);
2301 list_add(&rdev
->list
, ®ulator_list
);
2303 mutex_unlock(®ulator_list_mutex
);
2307 device_unregister(&rdev
->dev
);
2308 /* device core frees rdev */
2309 rdev
= ERR_PTR(ret
);
2314 rdev
= ERR_PTR(ret
);
2317 EXPORT_SYMBOL_GPL(regulator_register
);
2320 * regulator_unregister - unregister regulator
2321 * @rdev: regulator to unregister
2323 * Called by regulator drivers to unregister a regulator.
2325 void regulator_unregister(struct regulator_dev
*rdev
)
2330 mutex_lock(®ulator_list_mutex
);
2331 WARN_ON(rdev
->open_count
);
2332 unset_regulator_supplies(rdev
);
2333 list_del(&rdev
->list
);
2335 sysfs_remove_link(&rdev
->dev
.kobj
, "supply");
2336 device_unregister(&rdev
->dev
);
2337 mutex_unlock(®ulator_list_mutex
);
2339 EXPORT_SYMBOL_GPL(regulator_unregister
);
2342 * regulator_suspend_prepare - prepare regulators for system wide suspend
2343 * @state: system suspend state
2345 * Configure each regulator with it's suspend operating parameters for state.
2346 * This will usually be called by machine suspend code prior to supending.
2348 int regulator_suspend_prepare(suspend_state_t state
)
2350 struct regulator_dev
*rdev
;
2353 /* ON is handled by regulator active state */
2354 if (state
== PM_SUSPEND_ON
)
2357 mutex_lock(®ulator_list_mutex
);
2358 list_for_each_entry(rdev
, ®ulator_list
, list
) {
2360 mutex_lock(&rdev
->mutex
);
2361 ret
= suspend_prepare(rdev
, state
);
2362 mutex_unlock(&rdev
->mutex
);
2365 printk(KERN_ERR
"%s: failed to prepare %s\n",
2366 __func__
, rdev_get_name(rdev
));
2371 mutex_unlock(®ulator_list_mutex
);
2374 EXPORT_SYMBOL_GPL(regulator_suspend_prepare
);
2377 * regulator_has_full_constraints - the system has fully specified constraints
2379 * Calling this function will cause the regulator API to disable all
2380 * regulators which have a zero use count and don't have an always_on
2381 * constraint in a late_initcall.
2383 * The intention is that this will become the default behaviour in a
2384 * future kernel release so users are encouraged to use this facility
2387 void regulator_has_full_constraints(void)
2389 has_full_constraints
= 1;
2391 EXPORT_SYMBOL_GPL(regulator_has_full_constraints
);
2394 * rdev_get_drvdata - get rdev regulator driver data
2397 * Get rdev regulator driver private data. This call can be used in the
2398 * regulator driver context.
2400 void *rdev_get_drvdata(struct regulator_dev
*rdev
)
2402 return rdev
->reg_data
;
2404 EXPORT_SYMBOL_GPL(rdev_get_drvdata
);
2407 * regulator_get_drvdata - get regulator driver data
2408 * @regulator: regulator
2410 * Get regulator driver private data. This call can be used in the consumer
2411 * driver context when non API regulator specific functions need to be called.
2413 void *regulator_get_drvdata(struct regulator
*regulator
)
2415 return regulator
->rdev
->reg_data
;
2417 EXPORT_SYMBOL_GPL(regulator_get_drvdata
);
2420 * regulator_set_drvdata - set regulator driver data
2421 * @regulator: regulator
2424 void regulator_set_drvdata(struct regulator
*regulator
, void *data
)
2426 regulator
->rdev
->reg_data
= data
;
2428 EXPORT_SYMBOL_GPL(regulator_set_drvdata
);
2431 * regulator_get_id - get regulator ID
2434 int rdev_get_id(struct regulator_dev
*rdev
)
2436 return rdev
->desc
->id
;
2438 EXPORT_SYMBOL_GPL(rdev_get_id
);
2440 struct device
*rdev_get_dev(struct regulator_dev
*rdev
)
2444 EXPORT_SYMBOL_GPL(rdev_get_dev
);
2446 void *regulator_get_init_drvdata(struct regulator_init_data
*reg_init_data
)
2448 return reg_init_data
->driver_data
;
2450 EXPORT_SYMBOL_GPL(regulator_get_init_drvdata
);
2452 static int __init
regulator_init(void)
2454 printk(KERN_INFO
"regulator: core version %s\n", REGULATOR_VERSION
);
2455 return class_register(®ulator_class
);
2458 /* init early to allow our consumers to complete system booting */
2459 core_initcall(regulator_init
);
2461 static int __init
regulator_init_complete(void)
2463 struct regulator_dev
*rdev
;
2464 struct regulator_ops
*ops
;
2465 struct regulation_constraints
*c
;
2469 mutex_lock(®ulator_list_mutex
);
2471 /* If we have a full configuration then disable any regulators
2472 * which are not in use or always_on. This will become the
2473 * default behaviour in the future.
2475 list_for_each_entry(rdev
, ®ulator_list
, list
) {
2476 ops
= rdev
->desc
->ops
;
2477 c
= rdev
->constraints
;
2479 name
= rdev_get_name(rdev
);
2481 if (!ops
->disable
|| (c
&& c
->always_on
))
2484 mutex_lock(&rdev
->mutex
);
2486 if (rdev
->use_count
)
2489 /* If we can't read the status assume it's on. */
2490 if (ops
->is_enabled
)
2491 enabled
= ops
->is_enabled(rdev
);
2498 if (has_full_constraints
) {
2499 /* We log since this may kill the system if it
2501 printk(KERN_INFO
"%s: disabling %s\n",
2503 ret
= ops
->disable(rdev
);
2506 "%s: couldn't disable %s: %d\n",
2507 __func__
, name
, ret
);
2510 /* The intention is that in future we will
2511 * assume that full constraints are provided
2512 * so warn even if we aren't going to do
2516 "%s: incomplete constraints, leaving %s on\n",
2521 mutex_unlock(&rdev
->mutex
);
2524 mutex_unlock(®ulator_list_mutex
);
2528 late_initcall(regulator_init_complete
);