2 * wm8350.c -- Voltage and current regulation for the Wolfson WM8350 PMIC
4 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
6 * Author: Liam Girdwood
7 * linux@wolfsonmicro.com
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.
15 #include <linux/module.h>
16 #include <linux/moduleparam.h>
17 #include <linux/init.h>
18 #include <linux/bitops.h>
19 #include <linux/err.h>
20 #include <linux/i2c.h>
21 #include <linux/mfd/wm8350/core.h>
22 #include <linux/mfd/wm8350/pmic.h>
23 #include <linux/platform_device.h>
24 #include <linux/regulator/driver.h>
25 #include <linux/regulator/machine.h>
27 /* Maximum value possible for VSEL */
28 #define WM8350_DCDC_MAX_VSEL 0x66
31 static const int isink_cur
[] = {
98 static int get_isink_val(int min_uA
, int max_uA
, u16
*setting
)
102 for (i
= 0; i
< ARRAY_SIZE(isink_cur
); i
++) {
103 if (min_uA
<= isink_cur
[i
] && max_uA
>= isink_cur
[i
]) {
111 static int wm8350_isink_set_current(struct regulator_dev
*rdev
, int min_uA
,
114 struct wm8350
*wm8350
= rdev_get_drvdata(rdev
);
115 int isink
= rdev_get_id(rdev
);
119 ret
= get_isink_val(min_uA
, max_uA
, &setting
);
125 val
= wm8350_reg_read(wm8350
, WM8350_CURRENT_SINK_DRIVER_A
) &
126 ~WM8350_CS1_ISEL_MASK
;
127 wm8350_reg_write(wm8350
, WM8350_CURRENT_SINK_DRIVER_A
,
131 val
= wm8350_reg_read(wm8350
, WM8350_CURRENT_SINK_DRIVER_B
) &
132 ~WM8350_CS1_ISEL_MASK
;
133 wm8350_reg_write(wm8350
, WM8350_CURRENT_SINK_DRIVER_B
,
143 static int wm8350_isink_get_current(struct regulator_dev
*rdev
)
145 struct wm8350
*wm8350
= rdev_get_drvdata(rdev
);
146 int isink
= rdev_get_id(rdev
);
151 val
= wm8350_reg_read(wm8350
, WM8350_CURRENT_SINK_DRIVER_A
) &
152 WM8350_CS1_ISEL_MASK
;
155 val
= wm8350_reg_read(wm8350
, WM8350_CURRENT_SINK_DRIVER_B
) &
156 WM8350_CS1_ISEL_MASK
;
162 return isink_cur
[val
];
165 /* turn on ISINK followed by DCDC */
166 static int wm8350_isink_enable(struct regulator_dev
*rdev
)
168 struct wm8350
*wm8350
= rdev_get_drvdata(rdev
);
169 int isink
= rdev_get_id(rdev
);
173 switch (wm8350
->pmic
.isink_A_dcdc
) {
176 wm8350_set_bits(wm8350
, WM8350_POWER_MGMT_7
,
178 wm8350_set_bits(wm8350
, WM8350_CSA_FLASH_CONTROL
,
180 wm8350_set_bits(wm8350
, WM8350_DCDC_LDO_REQUESTED
,
181 1 << (wm8350
->pmic
.isink_A_dcdc
-
189 switch (wm8350
->pmic
.isink_B_dcdc
) {
192 wm8350_set_bits(wm8350
, WM8350_POWER_MGMT_7
,
194 wm8350_set_bits(wm8350
, WM8350_CSB_FLASH_CONTROL
,
196 wm8350_set_bits(wm8350
, WM8350_DCDC_LDO_REQUESTED
,
197 1 << (wm8350
->pmic
.isink_B_dcdc
-
210 static int wm8350_isink_disable(struct regulator_dev
*rdev
)
212 struct wm8350
*wm8350
= rdev_get_drvdata(rdev
);
213 int isink
= rdev_get_id(rdev
);
217 switch (wm8350
->pmic
.isink_A_dcdc
) {
220 wm8350_clear_bits(wm8350
, WM8350_DCDC_LDO_REQUESTED
,
221 1 << (wm8350
->pmic
.isink_A_dcdc
-
223 wm8350_clear_bits(wm8350
, WM8350_POWER_MGMT_7
,
231 switch (wm8350
->pmic
.isink_B_dcdc
) {
234 wm8350_clear_bits(wm8350
, WM8350_DCDC_LDO_REQUESTED
,
235 1 << (wm8350
->pmic
.isink_B_dcdc
-
237 wm8350_clear_bits(wm8350
, WM8350_POWER_MGMT_7
,
250 static int wm8350_isink_is_enabled(struct regulator_dev
*rdev
)
252 struct wm8350
*wm8350
= rdev_get_drvdata(rdev
);
253 int isink
= rdev_get_id(rdev
);
257 return wm8350_reg_read(wm8350
, WM8350_CURRENT_SINK_DRIVER_A
) &
260 return wm8350_reg_read(wm8350
, WM8350_CURRENT_SINK_DRIVER_B
) &
266 static int wm8350_isink_enable_time(struct regulator_dev
*rdev
)
268 struct wm8350
*wm8350
= rdev_get_drvdata(rdev
);
269 int isink
= rdev_get_id(rdev
);
274 reg
= wm8350_reg_read(wm8350
, WM8350_CSA_FLASH_CONTROL
);
277 reg
= wm8350_reg_read(wm8350
, WM8350_CSB_FLASH_CONTROL
);
283 if (reg
& WM8350_CS1_FLASH_MODE
) {
284 switch (reg
& WM8350_CS1_ON_RAMP_MASK
) {
295 switch (reg
& WM8350_CS1_ON_RAMP_MASK
) {
311 int wm8350_isink_set_flash(struct wm8350
*wm8350
, int isink
, u16 mode
,
312 u16 trigger
, u16 duration
, u16 on_ramp
, u16 off_ramp
,
317 wm8350_reg_write(wm8350
, WM8350_CSA_FLASH_CONTROL
,
318 (mode
? WM8350_CS1_FLASH_MODE
: 0) |
319 (trigger
? WM8350_CS1_TRIGSRC
: 0) |
320 duration
| on_ramp
| off_ramp
| drive
);
323 wm8350_reg_write(wm8350
, WM8350_CSB_FLASH_CONTROL
,
324 (mode
? WM8350_CS2_FLASH_MODE
: 0) |
325 (trigger
? WM8350_CS2_TRIGSRC
: 0) |
326 duration
| on_ramp
| off_ramp
| drive
);
333 EXPORT_SYMBOL_GPL(wm8350_isink_set_flash
);
335 static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev
*rdev
, int uV
)
337 struct wm8350
*wm8350
= rdev_get_drvdata(rdev
);
338 int sel
, volt_reg
, dcdc
= rdev_get_id(rdev
);
341 dev_dbg(wm8350
->dev
, "%s %d mV %d\n", __func__
, dcdc
, uV
/ 1000);
345 volt_reg
= WM8350_DCDC1_LOW_POWER
;
348 volt_reg
= WM8350_DCDC3_LOW_POWER
;
351 volt_reg
= WM8350_DCDC4_LOW_POWER
;
354 volt_reg
= WM8350_DCDC6_LOW_POWER
;
362 sel
= regulator_map_voltage_linear(rdev
, uV
, uV
);
366 /* all DCDCs have same mV bits */
367 val
= wm8350_reg_read(wm8350
, volt_reg
) & ~WM8350_DC1_VSEL_MASK
;
368 wm8350_reg_write(wm8350
, volt_reg
, val
| sel
);
372 static int wm8350_dcdc_set_suspend_enable(struct regulator_dev
*rdev
)
374 struct wm8350
*wm8350
= rdev_get_drvdata(rdev
);
375 int dcdc
= rdev_get_id(rdev
);
380 val
= wm8350_reg_read(wm8350
, WM8350_DCDC1_LOW_POWER
)
381 & ~WM8350_DCDC_HIB_MODE_MASK
;
382 wm8350_reg_write(wm8350
, WM8350_DCDC1_LOW_POWER
,
383 val
| wm8350
->pmic
.dcdc1_hib_mode
);
386 val
= wm8350_reg_read(wm8350
, WM8350_DCDC3_LOW_POWER
)
387 & ~WM8350_DCDC_HIB_MODE_MASK
;
388 wm8350_reg_write(wm8350
, WM8350_DCDC3_LOW_POWER
,
389 val
| wm8350
->pmic
.dcdc3_hib_mode
);
392 val
= wm8350_reg_read(wm8350
, WM8350_DCDC4_LOW_POWER
)
393 & ~WM8350_DCDC_HIB_MODE_MASK
;
394 wm8350_reg_write(wm8350
, WM8350_DCDC4_LOW_POWER
,
395 val
| wm8350
->pmic
.dcdc4_hib_mode
);
398 val
= wm8350_reg_read(wm8350
, WM8350_DCDC6_LOW_POWER
)
399 & ~WM8350_DCDC_HIB_MODE_MASK
;
400 wm8350_reg_write(wm8350
, WM8350_DCDC6_LOW_POWER
,
401 val
| wm8350
->pmic
.dcdc6_hib_mode
);
412 static int wm8350_dcdc_set_suspend_disable(struct regulator_dev
*rdev
)
414 struct wm8350
*wm8350
= rdev_get_drvdata(rdev
);
415 int dcdc
= rdev_get_id(rdev
);
420 val
= wm8350_reg_read(wm8350
, WM8350_DCDC1_LOW_POWER
);
421 wm8350
->pmic
.dcdc1_hib_mode
= val
& WM8350_DCDC_HIB_MODE_MASK
;
422 wm8350_reg_write(wm8350
, WM8350_DCDC1_LOW_POWER
,
423 val
| WM8350_DCDC_HIB_MODE_DIS
);
426 val
= wm8350_reg_read(wm8350
, WM8350_DCDC3_LOW_POWER
);
427 wm8350
->pmic
.dcdc3_hib_mode
= val
& WM8350_DCDC_HIB_MODE_MASK
;
428 wm8350_reg_write(wm8350
, WM8350_DCDC3_LOW_POWER
,
429 val
| WM8350_DCDC_HIB_MODE_DIS
);
432 val
= wm8350_reg_read(wm8350
, WM8350_DCDC4_LOW_POWER
);
433 wm8350
->pmic
.dcdc4_hib_mode
= val
& WM8350_DCDC_HIB_MODE_MASK
;
434 wm8350_reg_write(wm8350
, WM8350_DCDC4_LOW_POWER
,
435 val
| WM8350_DCDC_HIB_MODE_DIS
);
438 val
= wm8350_reg_read(wm8350
, WM8350_DCDC6_LOW_POWER
);
439 wm8350
->pmic
.dcdc6_hib_mode
= val
& WM8350_DCDC_HIB_MODE_MASK
;
440 wm8350_reg_write(wm8350
, WM8350_DCDC6_LOW_POWER
,
441 val
| WM8350_DCDC_HIB_MODE_DIS
);
452 static int wm8350_dcdc25_set_suspend_enable(struct regulator_dev
*rdev
)
454 struct wm8350
*wm8350
= rdev_get_drvdata(rdev
);
455 int dcdc
= rdev_get_id(rdev
);
460 val
= wm8350_reg_read(wm8350
, WM8350_DCDC2_CONTROL
)
461 & ~WM8350_DC2_HIB_MODE_MASK
;
462 wm8350_reg_write(wm8350
, WM8350_DCDC2_CONTROL
, val
|
463 (WM8350_DC2_HIB_MODE_ACTIVE
<< WM8350_DC2_HIB_MODE_SHIFT
));
466 val
= wm8350_reg_read(wm8350
, WM8350_DCDC5_CONTROL
)
467 & ~WM8350_DC5_HIB_MODE_MASK
;
468 wm8350_reg_write(wm8350
, WM8350_DCDC5_CONTROL
, val
|
469 (WM8350_DC5_HIB_MODE_ACTIVE
<< WM8350_DC5_HIB_MODE_SHIFT
));
477 static int wm8350_dcdc25_set_suspend_disable(struct regulator_dev
*rdev
)
479 struct wm8350
*wm8350
= rdev_get_drvdata(rdev
);
480 int dcdc
= rdev_get_id(rdev
);
485 val
= wm8350_reg_read(wm8350
, WM8350_DCDC2_CONTROL
)
486 & ~WM8350_DC2_HIB_MODE_MASK
;
487 wm8350_reg_write(wm8350
, WM8350_DCDC2_CONTROL
, val
|
488 (WM8350_DC2_HIB_MODE_DISABLE
<< WM8350_DC2_HIB_MODE_SHIFT
));
491 val
= wm8350_reg_read(wm8350
, WM8350_DCDC5_CONTROL
)
492 & ~WM8350_DC5_HIB_MODE_MASK
;
493 wm8350_reg_write(wm8350
, WM8350_DCDC5_CONTROL
, val
|
494 (WM8350_DC5_HIB_MODE_DISABLE
<< WM8350_DC5_HIB_MODE_SHIFT
));
502 static int wm8350_dcdc_set_suspend_mode(struct regulator_dev
*rdev
,
505 struct wm8350
*wm8350
= rdev_get_drvdata(rdev
);
506 int dcdc
= rdev_get_id(rdev
);
511 hib_mode
= &wm8350
->pmic
.dcdc1_hib_mode
;
514 hib_mode
= &wm8350
->pmic
.dcdc3_hib_mode
;
517 hib_mode
= &wm8350
->pmic
.dcdc4_hib_mode
;
520 hib_mode
= &wm8350
->pmic
.dcdc6_hib_mode
;
529 case REGULATOR_MODE_NORMAL
:
530 *hib_mode
= WM8350_DCDC_HIB_MODE_IMAGE
;
532 case REGULATOR_MODE_IDLE
:
533 *hib_mode
= WM8350_DCDC_HIB_MODE_STANDBY
;
535 case REGULATOR_MODE_STANDBY
:
536 *hib_mode
= WM8350_DCDC_HIB_MODE_LDO_IM
;
545 static int wm8350_ldo_list_voltage(struct regulator_dev
*rdev
,
548 if (selector
> WM8350_LDO1_VSEL_MASK
)
552 return (selector
* 50000) + 900000;
554 return ((selector
- 16) * 100000) + 1800000;
557 static int wm8350_ldo_map_voltage(struct regulator_dev
*rdev
, int min_uV
,
561 int min_mV
= min_uV
/ 1000;
562 int max_mV
= max_uV
/ 1000;
564 if (min_mV
< 900 || min_mV
> 3300)
566 if (max_mV
< 900 || max_mV
> 3300)
569 if (min_mV
< 1800) /* step size is 50mV < 1800mV */
570 sel
= DIV_ROUND_UP(min_uV
- 900, 50);
571 else /* step size is 100mV > 1800mV */
572 sel
= DIV_ROUND_UP(min_uV
- 1800, 100) + 16;
574 volt
= wm8350_ldo_list_voltage(rdev
, sel
);
575 if (volt
< min_uV
|| volt
> max_uV
)
581 static int wm8350_ldo_set_suspend_voltage(struct regulator_dev
*rdev
, int uV
)
583 struct wm8350
*wm8350
= rdev_get_drvdata(rdev
);
584 int sel
, volt_reg
, ldo
= rdev_get_id(rdev
);
587 dev_dbg(wm8350
->dev
, "%s %d mV %d\n", __func__
, ldo
, uV
/ 1000);
591 volt_reg
= WM8350_LDO1_LOW_POWER
;
594 volt_reg
= WM8350_LDO2_LOW_POWER
;
597 volt_reg
= WM8350_LDO3_LOW_POWER
;
600 volt_reg
= WM8350_LDO4_LOW_POWER
;
606 sel
= wm8350_ldo_map_voltage(rdev
, uV
, uV
);
610 /* all LDOs have same mV bits */
611 val
= wm8350_reg_read(wm8350
, volt_reg
) & ~WM8350_LDO1_VSEL_MASK
;
612 wm8350_reg_write(wm8350
, volt_reg
, val
| sel
);
616 static int wm8350_ldo_set_suspend_enable(struct regulator_dev
*rdev
)
618 struct wm8350
*wm8350
= rdev_get_drvdata(rdev
);
619 int volt_reg
, ldo
= rdev_get_id(rdev
);
624 volt_reg
= WM8350_LDO1_LOW_POWER
;
627 volt_reg
= WM8350_LDO2_LOW_POWER
;
630 volt_reg
= WM8350_LDO3_LOW_POWER
;
633 volt_reg
= WM8350_LDO4_LOW_POWER
;
639 /* all LDOs have same mV bits */
640 val
= wm8350_reg_read(wm8350
, volt_reg
) & ~WM8350_LDO1_HIB_MODE_MASK
;
641 wm8350_reg_write(wm8350
, volt_reg
, val
);
645 static int wm8350_ldo_set_suspend_disable(struct regulator_dev
*rdev
)
647 struct wm8350
*wm8350
= rdev_get_drvdata(rdev
);
648 int volt_reg
, ldo
= rdev_get_id(rdev
);
653 volt_reg
= WM8350_LDO1_LOW_POWER
;
656 volt_reg
= WM8350_LDO2_LOW_POWER
;
659 volt_reg
= WM8350_LDO3_LOW_POWER
;
662 volt_reg
= WM8350_LDO4_LOW_POWER
;
668 /* all LDOs have same mV bits */
669 val
= wm8350_reg_read(wm8350
, volt_reg
) & ~WM8350_LDO1_HIB_MODE_MASK
;
670 wm8350_reg_write(wm8350
, volt_reg
, val
| WM8350_LDO1_HIB_MODE_DIS
);
674 int wm8350_dcdc_set_slot(struct wm8350
*wm8350
, int dcdc
, u16 start
,
680 dev_dbg(wm8350
->dev
, "%s %d start %d stop %d\n",
681 __func__
, dcdc
, start
, stop
);
684 if (start
> 15 || stop
> 15)
689 slot_reg
= WM8350_DCDC1_TIMEOUTS
;
692 slot_reg
= WM8350_DCDC2_TIMEOUTS
;
695 slot_reg
= WM8350_DCDC3_TIMEOUTS
;
698 slot_reg
= WM8350_DCDC4_TIMEOUTS
;
701 slot_reg
= WM8350_DCDC5_TIMEOUTS
;
704 slot_reg
= WM8350_DCDC6_TIMEOUTS
;
710 val
= wm8350_reg_read(wm8350
, slot_reg
) &
711 ~(WM8350_DC1_ENSLOT_MASK
| WM8350_DC1_SDSLOT_MASK
|
712 WM8350_DC1_ERRACT_MASK
);
713 wm8350_reg_write(wm8350
, slot_reg
,
714 val
| (start
<< WM8350_DC1_ENSLOT_SHIFT
) |
715 (stop
<< WM8350_DC1_SDSLOT_SHIFT
) |
716 (fault
<< WM8350_DC1_ERRACT_SHIFT
));
720 EXPORT_SYMBOL_GPL(wm8350_dcdc_set_slot
);
722 int wm8350_ldo_set_slot(struct wm8350
*wm8350
, int ldo
, u16 start
, u16 stop
)
727 dev_dbg(wm8350
->dev
, "%s %d start %d stop %d\n",
728 __func__
, ldo
, start
, stop
);
731 if (start
> 15 || stop
> 15)
736 slot_reg
= WM8350_LDO1_TIMEOUTS
;
739 slot_reg
= WM8350_LDO2_TIMEOUTS
;
742 slot_reg
= WM8350_LDO3_TIMEOUTS
;
745 slot_reg
= WM8350_LDO4_TIMEOUTS
;
751 val
= wm8350_reg_read(wm8350
, slot_reg
) & ~WM8350_LDO1_SDSLOT_MASK
;
752 wm8350_reg_write(wm8350
, slot_reg
, val
| ((start
<< 10) | (stop
<< 6)));
755 EXPORT_SYMBOL_GPL(wm8350_ldo_set_slot
);
757 int wm8350_dcdc25_set_mode(struct wm8350
*wm8350
, int dcdc
, u16 mode
,
758 u16 ilim
, u16 ramp
, u16 feedback
)
762 dev_dbg(wm8350
->dev
, "%s %d mode: %s %s\n", __func__
, dcdc
,
763 mode
? "normal" : "boost", ilim
? "low" : "normal");
767 val
= wm8350_reg_read(wm8350
, WM8350_DCDC2_CONTROL
)
768 & ~(WM8350_DC2_MODE_MASK
| WM8350_DC2_ILIM_MASK
|
769 WM8350_DC2_RMP_MASK
| WM8350_DC2_FBSRC_MASK
);
770 wm8350_reg_write(wm8350
, WM8350_DCDC2_CONTROL
, val
|
771 (mode
<< WM8350_DC2_MODE_SHIFT
) |
772 (ilim
<< WM8350_DC2_ILIM_SHIFT
) |
773 (ramp
<< WM8350_DC2_RMP_SHIFT
) |
774 (feedback
<< WM8350_DC2_FBSRC_SHIFT
));
777 val
= wm8350_reg_read(wm8350
, WM8350_DCDC5_CONTROL
)
778 & ~(WM8350_DC5_MODE_MASK
| WM8350_DC5_ILIM_MASK
|
779 WM8350_DC5_RMP_MASK
| WM8350_DC5_FBSRC_MASK
);
780 wm8350_reg_write(wm8350
, WM8350_DCDC5_CONTROL
, val
|
781 (mode
<< WM8350_DC5_MODE_SHIFT
) |
782 (ilim
<< WM8350_DC5_ILIM_SHIFT
) |
783 (ramp
<< WM8350_DC5_RMP_SHIFT
) |
784 (feedback
<< WM8350_DC5_FBSRC_SHIFT
));
792 EXPORT_SYMBOL_GPL(wm8350_dcdc25_set_mode
);
794 static int force_continuous_enable(struct wm8350
*wm8350
, int dcdc
, int enable
)
800 reg
= WM8350_DCDC1_FORCE_PWM
;
803 reg
= WM8350_DCDC3_FORCE_PWM
;
806 reg
= WM8350_DCDC4_FORCE_PWM
;
809 reg
= WM8350_DCDC6_FORCE_PWM
;
816 ret
= wm8350_set_bits(wm8350
, reg
,
817 WM8350_DCDC1_FORCE_PWM_ENA
);
819 ret
= wm8350_clear_bits(wm8350
, reg
,
820 WM8350_DCDC1_FORCE_PWM_ENA
);
824 static int wm8350_dcdc_set_mode(struct regulator_dev
*rdev
, unsigned int mode
)
826 struct wm8350
*wm8350
= rdev_get_drvdata(rdev
);
827 int dcdc
= rdev_get_id(rdev
);
830 if (dcdc
< WM8350_DCDC_1
|| dcdc
> WM8350_DCDC_6
)
833 if (dcdc
== WM8350_DCDC_2
|| dcdc
== WM8350_DCDC_5
)
836 val
= 1 << (dcdc
- WM8350_DCDC_1
);
839 case REGULATOR_MODE_FAST
:
840 /* force continuous mode */
841 wm8350_set_bits(wm8350
, WM8350_DCDC_ACTIVE_OPTIONS
, val
);
842 wm8350_clear_bits(wm8350
, WM8350_DCDC_SLEEP_OPTIONS
, val
);
843 force_continuous_enable(wm8350
, dcdc
, 1);
845 case REGULATOR_MODE_NORMAL
:
846 /* active / pulse skipping */
847 wm8350_set_bits(wm8350
, WM8350_DCDC_ACTIVE_OPTIONS
, val
);
848 wm8350_clear_bits(wm8350
, WM8350_DCDC_SLEEP_OPTIONS
, val
);
849 force_continuous_enable(wm8350
, dcdc
, 0);
851 case REGULATOR_MODE_IDLE
:
853 force_continuous_enable(wm8350
, dcdc
, 0);
854 wm8350_clear_bits(wm8350
, WM8350_DCDC_SLEEP_OPTIONS
, val
);
855 wm8350_clear_bits(wm8350
, WM8350_DCDC_ACTIVE_OPTIONS
, val
);
857 case REGULATOR_MODE_STANDBY
:
859 force_continuous_enable(wm8350
, dcdc
, 0);
860 wm8350_set_bits(wm8350
, WM8350_DCDC_SLEEP_OPTIONS
, val
);
867 static unsigned int wm8350_dcdc_get_mode(struct regulator_dev
*rdev
)
869 struct wm8350
*wm8350
= rdev_get_drvdata(rdev
);
870 int dcdc
= rdev_get_id(rdev
);
871 u16 mask
, sleep
, active
, force
;
872 int mode
= REGULATOR_MODE_NORMAL
;
877 reg
= WM8350_DCDC1_FORCE_PWM
;
880 reg
= WM8350_DCDC3_FORCE_PWM
;
883 reg
= WM8350_DCDC4_FORCE_PWM
;
886 reg
= WM8350_DCDC6_FORCE_PWM
;
892 mask
= 1 << (dcdc
- WM8350_DCDC_1
);
893 active
= wm8350_reg_read(wm8350
, WM8350_DCDC_ACTIVE_OPTIONS
) & mask
;
894 force
= wm8350_reg_read(wm8350
, reg
) & WM8350_DCDC1_FORCE_PWM_ENA
;
895 sleep
= wm8350_reg_read(wm8350
, WM8350_DCDC_SLEEP_OPTIONS
) & mask
;
897 dev_dbg(wm8350
->dev
, "mask %x active %x sleep %x force %x",
898 mask
, active
, sleep
, force
);
900 if (active
&& !sleep
) {
902 mode
= REGULATOR_MODE_FAST
;
904 mode
= REGULATOR_MODE_NORMAL
;
905 } else if (!active
&& !sleep
)
906 mode
= REGULATOR_MODE_IDLE
;
908 mode
= REGULATOR_MODE_STANDBY
;
913 static unsigned int wm8350_ldo_get_mode(struct regulator_dev
*rdev
)
915 return REGULATOR_MODE_NORMAL
;
918 struct wm8350_dcdc_efficiency
{
924 static const struct wm8350_dcdc_efficiency dcdc1_6_efficiency
[] = {
925 {0, 10000, REGULATOR_MODE_STANDBY
}, /* 0 - 10mA - LDO */
926 {10000, 100000, REGULATOR_MODE_IDLE
}, /* 10mA - 100mA - Standby */
927 {100000, 1000000, REGULATOR_MODE_NORMAL
}, /* > 100mA - Active */
928 {-1, -1, REGULATOR_MODE_NORMAL
},
931 static const struct wm8350_dcdc_efficiency dcdc3_4_efficiency
[] = {
932 {0, 10000, REGULATOR_MODE_STANDBY
}, /* 0 - 10mA - LDO */
933 {10000, 100000, REGULATOR_MODE_IDLE
}, /* 10mA - 100mA - Standby */
934 {100000, 800000, REGULATOR_MODE_NORMAL
}, /* > 100mA - Active */
935 {-1, -1, REGULATOR_MODE_NORMAL
},
938 static unsigned int get_mode(int uA
, const struct wm8350_dcdc_efficiency
*eff
)
942 while (eff
[i
].uA_load_min
!= -1) {
943 if (uA
>= eff
[i
].uA_load_min
&& uA
<= eff
[i
].uA_load_max
)
946 return REGULATOR_MODE_NORMAL
;
949 /* Query the regulator for it's most efficient mode @ uV,uA
950 * WM8350 regulator efficiency is pretty similar over
951 * different input and output uV.
953 static unsigned int wm8350_dcdc_get_optimum_mode(struct regulator_dev
*rdev
,
954 int input_uV
, int output_uV
,
957 int dcdc
= rdev_get_id(rdev
), mode
;
962 mode
= get_mode(output_uA
, dcdc1_6_efficiency
);
966 mode
= get_mode(output_uA
, dcdc3_4_efficiency
);
969 mode
= REGULATOR_MODE_NORMAL
;
975 static struct regulator_ops wm8350_dcdc_ops
= {
976 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
977 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
978 .list_voltage
= regulator_list_voltage_linear
,
979 .map_voltage
= regulator_map_voltage_linear
,
980 .enable
= regulator_enable_regmap
,
981 .disable
= regulator_disable_regmap
,
982 .is_enabled
= regulator_is_enabled_regmap
,
983 .get_mode
= wm8350_dcdc_get_mode
,
984 .set_mode
= wm8350_dcdc_set_mode
,
985 .get_optimum_mode
= wm8350_dcdc_get_optimum_mode
,
986 .set_suspend_voltage
= wm8350_dcdc_set_suspend_voltage
,
987 .set_suspend_enable
= wm8350_dcdc_set_suspend_enable
,
988 .set_suspend_disable
= wm8350_dcdc_set_suspend_disable
,
989 .set_suspend_mode
= wm8350_dcdc_set_suspend_mode
,
992 static struct regulator_ops wm8350_dcdc2_5_ops
= {
993 .enable
= regulator_enable_regmap
,
994 .disable
= regulator_disable_regmap
,
995 .is_enabled
= regulator_is_enabled_regmap
,
996 .set_suspend_enable
= wm8350_dcdc25_set_suspend_enable
,
997 .set_suspend_disable
= wm8350_dcdc25_set_suspend_disable
,
1000 static struct regulator_ops wm8350_ldo_ops
= {
1001 .map_voltage
= wm8350_ldo_map_voltage
,
1002 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
1003 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
1004 .list_voltage
= wm8350_ldo_list_voltage
,
1005 .enable
= regulator_enable_regmap
,
1006 .disable
= regulator_disable_regmap
,
1007 .is_enabled
= regulator_is_enabled_regmap
,
1008 .get_mode
= wm8350_ldo_get_mode
,
1009 .set_suspend_voltage
= wm8350_ldo_set_suspend_voltage
,
1010 .set_suspend_enable
= wm8350_ldo_set_suspend_enable
,
1011 .set_suspend_disable
= wm8350_ldo_set_suspend_disable
,
1014 static struct regulator_ops wm8350_isink_ops
= {
1015 .set_current_limit
= wm8350_isink_set_current
,
1016 .get_current_limit
= wm8350_isink_get_current
,
1017 .enable
= wm8350_isink_enable
,
1018 .disable
= wm8350_isink_disable
,
1019 .is_enabled
= wm8350_isink_is_enabled
,
1020 .enable_time
= wm8350_isink_enable_time
,
1023 static const struct regulator_desc wm8350_reg
[NUM_WM8350_REGULATORS
] = {
1026 .id
= WM8350_DCDC_1
,
1027 .ops
= &wm8350_dcdc_ops
,
1028 .irq
= WM8350_IRQ_UV_DC1
,
1029 .type
= REGULATOR_VOLTAGE
,
1030 .n_voltages
= WM8350_DCDC_MAX_VSEL
+ 1,
1033 .vsel_reg
= WM8350_DCDC1_CONTROL
,
1034 .vsel_mask
= WM8350_DC1_VSEL_MASK
,
1035 .enable_reg
= WM8350_DCDC_LDO_REQUESTED
,
1036 .enable_mask
= WM8350_DC1_ENA
,
1037 .owner
= THIS_MODULE
,
1041 .id
= WM8350_DCDC_2
,
1042 .ops
= &wm8350_dcdc2_5_ops
,
1043 .irq
= WM8350_IRQ_UV_DC2
,
1044 .type
= REGULATOR_VOLTAGE
,
1045 .enable_reg
= WM8350_DCDC_LDO_REQUESTED
,
1046 .enable_mask
= WM8350_DC2_ENA
,
1047 .owner
= THIS_MODULE
,
1051 .id
= WM8350_DCDC_3
,
1052 .ops
= &wm8350_dcdc_ops
,
1053 .irq
= WM8350_IRQ_UV_DC3
,
1054 .type
= REGULATOR_VOLTAGE
,
1055 .n_voltages
= WM8350_DCDC_MAX_VSEL
+ 1,
1058 .vsel_reg
= WM8350_DCDC3_CONTROL
,
1059 .vsel_mask
= WM8350_DC3_VSEL_MASK
,
1060 .enable_reg
= WM8350_DCDC_LDO_REQUESTED
,
1061 .enable_mask
= WM8350_DC3_ENA
,
1062 .owner
= THIS_MODULE
,
1066 .id
= WM8350_DCDC_4
,
1067 .ops
= &wm8350_dcdc_ops
,
1068 .irq
= WM8350_IRQ_UV_DC4
,
1069 .type
= REGULATOR_VOLTAGE
,
1070 .n_voltages
= WM8350_DCDC_MAX_VSEL
+ 1,
1073 .vsel_reg
= WM8350_DCDC4_CONTROL
,
1074 .vsel_mask
= WM8350_DC4_VSEL_MASK
,
1075 .enable_reg
= WM8350_DCDC_LDO_REQUESTED
,
1076 .enable_mask
= WM8350_DC4_ENA
,
1077 .owner
= THIS_MODULE
,
1081 .id
= WM8350_DCDC_5
,
1082 .ops
= &wm8350_dcdc2_5_ops
,
1083 .irq
= WM8350_IRQ_UV_DC5
,
1084 .type
= REGULATOR_VOLTAGE
,
1085 .enable_reg
= WM8350_DCDC_LDO_REQUESTED
,
1086 .enable_mask
= WM8350_DC5_ENA
,
1087 .owner
= THIS_MODULE
,
1091 .id
= WM8350_DCDC_6
,
1092 .ops
= &wm8350_dcdc_ops
,
1093 .irq
= WM8350_IRQ_UV_DC6
,
1094 .type
= REGULATOR_VOLTAGE
,
1095 .n_voltages
= WM8350_DCDC_MAX_VSEL
+ 1,
1098 .vsel_reg
= WM8350_DCDC6_CONTROL
,
1099 .vsel_mask
= WM8350_DC6_VSEL_MASK
,
1100 .enable_reg
= WM8350_DCDC_LDO_REQUESTED
,
1101 .enable_mask
= WM8350_DC6_ENA
,
1102 .owner
= THIS_MODULE
,
1107 .ops
= &wm8350_ldo_ops
,
1108 .irq
= WM8350_IRQ_UV_LDO1
,
1109 .type
= REGULATOR_VOLTAGE
,
1110 .n_voltages
= WM8350_LDO1_VSEL_MASK
+ 1,
1111 .vsel_reg
= WM8350_LDO1_CONTROL
,
1112 .vsel_mask
= WM8350_LDO1_VSEL_MASK
,
1113 .enable_reg
= WM8350_DCDC_LDO_REQUESTED
,
1114 .enable_mask
= WM8350_LDO1_ENA
,
1115 .owner
= THIS_MODULE
,
1120 .ops
= &wm8350_ldo_ops
,
1121 .irq
= WM8350_IRQ_UV_LDO2
,
1122 .type
= REGULATOR_VOLTAGE
,
1123 .n_voltages
= WM8350_LDO2_VSEL_MASK
+ 1,
1124 .vsel_reg
= WM8350_LDO2_CONTROL
,
1125 .vsel_mask
= WM8350_LDO2_VSEL_MASK
,
1126 .enable_reg
= WM8350_DCDC_LDO_REQUESTED
,
1127 .enable_mask
= WM8350_LDO2_ENA
,
1128 .owner
= THIS_MODULE
,
1133 .ops
= &wm8350_ldo_ops
,
1134 .irq
= WM8350_IRQ_UV_LDO3
,
1135 .type
= REGULATOR_VOLTAGE
,
1136 .n_voltages
= WM8350_LDO3_VSEL_MASK
+ 1,
1137 .vsel_reg
= WM8350_LDO3_CONTROL
,
1138 .vsel_mask
= WM8350_LDO3_VSEL_MASK
,
1139 .enable_reg
= WM8350_DCDC_LDO_REQUESTED
,
1140 .enable_mask
= WM8350_LDO3_ENA
,
1141 .owner
= THIS_MODULE
,
1146 .ops
= &wm8350_ldo_ops
,
1147 .irq
= WM8350_IRQ_UV_LDO4
,
1148 .type
= REGULATOR_VOLTAGE
,
1149 .n_voltages
= WM8350_LDO4_VSEL_MASK
+ 1,
1150 .vsel_reg
= WM8350_LDO4_CONTROL
,
1151 .vsel_mask
= WM8350_LDO4_VSEL_MASK
,
1152 .enable_reg
= WM8350_DCDC_LDO_REQUESTED
,
1153 .enable_mask
= WM8350_LDO4_ENA
,
1154 .owner
= THIS_MODULE
,
1158 .id
= WM8350_ISINK_A
,
1159 .ops
= &wm8350_isink_ops
,
1160 .irq
= WM8350_IRQ_CS1
,
1161 .type
= REGULATOR_CURRENT
,
1162 .owner
= THIS_MODULE
,
1166 .id
= WM8350_ISINK_B
,
1167 .ops
= &wm8350_isink_ops
,
1168 .irq
= WM8350_IRQ_CS2
,
1169 .type
= REGULATOR_CURRENT
,
1170 .owner
= THIS_MODULE
,
1174 static irqreturn_t
pmic_uv_handler(int irq
, void *data
)
1176 struct regulator_dev
*rdev
= (struct regulator_dev
*)data
;
1177 struct wm8350
*wm8350
= rdev_get_drvdata(rdev
);
1179 mutex_lock(&rdev
->mutex
);
1180 if (irq
== WM8350_IRQ_CS1
|| irq
== WM8350_IRQ_CS2
)
1181 regulator_notifier_call_chain(rdev
,
1182 REGULATOR_EVENT_REGULATION_OUT
,
1185 regulator_notifier_call_chain(rdev
,
1186 REGULATOR_EVENT_UNDER_VOLTAGE
,
1188 mutex_unlock(&rdev
->mutex
);
1193 static int wm8350_regulator_probe(struct platform_device
*pdev
)
1195 struct wm8350
*wm8350
= dev_get_drvdata(&pdev
->dev
);
1196 struct regulator_config config
= { };
1197 struct regulator_dev
*rdev
;
1201 if (pdev
->id
< WM8350_DCDC_1
|| pdev
->id
> WM8350_ISINK_B
)
1204 /* do any regulatior specific init */
1207 val
= wm8350_reg_read(wm8350
, WM8350_DCDC1_LOW_POWER
);
1208 wm8350
->pmic
.dcdc1_hib_mode
= val
& WM8350_DCDC_HIB_MODE_MASK
;
1211 val
= wm8350_reg_read(wm8350
, WM8350_DCDC3_LOW_POWER
);
1212 wm8350
->pmic
.dcdc3_hib_mode
= val
& WM8350_DCDC_HIB_MODE_MASK
;
1215 val
= wm8350_reg_read(wm8350
, WM8350_DCDC4_LOW_POWER
);
1216 wm8350
->pmic
.dcdc4_hib_mode
= val
& WM8350_DCDC_HIB_MODE_MASK
;
1219 val
= wm8350_reg_read(wm8350
, WM8350_DCDC6_LOW_POWER
);
1220 wm8350
->pmic
.dcdc6_hib_mode
= val
& WM8350_DCDC_HIB_MODE_MASK
;
1224 config
.dev
= &pdev
->dev
;
1225 config
.init_data
= pdev
->dev
.platform_data
;
1226 config
.driver_data
= dev_get_drvdata(&pdev
->dev
);
1227 config
.regmap
= wm8350
->regmap
;
1229 /* register regulator */
1230 rdev
= regulator_register(&wm8350_reg
[pdev
->id
], &config
);
1232 dev_err(&pdev
->dev
, "failed to register %s\n",
1233 wm8350_reg
[pdev
->id
].name
);
1234 return PTR_ERR(rdev
);
1237 /* register regulator IRQ */
1238 ret
= wm8350_register_irq(wm8350
, wm8350_reg
[pdev
->id
].irq
,
1239 pmic_uv_handler
, 0, "UV", rdev
);
1241 regulator_unregister(rdev
);
1242 dev_err(&pdev
->dev
, "failed to register regulator %s IRQ\n",
1243 wm8350_reg
[pdev
->id
].name
);
1250 static int wm8350_regulator_remove(struct platform_device
*pdev
)
1252 struct regulator_dev
*rdev
= platform_get_drvdata(pdev
);
1253 struct wm8350
*wm8350
= rdev_get_drvdata(rdev
);
1255 wm8350_free_irq(wm8350
, wm8350_reg
[pdev
->id
].irq
, rdev
);
1257 regulator_unregister(rdev
);
1262 int wm8350_register_regulator(struct wm8350
*wm8350
, int reg
,
1263 struct regulator_init_data
*initdata
)
1265 struct platform_device
*pdev
;
1267 if (reg
< 0 || reg
>= NUM_WM8350_REGULATORS
)
1270 if (wm8350
->pmic
.pdev
[reg
])
1273 if (reg
>= WM8350_DCDC_1
&& reg
<= WM8350_DCDC_6
&&
1274 reg
> wm8350
->pmic
.max_dcdc
)
1276 if (reg
>= WM8350_ISINK_A
&& reg
<= WM8350_ISINK_B
&&
1277 reg
> wm8350
->pmic
.max_isink
)
1280 pdev
= platform_device_alloc("wm8350-regulator", reg
);
1284 wm8350
->pmic
.pdev
[reg
] = pdev
;
1286 initdata
->driver_data
= wm8350
;
1288 pdev
->dev
.platform_data
= initdata
;
1289 pdev
->dev
.parent
= wm8350
->dev
;
1290 platform_set_drvdata(pdev
, wm8350
);
1292 ret
= platform_device_add(pdev
);
1295 dev_err(wm8350
->dev
, "Failed to register regulator %d: %d\n",
1297 platform_device_put(pdev
);
1298 wm8350
->pmic
.pdev
[reg
] = NULL
;
1303 EXPORT_SYMBOL_GPL(wm8350_register_regulator
);
1306 * wm8350_register_led - Register a WM8350 LED output
1308 * @param wm8350 The WM8350 device to configure.
1309 * @param lednum LED device index to create.
1310 * @param dcdc The DCDC to use for the LED.
1311 * @param isink The ISINK to use for the LED.
1312 * @param pdata Configuration for the LED.
1314 * The WM8350 supports the use of an ISINK together with a DCDC to
1315 * provide a power-efficient LED driver. This function registers the
1316 * regulators and instantiates the platform device for a LED. The
1317 * operating modes for the LED regulators must be configured using
1318 * wm8350_isink_set_flash(), wm8350_dcdc25_set_mode() and
1319 * wm8350_dcdc_set_slot() prior to calling this function.
1321 int wm8350_register_led(struct wm8350
*wm8350
, int lednum
, int dcdc
, int isink
,
1322 struct wm8350_led_platform_data
*pdata
)
1324 struct wm8350_led
*led
;
1325 struct platform_device
*pdev
;
1328 if (lednum
>= ARRAY_SIZE(wm8350
->pmic
.led
) || lednum
< 0) {
1329 dev_err(wm8350
->dev
, "Invalid LED index %d\n", lednum
);
1333 led
= &wm8350
->pmic
.led
[lednum
];
1336 dev_err(wm8350
->dev
, "LED %d already allocated\n", lednum
);
1340 pdev
= platform_device_alloc("wm8350-led", lednum
);
1342 dev_err(wm8350
->dev
, "Failed to allocate LED %d\n", lednum
);
1346 led
->isink_consumer
.dev_name
= dev_name(&pdev
->dev
);
1347 led
->isink_consumer
.supply
= "led_isink";
1348 led
->isink_init
.num_consumer_supplies
= 1;
1349 led
->isink_init
.consumer_supplies
= &led
->isink_consumer
;
1350 led
->isink_init
.constraints
.min_uA
= 0;
1351 led
->isink_init
.constraints
.max_uA
= pdata
->max_uA
;
1352 led
->isink_init
.constraints
.valid_ops_mask
1353 = REGULATOR_CHANGE_CURRENT
| REGULATOR_CHANGE_STATUS
;
1354 led
->isink_init
.constraints
.valid_modes_mask
= REGULATOR_MODE_NORMAL
;
1355 ret
= wm8350_register_regulator(wm8350
, isink
, &led
->isink_init
);
1357 platform_device_put(pdev
);
1361 led
->dcdc_consumer
.dev_name
= dev_name(&pdev
->dev
);
1362 led
->dcdc_consumer
.supply
= "led_vcc";
1363 led
->dcdc_init
.num_consumer_supplies
= 1;
1364 led
->dcdc_init
.consumer_supplies
= &led
->dcdc_consumer
;
1365 led
->dcdc_init
.constraints
.valid_modes_mask
= REGULATOR_MODE_NORMAL
;
1366 led
->dcdc_init
.constraints
.valid_ops_mask
= REGULATOR_CHANGE_STATUS
;
1367 ret
= wm8350_register_regulator(wm8350
, dcdc
, &led
->dcdc_init
);
1369 platform_device_put(pdev
);
1374 case WM8350_ISINK_A
:
1375 wm8350
->pmic
.isink_A_dcdc
= dcdc
;
1377 case WM8350_ISINK_B
:
1378 wm8350
->pmic
.isink_B_dcdc
= dcdc
;
1382 pdev
->dev
.platform_data
= pdata
;
1383 pdev
->dev
.parent
= wm8350
->dev
;
1384 ret
= platform_device_add(pdev
);
1386 dev_err(wm8350
->dev
, "Failed to register LED %d: %d\n",
1388 platform_device_put(pdev
);
1396 EXPORT_SYMBOL_GPL(wm8350_register_led
);
1398 static struct platform_driver wm8350_regulator_driver
= {
1399 .probe
= wm8350_regulator_probe
,
1400 .remove
= wm8350_regulator_remove
,
1402 .name
= "wm8350-regulator",
1406 static int __init
wm8350_regulator_init(void)
1408 return platform_driver_register(&wm8350_regulator_driver
);
1410 subsys_initcall(wm8350_regulator_init
);
1412 static void __exit
wm8350_regulator_exit(void)
1414 platform_driver_unregister(&wm8350_regulator_driver
);
1416 module_exit(wm8350_regulator_exit
);
1418 /* Module information */
1419 MODULE_AUTHOR("Liam Girdwood");
1420 MODULE_DESCRIPTION("WM8350 voltage and current regulator driver");
1421 MODULE_LICENSE("GPL");
1422 MODULE_ALIAS("platform:wm8350-regulator");