2 * helpers.c -- Voltage/Current Regulator framework helper functions.
4 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
5 * Copyright 2008 SlimLogic Ltd.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
14 #include <linux/kernel.h>
15 #include <linux/err.h>
16 #include <linux/delay.h>
17 #include <linux/regmap.h>
18 #include <linux/regulator/consumer.h>
19 #include <linux/regulator/driver.h>
20 #include <linux/module.h>
23 * regulator_is_enabled_regmap - standard is_enabled() for regmap users
25 * @rdev: regulator to operate on
27 * Regulators that use regmap for their register I/O can set the
28 * enable_reg and enable_mask fields in their descriptor and then use
29 * this as their is_enabled operation, saving some code.
31 int regulator_is_enabled_regmap(struct regulator_dev
*rdev
)
36 ret
= regmap_read(rdev
->regmap
, rdev
->desc
->enable_reg
, &val
);
40 val
&= rdev
->desc
->enable_mask
;
42 if (rdev
->desc
->enable_is_inverted
) {
43 if (rdev
->desc
->enable_val
)
44 return val
!= rdev
->desc
->enable_val
;
47 if (rdev
->desc
->enable_val
)
48 return val
== rdev
->desc
->enable_val
;
52 EXPORT_SYMBOL_GPL(regulator_is_enabled_regmap
);
55 * regulator_enable_regmap - standard enable() for regmap users
57 * @rdev: regulator to operate on
59 * Regulators that use regmap for their register I/O can set the
60 * enable_reg and enable_mask fields in their descriptor and then use
61 * this as their enable() operation, saving some code.
63 int regulator_enable_regmap(struct regulator_dev
*rdev
)
67 if (rdev
->desc
->enable_is_inverted
) {
68 val
= rdev
->desc
->disable_val
;
70 val
= rdev
->desc
->enable_val
;
72 val
= rdev
->desc
->enable_mask
;
75 return regmap_update_bits(rdev
->regmap
, rdev
->desc
->enable_reg
,
76 rdev
->desc
->enable_mask
, val
);
78 EXPORT_SYMBOL_GPL(regulator_enable_regmap
);
81 * regulator_disable_regmap - standard disable() for regmap users
83 * @rdev: regulator to operate on
85 * Regulators that use regmap for their register I/O can set the
86 * enable_reg and enable_mask fields in their descriptor and then use
87 * this as their disable() operation, saving some code.
89 int regulator_disable_regmap(struct regulator_dev
*rdev
)
93 if (rdev
->desc
->enable_is_inverted
) {
94 val
= rdev
->desc
->enable_val
;
96 val
= rdev
->desc
->enable_mask
;
98 val
= rdev
->desc
->disable_val
;
101 return regmap_update_bits(rdev
->regmap
, rdev
->desc
->enable_reg
,
102 rdev
->desc
->enable_mask
, val
);
104 EXPORT_SYMBOL_GPL(regulator_disable_regmap
);
106 static int regulator_range_selector_to_index(struct regulator_dev
*rdev
,
111 if (!rdev
->desc
->linear_range_selectors
)
114 rval
&= rdev
->desc
->vsel_range_mask
;
116 for (i
= 0; i
< rdev
->desc
->n_linear_ranges
; i
++) {
117 if (rdev
->desc
->linear_range_selectors
[i
] == rval
)
124 * regulator_get_voltage_sel_pickable_regmap - pickable range get_voltage_sel
126 * @rdev: regulator to operate on
128 * Regulators that use regmap for their register I/O and use pickable
129 * ranges can set the vsel_reg, vsel_mask, vsel_range_reg and vsel_range_mask
130 * fields in their descriptor and then use this as their get_voltage_vsel
131 * operation, saving some code.
133 int regulator_get_voltage_sel_pickable_regmap(struct regulator_dev
*rdev
)
139 unsigned int voltages_in_range
= 0;
141 if (!rdev
->desc
->linear_ranges
)
144 ret
= regmap_read(rdev
->regmap
, rdev
->desc
->vsel_reg
, &val
);
148 ret
= regmap_read(rdev
->regmap
, rdev
->desc
->vsel_range_reg
, &r_val
);
152 val
&= rdev
->desc
->vsel_mask
;
153 val
>>= ffs(rdev
->desc
->vsel_mask
) - 1;
155 range
= regulator_range_selector_to_index(rdev
, r_val
);
159 for (i
= 0; i
< range
; i
++)
160 voltages_in_range
+= (rdev
->desc
->linear_ranges
[i
].max_sel
-
161 rdev
->desc
->linear_ranges
[i
].min_sel
) + 1;
163 return val
+ voltages_in_range
;
165 EXPORT_SYMBOL_GPL(regulator_get_voltage_sel_pickable_regmap
);
168 * regulator_set_voltage_sel_pickable_regmap - pickable range set_voltage_sel
170 * @rdev: regulator to operate on
171 * @sel: Selector to set
173 * Regulators that use regmap for their register I/O and use pickable
174 * ranges can set the vsel_reg, vsel_mask, vsel_range_reg and vsel_range_mask
175 * fields in their descriptor and then use this as their set_voltage_vsel
176 * operation, saving some code.
178 int regulator_set_voltage_sel_pickable_regmap(struct regulator_dev
*rdev
,
183 unsigned int voltages_in_range
= 0;
185 for (i
= 0; i
< rdev
->desc
->n_linear_ranges
; i
++) {
186 voltages_in_range
= (rdev
->desc
->linear_ranges
[i
].max_sel
-
187 rdev
->desc
->linear_ranges
[i
].min_sel
) + 1;
188 if (sel
< voltages_in_range
)
190 sel
-= voltages_in_range
;
193 if (i
== rdev
->desc
->n_linear_ranges
)
196 sel
<<= ffs(rdev
->desc
->vsel_mask
) - 1;
197 sel
+= rdev
->desc
->linear_ranges
[i
].min_sel
;
199 range
= rdev
->desc
->linear_range_selectors
[i
];
201 if (rdev
->desc
->vsel_reg
== rdev
->desc
->vsel_range_reg
) {
202 ret
= regmap_update_bits(rdev
->regmap
,
203 rdev
->desc
->vsel_reg
,
204 rdev
->desc
->vsel_range_mask
|
205 rdev
->desc
->vsel_mask
, sel
| range
);
207 ret
= regmap_update_bits(rdev
->regmap
,
208 rdev
->desc
->vsel_range_reg
,
209 rdev
->desc
->vsel_range_mask
, range
);
213 ret
= regmap_update_bits(rdev
->regmap
, rdev
->desc
->vsel_reg
,
214 rdev
->desc
->vsel_mask
, sel
);
220 if (rdev
->desc
->apply_bit
)
221 ret
= regmap_update_bits(rdev
->regmap
, rdev
->desc
->apply_reg
,
222 rdev
->desc
->apply_bit
,
223 rdev
->desc
->apply_bit
);
226 EXPORT_SYMBOL_GPL(regulator_set_voltage_sel_pickable_regmap
);
229 * regulator_get_voltage_sel_regmap - standard get_voltage_sel for regmap users
231 * @rdev: regulator to operate on
233 * Regulators that use regmap for their register I/O can set the
234 * vsel_reg and vsel_mask fields in their descriptor and then use this
235 * as their get_voltage_vsel operation, saving some code.
237 int regulator_get_voltage_sel_regmap(struct regulator_dev
*rdev
)
242 ret
= regmap_read(rdev
->regmap
, rdev
->desc
->vsel_reg
, &val
);
246 val
&= rdev
->desc
->vsel_mask
;
247 val
>>= ffs(rdev
->desc
->vsel_mask
) - 1;
251 EXPORT_SYMBOL_GPL(regulator_get_voltage_sel_regmap
);
254 * regulator_set_voltage_sel_regmap - standard set_voltage_sel for regmap users
256 * @rdev: regulator to operate on
257 * @sel: Selector to set
259 * Regulators that use regmap for their register I/O can set the
260 * vsel_reg and vsel_mask fields in their descriptor and then use this
261 * as their set_voltage_vsel operation, saving some code.
263 int regulator_set_voltage_sel_regmap(struct regulator_dev
*rdev
, unsigned sel
)
267 sel
<<= ffs(rdev
->desc
->vsel_mask
) - 1;
269 ret
= regmap_update_bits(rdev
->regmap
, rdev
->desc
->vsel_reg
,
270 rdev
->desc
->vsel_mask
, sel
);
274 if (rdev
->desc
->apply_bit
)
275 ret
= regmap_update_bits(rdev
->regmap
, rdev
->desc
->apply_reg
,
276 rdev
->desc
->apply_bit
,
277 rdev
->desc
->apply_bit
);
280 EXPORT_SYMBOL_GPL(regulator_set_voltage_sel_regmap
);
283 * regulator_map_voltage_iterate - map_voltage() based on list_voltage()
285 * @rdev: Regulator to operate on
286 * @min_uV: Lower bound for voltage
287 * @max_uV: Upper bound for voltage
289 * Drivers implementing set_voltage_sel() and list_voltage() can use
290 * this as their map_voltage() operation. It will find a suitable
291 * voltage by calling list_voltage() until it gets something in bounds
292 * for the requested voltages.
294 int regulator_map_voltage_iterate(struct regulator_dev
*rdev
,
295 int min_uV
, int max_uV
)
297 int best_val
= INT_MAX
;
301 /* Find the smallest voltage that falls within the specified
304 for (i
= 0; i
< rdev
->desc
->n_voltages
; i
++) {
305 ret
= rdev
->desc
->ops
->list_voltage(rdev
, i
);
309 if (ret
< best_val
&& ret
>= min_uV
&& ret
<= max_uV
) {
315 if (best_val
!= INT_MAX
)
320 EXPORT_SYMBOL_GPL(regulator_map_voltage_iterate
);
323 * regulator_map_voltage_ascend - map_voltage() for ascendant voltage list
325 * @rdev: Regulator to operate on
326 * @min_uV: Lower bound for voltage
327 * @max_uV: Upper bound for voltage
329 * Drivers that have ascendant voltage list can use this as their
330 * map_voltage() operation.
332 int regulator_map_voltage_ascend(struct regulator_dev
*rdev
,
333 int min_uV
, int max_uV
)
337 for (i
= 0; i
< rdev
->desc
->n_voltages
; i
++) {
338 ret
= rdev
->desc
->ops
->list_voltage(rdev
, i
);
345 if (ret
>= min_uV
&& ret
<= max_uV
)
351 EXPORT_SYMBOL_GPL(regulator_map_voltage_ascend
);
354 * regulator_map_voltage_linear - map_voltage() for simple linear mappings
356 * @rdev: Regulator to operate on
357 * @min_uV: Lower bound for voltage
358 * @max_uV: Upper bound for voltage
360 * Drivers providing min_uV and uV_step in their regulator_desc can
361 * use this as their map_voltage() operation.
363 int regulator_map_voltage_linear(struct regulator_dev
*rdev
,
364 int min_uV
, int max_uV
)
368 /* Allow uV_step to be 0 for fixed voltage */
369 if (rdev
->desc
->n_voltages
== 1 && rdev
->desc
->uV_step
== 0) {
370 if (min_uV
<= rdev
->desc
->min_uV
&& rdev
->desc
->min_uV
<= max_uV
)
376 if (!rdev
->desc
->uV_step
) {
377 BUG_ON(!rdev
->desc
->uV_step
);
381 if (min_uV
< rdev
->desc
->min_uV
)
382 min_uV
= rdev
->desc
->min_uV
;
384 ret
= DIV_ROUND_UP(min_uV
- rdev
->desc
->min_uV
, rdev
->desc
->uV_step
);
388 ret
+= rdev
->desc
->linear_min_sel
;
390 /* Map back into a voltage to verify we're still in bounds */
391 voltage
= rdev
->desc
->ops
->list_voltage(rdev
, ret
);
392 if (voltage
< min_uV
|| voltage
> max_uV
)
397 EXPORT_SYMBOL_GPL(regulator_map_voltage_linear
);
400 * regulator_map_voltage_linear_range - map_voltage() for multiple linear ranges
402 * @rdev: Regulator to operate on
403 * @min_uV: Lower bound for voltage
404 * @max_uV: Upper bound for voltage
406 * Drivers providing linear_ranges in their descriptor can use this as
407 * their map_voltage() callback.
409 int regulator_map_voltage_linear_range(struct regulator_dev
*rdev
,
410 int min_uV
, int max_uV
)
412 const struct regulator_linear_range
*range
;
416 if (!rdev
->desc
->n_linear_ranges
) {
417 BUG_ON(!rdev
->desc
->n_linear_ranges
);
421 for (i
= 0; i
< rdev
->desc
->n_linear_ranges
; i
++) {
424 range
= &rdev
->desc
->linear_ranges
[i
];
425 linear_max_uV
= range
->min_uV
+
426 (range
->max_sel
- range
->min_sel
) * range
->uV_step
;
428 if (!(min_uV
<= linear_max_uV
&& max_uV
>= range
->min_uV
))
431 if (min_uV
<= range
->min_uV
)
432 min_uV
= range
->min_uV
;
434 /* range->uV_step == 0 means fixed voltage range */
435 if (range
->uV_step
== 0) {
438 ret
= DIV_ROUND_UP(min_uV
- range
->min_uV
,
444 ret
+= range
->min_sel
;
447 * Map back into a voltage to verify we're still in bounds.
448 * If we are not, then continue checking rest of the ranges.
450 voltage
= rdev
->desc
->ops
->list_voltage(rdev
, ret
);
451 if (voltage
>= min_uV
&& voltage
<= max_uV
)
455 if (i
== rdev
->desc
->n_linear_ranges
)
460 EXPORT_SYMBOL_GPL(regulator_map_voltage_linear_range
);
463 * regulator_map_voltage_pickable_linear_range - map_voltage, pickable ranges
465 * @rdev: Regulator to operate on
466 * @min_uV: Lower bound for voltage
467 * @max_uV: Upper bound for voltage
469 * Drivers providing pickable linear_ranges in their descriptor can use
470 * this as their map_voltage() callback.
472 int regulator_map_voltage_pickable_linear_range(struct regulator_dev
*rdev
,
473 int min_uV
, int max_uV
)
475 const struct regulator_linear_range
*range
;
478 unsigned int selector
= 0;
480 if (!rdev
->desc
->n_linear_ranges
) {
481 BUG_ON(!rdev
->desc
->n_linear_ranges
);
485 for (i
= 0; i
< rdev
->desc
->n_linear_ranges
; i
++) {
488 range
= &rdev
->desc
->linear_ranges
[i
];
489 linear_max_uV
= range
->min_uV
+
490 (range
->max_sel
- range
->min_sel
) * range
->uV_step
;
492 if (!(min_uV
<= linear_max_uV
&& max_uV
>= range
->min_uV
)) {
493 selector
+= (range
->max_sel
- range
->min_sel
+ 1);
497 if (min_uV
<= range
->min_uV
)
498 min_uV
= range
->min_uV
;
500 /* range->uV_step == 0 means fixed voltage range */
501 if (range
->uV_step
== 0) {
504 ret
= DIV_ROUND_UP(min_uV
- range
->min_uV
,
512 voltage
= rdev
->desc
->ops
->list_voltage(rdev
, ret
);
515 * Map back into a voltage to verify we're still in bounds.
516 * We may have overlapping voltage ranges. Hence we don't
517 * exit but retry until we have checked all ranges.
519 if (voltage
< min_uV
|| voltage
> max_uV
)
520 selector
+= (range
->max_sel
- range
->min_sel
+ 1);
525 if (i
== rdev
->desc
->n_linear_ranges
)
530 EXPORT_SYMBOL_GPL(regulator_map_voltage_pickable_linear_range
);
533 * regulator_list_voltage_linear - List voltages with simple calculation
535 * @rdev: Regulator device
536 * @selector: Selector to convert into a voltage
538 * Regulators with a simple linear mapping between voltages and
539 * selectors can set min_uV and uV_step in the regulator descriptor
540 * and then use this function as their list_voltage() operation,
542 int regulator_list_voltage_linear(struct regulator_dev
*rdev
,
543 unsigned int selector
)
545 if (selector
>= rdev
->desc
->n_voltages
)
547 if (selector
< rdev
->desc
->linear_min_sel
)
550 selector
-= rdev
->desc
->linear_min_sel
;
552 return rdev
->desc
->min_uV
+ (rdev
->desc
->uV_step
* selector
);
554 EXPORT_SYMBOL_GPL(regulator_list_voltage_linear
);
557 * regulator_list_voltage_pickable_linear_range - pickable range list voltages
559 * @rdev: Regulator device
560 * @selector: Selector to convert into a voltage
562 * list_voltage() operation, intended to be used by drivers utilizing pickable
565 int regulator_list_voltage_pickable_linear_range(struct regulator_dev
*rdev
,
566 unsigned int selector
)
568 const struct regulator_linear_range
*range
;
570 unsigned int all_sels
= 0;
572 if (!rdev
->desc
->n_linear_ranges
) {
573 BUG_ON(!rdev
->desc
->n_linear_ranges
);
577 for (i
= 0; i
< rdev
->desc
->n_linear_ranges
; i
++) {
578 unsigned int sels_in_range
;
580 range
= &rdev
->desc
->linear_ranges
[i
];
582 sels_in_range
= range
->max_sel
- range
->min_sel
;
584 if (all_sels
+ sels_in_range
>= selector
) {
585 selector
-= all_sels
;
586 return range
->min_uV
+ (range
->uV_step
* selector
);
589 all_sels
+= (sels_in_range
+ 1);
594 EXPORT_SYMBOL_GPL(regulator_list_voltage_pickable_linear_range
);
597 * regulator_desc_list_voltage_linear_range - List voltages for linear ranges
599 * @desc: Regulator desc for regulator which volatges are to be listed
600 * @selector: Selector to convert into a voltage
602 * Regulators with a series of simple linear mappings between voltages
603 * and selectors who have set linear_ranges in the regulator descriptor
604 * can use this function prior regulator registration to list voltages.
605 * This is useful when voltages need to be listed during device-tree
608 int regulator_desc_list_voltage_linear_range(const struct regulator_desc
*desc
,
609 unsigned int selector
)
611 const struct regulator_linear_range
*range
;
614 if (!desc
->n_linear_ranges
) {
615 BUG_ON(!desc
->n_linear_ranges
);
619 for (i
= 0; i
< desc
->n_linear_ranges
; i
++) {
620 range
= &desc
->linear_ranges
[i
];
622 if (!(selector
>= range
->min_sel
&&
623 selector
<= range
->max_sel
))
626 selector
-= range
->min_sel
;
628 return range
->min_uV
+ (range
->uV_step
* selector
);
633 EXPORT_SYMBOL_GPL(regulator_desc_list_voltage_linear_range
);
636 * regulator_list_voltage_linear_range - List voltages for linear ranges
638 * @rdev: Regulator device
639 * @selector: Selector to convert into a voltage
641 * Regulators with a series of simple linear mappings between voltages
642 * and selectors can set linear_ranges in the regulator descriptor and
643 * then use this function as their list_voltage() operation,
645 int regulator_list_voltage_linear_range(struct regulator_dev
*rdev
,
646 unsigned int selector
)
648 return regulator_desc_list_voltage_linear_range(rdev
->desc
, selector
);
650 EXPORT_SYMBOL_GPL(regulator_list_voltage_linear_range
);
653 * regulator_list_voltage_table - List voltages with table based mapping
655 * @rdev: Regulator device
656 * @selector: Selector to convert into a voltage
658 * Regulators with table based mapping between voltages and
659 * selectors can set volt_table in the regulator descriptor
660 * and then use this function as their list_voltage() operation.
662 int regulator_list_voltage_table(struct regulator_dev
*rdev
,
663 unsigned int selector
)
665 if (!rdev
->desc
->volt_table
) {
666 BUG_ON(!rdev
->desc
->volt_table
);
670 if (selector
>= rdev
->desc
->n_voltages
)
673 return rdev
->desc
->volt_table
[selector
];
675 EXPORT_SYMBOL_GPL(regulator_list_voltage_table
);
678 * regulator_set_bypass_regmap - Default set_bypass() using regmap
680 * @rdev: device to operate on.
681 * @enable: state to set.
683 int regulator_set_bypass_regmap(struct regulator_dev
*rdev
, bool enable
)
688 val
= rdev
->desc
->bypass_val_on
;
690 val
= rdev
->desc
->bypass_mask
;
692 val
= rdev
->desc
->bypass_val_off
;
695 return regmap_update_bits(rdev
->regmap
, rdev
->desc
->bypass_reg
,
696 rdev
->desc
->bypass_mask
, val
);
698 EXPORT_SYMBOL_GPL(regulator_set_bypass_regmap
);
701 * regulator_set_soft_start_regmap - Default set_soft_start() using regmap
703 * @rdev: device to operate on.
705 int regulator_set_soft_start_regmap(struct regulator_dev
*rdev
)
709 val
= rdev
->desc
->soft_start_val_on
;
711 val
= rdev
->desc
->soft_start_mask
;
713 return regmap_update_bits(rdev
->regmap
, rdev
->desc
->soft_start_reg
,
714 rdev
->desc
->soft_start_mask
, val
);
716 EXPORT_SYMBOL_GPL(regulator_set_soft_start_regmap
);
719 * regulator_set_pull_down_regmap - Default set_pull_down() using regmap
721 * @rdev: device to operate on.
723 int regulator_set_pull_down_regmap(struct regulator_dev
*rdev
)
727 val
= rdev
->desc
->pull_down_val_on
;
729 val
= rdev
->desc
->pull_down_mask
;
731 return regmap_update_bits(rdev
->regmap
, rdev
->desc
->pull_down_reg
,
732 rdev
->desc
->pull_down_mask
, val
);
734 EXPORT_SYMBOL_GPL(regulator_set_pull_down_regmap
);
737 * regulator_get_bypass_regmap - Default get_bypass() using regmap
739 * @rdev: device to operate on.
740 * @enable: current state.
742 int regulator_get_bypass_regmap(struct regulator_dev
*rdev
, bool *enable
)
745 unsigned int val_on
= rdev
->desc
->bypass_val_on
;
748 ret
= regmap_read(rdev
->regmap
, rdev
->desc
->bypass_reg
, &val
);
753 val_on
= rdev
->desc
->bypass_mask
;
755 *enable
= (val
& rdev
->desc
->bypass_mask
) == val_on
;
759 EXPORT_SYMBOL_GPL(regulator_get_bypass_regmap
);
762 * regulator_set_active_discharge_regmap - Default set_active_discharge()
765 * @rdev: device to operate on.
766 * @enable: state to set, 0 to disable and 1 to enable.
768 int regulator_set_active_discharge_regmap(struct regulator_dev
*rdev
,
774 val
= rdev
->desc
->active_discharge_on
;
776 val
= rdev
->desc
->active_discharge_off
;
778 return regmap_update_bits(rdev
->regmap
,
779 rdev
->desc
->active_discharge_reg
,
780 rdev
->desc
->active_discharge_mask
, val
);
782 EXPORT_SYMBOL_GPL(regulator_set_active_discharge_regmap
);
785 * regulator_set_current_limit_regmap - set_current_limit for regmap users
787 * @rdev: regulator to operate on
788 * @min_uA: Lower bound for current limit
789 * @max_uA: Upper bound for current limit
791 * Regulators that use regmap for their register I/O can set curr_table,
792 * csel_reg and csel_mask fields in their descriptor and then use this
793 * as their set_current_limit operation, saving some code.
795 int regulator_set_current_limit_regmap(struct regulator_dev
*rdev
,
796 int min_uA
, int max_uA
)
798 unsigned int n_currents
= rdev
->desc
->n_current_limits
;
804 if (rdev
->desc
->curr_table
) {
805 const unsigned int *curr_table
= rdev
->desc
->curr_table
;
806 bool ascend
= curr_table
[n_currents
- 1] > curr_table
[0];
808 /* search for closest to maximum */
810 for (i
= n_currents
- 1; i
>= 0; i
--) {
811 if (min_uA
<= curr_table
[i
] &&
812 curr_table
[i
] <= max_uA
) {
818 for (i
= 0; i
< n_currents
; i
++) {
819 if (min_uA
<= curr_table
[i
] &&
820 curr_table
[i
] <= max_uA
) {
831 sel
<<= ffs(rdev
->desc
->csel_mask
) - 1;
833 return regmap_update_bits(rdev
->regmap
, rdev
->desc
->csel_reg
,
834 rdev
->desc
->csel_mask
, sel
);
836 EXPORT_SYMBOL_GPL(regulator_set_current_limit_regmap
);
839 * regulator_get_current_limit_regmap - get_current_limit for regmap users
841 * @rdev: regulator to operate on
843 * Regulators that use regmap for their register I/O can set the
844 * csel_reg and csel_mask fields in their descriptor and then use this
845 * as their get_current_limit operation, saving some code.
847 int regulator_get_current_limit_regmap(struct regulator_dev
*rdev
)
852 ret
= regmap_read(rdev
->regmap
, rdev
->desc
->csel_reg
, &val
);
856 val
&= rdev
->desc
->csel_mask
;
857 val
>>= ffs(rdev
->desc
->csel_mask
) - 1;
859 if (rdev
->desc
->curr_table
) {
860 if (val
>= rdev
->desc
->n_current_limits
)
863 return rdev
->desc
->curr_table
[val
];
868 EXPORT_SYMBOL_GPL(regulator_get_current_limit_regmap
);