1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2014, Sony Mobile Communications AB.
4 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
7 #include <linux/module.h>
8 #include <linux/platform_device.h>
10 #include <linux/of_device.h>
11 #include <linux/regulator/driver.h>
12 #include <linux/regulator/machine.h>
13 #include <linux/regulator/of_regulator.h>
14 #include <linux/mfd/qcom_rpm.h>
16 #include <dt-bindings/mfd/qcom-rpm.h>
18 #define MAX_REQUEST_LEN 2
20 struct request_member
{
26 struct rpm_reg_parts
{
27 struct request_member mV
; /* used if voltage is in mV */
28 struct request_member uV
; /* used if voltage is in uV */
29 struct request_member ip
; /* peak current in mA */
30 struct request_member pd
; /* pull down enable */
31 struct request_member ia
; /* average current in mA */
32 struct request_member fm
; /* force mode */
33 struct request_member pm
; /* power mode */
34 struct request_member pc
; /* pin control */
35 struct request_member pf
; /* pin function */
36 struct request_member enable_state
; /* NCP and switch */
37 struct request_member comp_mode
; /* NCP */
38 struct request_member freq
; /* frequency: NCP and SMPS */
39 struct request_member freq_clk_src
; /* clock source: SMPS */
40 struct request_member hpm
; /* switch: control OCP and SS */
44 #define FORCE_MODE_IS_2_BITS(reg) \
45 (((reg)->parts->fm.mask >> (reg)->parts->fm.shift) == 3)
52 struct regulator_desc desc
;
53 const struct rpm_reg_parts
*parts
;
56 u32 val
[MAX_REQUEST_LEN
];
61 bool supports_force_mode_auto
;
62 bool supports_force_mode_bypass
;
65 static const struct rpm_reg_parts rpm8660_ldo_parts
= {
67 .mV
= { 0, 0x00000FFF, 0 },
68 .ip
= { 0, 0x00FFF000, 12 },
69 .fm
= { 0, 0x03000000, 24 },
70 .pc
= { 0, 0x3C000000, 26 },
71 .pf
= { 0, 0xC0000000, 30 },
72 .pd
= { 1, 0x00000001, 0 },
73 .ia
= { 1, 0x00001FFE, 1 },
76 static const struct rpm_reg_parts rpm8660_smps_parts
= {
78 .mV
= { 0, 0x00000FFF, 0 },
79 .ip
= { 0, 0x00FFF000, 12 },
80 .fm
= { 0, 0x03000000, 24 },
81 .pc
= { 0, 0x3C000000, 26 },
82 .pf
= { 0, 0xC0000000, 30 },
83 .pd
= { 1, 0x00000001, 0 },
84 .ia
= { 1, 0x00001FFE, 1 },
85 .freq
= { 1, 0x001FE000, 13 },
86 .freq_clk_src
= { 1, 0x00600000, 21 },
89 static const struct rpm_reg_parts rpm8660_switch_parts
= {
91 .enable_state
= { 0, 0x00000001, 0 },
92 .pd
= { 0, 0x00000002, 1 },
93 .pc
= { 0, 0x0000003C, 2 },
94 .pf
= { 0, 0x000000C0, 6 },
95 .hpm
= { 0, 0x00000300, 8 },
98 static const struct rpm_reg_parts rpm8660_ncp_parts
= {
100 .mV
= { 0, 0x00000FFF, 0 },
101 .enable_state
= { 0, 0x00001000, 12 },
102 .comp_mode
= { 0, 0x00002000, 13 },
103 .freq
= { 0, 0x003FC000, 14 },
106 static const struct rpm_reg_parts rpm8960_ldo_parts
= {
108 .uV
= { 0, 0x007FFFFF, 0 },
109 .pd
= { 0, 0x00800000, 23 },
110 .pc
= { 0, 0x0F000000, 24 },
111 .pf
= { 0, 0xF0000000, 28 },
112 .ip
= { 1, 0x000003FF, 0 },
113 .ia
= { 1, 0x000FFC00, 10 },
114 .fm
= { 1, 0x00700000, 20 },
117 static const struct rpm_reg_parts rpm8960_smps_parts
= {
119 .uV
= { 0, 0x007FFFFF, 0 },
120 .pd
= { 0, 0x00800000, 23 },
121 .pc
= { 0, 0x0F000000, 24 },
122 .pf
= { 0, 0xF0000000, 28 },
123 .ip
= { 1, 0x000003FF, 0 },
124 .ia
= { 1, 0x000FFC00, 10 },
125 .fm
= { 1, 0x00700000, 20 },
126 .pm
= { 1, 0x00800000, 23 },
127 .freq
= { 1, 0x1F000000, 24 },
128 .freq_clk_src
= { 1, 0x60000000, 29 },
131 static const struct rpm_reg_parts rpm8960_switch_parts
= {
133 .enable_state
= { 0, 0x00000001, 0 },
134 .pd
= { 0, 0x00000002, 1 },
135 .pc
= { 0, 0x0000003C, 2 },
136 .pf
= { 0, 0x000003C0, 6 },
137 .hpm
= { 0, 0x00000C00, 10 },
140 static const struct rpm_reg_parts rpm8960_ncp_parts
= {
142 .uV
= { 0, 0x007FFFFF, 0 },
143 .enable_state
= { 0, 0x00800000, 23 },
144 .comp_mode
= { 0, 0x01000000, 24 },
145 .freq
= { 0, 0x3E000000, 25 },
149 * Physically available PMIC regulator voltage ranges
151 static const struct linear_range pldo_ranges
[] = {
152 REGULATOR_LINEAR_RANGE( 750000, 0, 59, 12500),
153 REGULATOR_LINEAR_RANGE(1500000, 60, 123, 25000),
154 REGULATOR_LINEAR_RANGE(3100000, 124, 160, 50000),
157 static const struct linear_range nldo_ranges
[] = {
158 REGULATOR_LINEAR_RANGE( 750000, 0, 63, 12500),
161 static const struct linear_range nldo1200_ranges
[] = {
162 REGULATOR_LINEAR_RANGE( 375000, 0, 59, 6250),
163 REGULATOR_LINEAR_RANGE( 750000, 60, 123, 12500),
166 static const struct linear_range smps_ranges
[] = {
167 REGULATOR_LINEAR_RANGE( 375000, 0, 29, 12500),
168 REGULATOR_LINEAR_RANGE( 750000, 30, 89, 12500),
169 REGULATOR_LINEAR_RANGE(1500000, 90, 153, 25000),
172 static const struct linear_range ftsmps_ranges
[] = {
173 REGULATOR_LINEAR_RANGE( 350000, 0, 6, 50000),
174 REGULATOR_LINEAR_RANGE( 700000, 7, 63, 12500),
175 REGULATOR_LINEAR_RANGE(1500000, 64, 100, 50000),
178 static const struct linear_range smb208_ranges
[] = {
179 REGULATOR_LINEAR_RANGE( 375000, 0, 29, 12500),
180 REGULATOR_LINEAR_RANGE( 750000, 30, 89, 12500),
181 REGULATOR_LINEAR_RANGE(1500000, 90, 153, 25000),
182 REGULATOR_LINEAR_RANGE(3100000, 154, 234, 25000),
185 static const struct linear_range ncp_ranges
[] = {
186 REGULATOR_LINEAR_RANGE(1500000, 0, 31, 50000),
189 static int rpm_reg_write(struct qcom_rpm_reg
*vreg
,
190 const struct request_member
*req
,
193 if (WARN_ON((value
<< req
->shift
) & ~req
->mask
))
196 vreg
->val
[req
->word
] &= ~req
->mask
;
197 vreg
->val
[req
->word
] |= value
<< req
->shift
;
199 return qcom_rpm_write(vreg
->rpm
,
200 QCOM_RPM_ACTIVE_STATE
,
203 vreg
->parts
->request_len
);
206 static int rpm_reg_set_mV_sel(struct regulator_dev
*rdev
,
209 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
210 const struct rpm_reg_parts
*parts
= vreg
->parts
;
211 const struct request_member
*req
= &parts
->mV
;
218 uV
= regulator_list_voltage_linear_range(rdev
, selector
);
222 mutex_lock(&vreg
->lock
);
223 if (vreg
->is_enabled
)
224 ret
= rpm_reg_write(vreg
, req
, uV
/ 1000);
228 mutex_unlock(&vreg
->lock
);
233 static int rpm_reg_set_uV_sel(struct regulator_dev
*rdev
,
236 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
237 const struct rpm_reg_parts
*parts
= vreg
->parts
;
238 const struct request_member
*req
= &parts
->uV
;
245 uV
= regulator_list_voltage_linear_range(rdev
, selector
);
249 mutex_lock(&vreg
->lock
);
250 if (vreg
->is_enabled
)
251 ret
= rpm_reg_write(vreg
, req
, uV
);
255 mutex_unlock(&vreg
->lock
);
260 static int rpm_reg_get_voltage(struct regulator_dev
*rdev
)
262 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
267 static int rpm_reg_mV_enable(struct regulator_dev
*rdev
)
269 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
270 const struct rpm_reg_parts
*parts
= vreg
->parts
;
271 const struct request_member
*req
= &parts
->mV
;
277 mutex_lock(&vreg
->lock
);
278 ret
= rpm_reg_write(vreg
, req
, vreg
->uV
/ 1000);
280 vreg
->is_enabled
= 1;
281 mutex_unlock(&vreg
->lock
);
286 static int rpm_reg_uV_enable(struct regulator_dev
*rdev
)
288 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
289 const struct rpm_reg_parts
*parts
= vreg
->parts
;
290 const struct request_member
*req
= &parts
->uV
;
296 mutex_lock(&vreg
->lock
);
297 ret
= rpm_reg_write(vreg
, req
, vreg
->uV
);
299 vreg
->is_enabled
= 1;
300 mutex_unlock(&vreg
->lock
);
305 static int rpm_reg_switch_enable(struct regulator_dev
*rdev
)
307 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
308 const struct rpm_reg_parts
*parts
= vreg
->parts
;
309 const struct request_member
*req
= &parts
->enable_state
;
315 mutex_lock(&vreg
->lock
);
316 ret
= rpm_reg_write(vreg
, req
, 1);
318 vreg
->is_enabled
= 1;
319 mutex_unlock(&vreg
->lock
);
324 static int rpm_reg_mV_disable(struct regulator_dev
*rdev
)
326 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
327 const struct rpm_reg_parts
*parts
= vreg
->parts
;
328 const struct request_member
*req
= &parts
->mV
;
334 mutex_lock(&vreg
->lock
);
335 ret
= rpm_reg_write(vreg
, req
, 0);
337 vreg
->is_enabled
= 0;
338 mutex_unlock(&vreg
->lock
);
343 static int rpm_reg_uV_disable(struct regulator_dev
*rdev
)
345 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
346 const struct rpm_reg_parts
*parts
= vreg
->parts
;
347 const struct request_member
*req
= &parts
->uV
;
353 mutex_lock(&vreg
->lock
);
354 ret
= rpm_reg_write(vreg
, req
, 0);
356 vreg
->is_enabled
= 0;
357 mutex_unlock(&vreg
->lock
);
362 static int rpm_reg_switch_disable(struct regulator_dev
*rdev
)
364 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
365 const struct rpm_reg_parts
*parts
= vreg
->parts
;
366 const struct request_member
*req
= &parts
->enable_state
;
372 mutex_lock(&vreg
->lock
);
373 ret
= rpm_reg_write(vreg
, req
, 0);
375 vreg
->is_enabled
= 0;
376 mutex_unlock(&vreg
->lock
);
381 static int rpm_reg_is_enabled(struct regulator_dev
*rdev
)
383 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
385 return vreg
->is_enabled
;
388 static int rpm_reg_set_load(struct regulator_dev
*rdev
, int load_uA
)
390 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
391 const struct rpm_reg_parts
*parts
= vreg
->parts
;
392 const struct request_member
*req
= &parts
->ia
;
393 int load_mA
= load_uA
/ 1000;
394 int max_mA
= req
->mask
>> req
->shift
;
400 if (load_mA
> max_mA
)
403 mutex_lock(&vreg
->lock
);
404 ret
= rpm_reg_write(vreg
, req
, load_mA
);
405 mutex_unlock(&vreg
->lock
);
410 static const struct regulator_ops uV_ops
= {
411 .list_voltage
= regulator_list_voltage_linear_range
,
413 .set_voltage_sel
= rpm_reg_set_uV_sel
,
414 .get_voltage
= rpm_reg_get_voltage
,
416 .enable
= rpm_reg_uV_enable
,
417 .disable
= rpm_reg_uV_disable
,
418 .is_enabled
= rpm_reg_is_enabled
,
420 .set_load
= rpm_reg_set_load
,
423 static const struct regulator_ops mV_ops
= {
424 .list_voltage
= regulator_list_voltage_linear_range
,
426 .set_voltage_sel
= rpm_reg_set_mV_sel
,
427 .get_voltage
= rpm_reg_get_voltage
,
429 .enable
= rpm_reg_mV_enable
,
430 .disable
= rpm_reg_mV_disable
,
431 .is_enabled
= rpm_reg_is_enabled
,
433 .set_load
= rpm_reg_set_load
,
436 static const struct regulator_ops switch_ops
= {
437 .enable
= rpm_reg_switch_enable
,
438 .disable
= rpm_reg_switch_disable
,
439 .is_enabled
= rpm_reg_is_enabled
,
445 static const struct qcom_rpm_reg pm8018_pldo
= {
446 .desc
.linear_ranges
= pldo_ranges
,
447 .desc
.n_linear_ranges
= ARRAY_SIZE(pldo_ranges
),
448 .desc
.n_voltages
= 161,
450 .parts
= &rpm8960_ldo_parts
,
451 .supports_force_mode_auto
= false,
452 .supports_force_mode_bypass
= false,
455 static const struct qcom_rpm_reg pm8018_nldo
= {
456 .desc
.linear_ranges
= nldo_ranges
,
457 .desc
.n_linear_ranges
= ARRAY_SIZE(nldo_ranges
),
458 .desc
.n_voltages
= 64,
460 .parts
= &rpm8960_ldo_parts
,
461 .supports_force_mode_auto
= false,
462 .supports_force_mode_bypass
= false,
465 static const struct qcom_rpm_reg pm8018_smps
= {
466 .desc
.linear_ranges
= smps_ranges
,
467 .desc
.n_linear_ranges
= ARRAY_SIZE(smps_ranges
),
468 .desc
.n_voltages
= 154,
470 .parts
= &rpm8960_smps_parts
,
471 .supports_force_mode_auto
= false,
472 .supports_force_mode_bypass
= false,
475 static const struct qcom_rpm_reg pm8018_switch
= {
476 .desc
.ops
= &switch_ops
,
477 .parts
= &rpm8960_switch_parts
,
483 static const struct qcom_rpm_reg pm8058_pldo
= {
484 .desc
.linear_ranges
= pldo_ranges
,
485 .desc
.n_linear_ranges
= ARRAY_SIZE(pldo_ranges
),
486 .desc
.n_voltages
= 161,
488 .parts
= &rpm8660_ldo_parts
,
489 .supports_force_mode_auto
= false,
490 .supports_force_mode_bypass
= false,
493 static const struct qcom_rpm_reg pm8058_nldo
= {
494 .desc
.linear_ranges
= nldo_ranges
,
495 .desc
.n_linear_ranges
= ARRAY_SIZE(nldo_ranges
),
496 .desc
.n_voltages
= 64,
498 .parts
= &rpm8660_ldo_parts
,
499 .supports_force_mode_auto
= false,
500 .supports_force_mode_bypass
= false,
503 static const struct qcom_rpm_reg pm8058_smps
= {
504 .desc
.linear_ranges
= smps_ranges
,
505 .desc
.n_linear_ranges
= ARRAY_SIZE(smps_ranges
),
506 .desc
.n_voltages
= 154,
508 .parts
= &rpm8660_smps_parts
,
509 .supports_force_mode_auto
= false,
510 .supports_force_mode_bypass
= false,
513 static const struct qcom_rpm_reg pm8058_ncp
= {
514 .desc
.linear_ranges
= ncp_ranges
,
515 .desc
.n_linear_ranges
= ARRAY_SIZE(ncp_ranges
),
516 .desc
.n_voltages
= 32,
518 .parts
= &rpm8660_ncp_parts
,
521 static const struct qcom_rpm_reg pm8058_switch
= {
522 .desc
.ops
= &switch_ops
,
523 .parts
= &rpm8660_switch_parts
,
529 static const struct qcom_rpm_reg pm8901_pldo
= {
530 .desc
.linear_ranges
= pldo_ranges
,
531 .desc
.n_linear_ranges
= ARRAY_SIZE(pldo_ranges
),
532 .desc
.n_voltages
= 161,
534 .parts
= &rpm8660_ldo_parts
,
535 .supports_force_mode_auto
= false,
536 .supports_force_mode_bypass
= true,
539 static const struct qcom_rpm_reg pm8901_nldo
= {
540 .desc
.linear_ranges
= nldo_ranges
,
541 .desc
.n_linear_ranges
= ARRAY_SIZE(nldo_ranges
),
542 .desc
.n_voltages
= 64,
544 .parts
= &rpm8660_ldo_parts
,
545 .supports_force_mode_auto
= false,
546 .supports_force_mode_bypass
= true,
549 static const struct qcom_rpm_reg pm8901_ftsmps
= {
550 .desc
.linear_ranges
= ftsmps_ranges
,
551 .desc
.n_linear_ranges
= ARRAY_SIZE(ftsmps_ranges
),
552 .desc
.n_voltages
= 101,
554 .parts
= &rpm8660_smps_parts
,
555 .supports_force_mode_auto
= true,
556 .supports_force_mode_bypass
= false,
559 static const struct qcom_rpm_reg pm8901_switch
= {
560 .desc
.ops
= &switch_ops
,
561 .parts
= &rpm8660_switch_parts
,
567 static const struct qcom_rpm_reg pm8921_pldo
= {
568 .desc
.linear_ranges
= pldo_ranges
,
569 .desc
.n_linear_ranges
= ARRAY_SIZE(pldo_ranges
),
570 .desc
.n_voltages
= 161,
572 .parts
= &rpm8960_ldo_parts
,
573 .supports_force_mode_auto
= false,
574 .supports_force_mode_bypass
= true,
577 static const struct qcom_rpm_reg pm8921_nldo
= {
578 .desc
.linear_ranges
= nldo_ranges
,
579 .desc
.n_linear_ranges
= ARRAY_SIZE(nldo_ranges
),
580 .desc
.n_voltages
= 64,
582 .parts
= &rpm8960_ldo_parts
,
583 .supports_force_mode_auto
= false,
584 .supports_force_mode_bypass
= true,
587 static const struct qcom_rpm_reg pm8921_nldo1200
= {
588 .desc
.linear_ranges
= nldo1200_ranges
,
589 .desc
.n_linear_ranges
= ARRAY_SIZE(nldo1200_ranges
),
590 .desc
.n_voltages
= 124,
592 .parts
= &rpm8960_ldo_parts
,
593 .supports_force_mode_auto
= false,
594 .supports_force_mode_bypass
= true,
597 static const struct qcom_rpm_reg pm8921_smps
= {
598 .desc
.linear_ranges
= smps_ranges
,
599 .desc
.n_linear_ranges
= ARRAY_SIZE(smps_ranges
),
600 .desc
.n_voltages
= 154,
602 .parts
= &rpm8960_smps_parts
,
603 .supports_force_mode_auto
= true,
604 .supports_force_mode_bypass
= false,
607 static const struct qcom_rpm_reg pm8921_ncp
= {
608 .desc
.linear_ranges
= ncp_ranges
,
609 .desc
.n_linear_ranges
= ARRAY_SIZE(ncp_ranges
),
610 .desc
.n_voltages
= 32,
612 .parts
= &rpm8960_ncp_parts
,
615 static const struct qcom_rpm_reg pm8921_switch
= {
616 .desc
.ops
= &switch_ops
,
617 .parts
= &rpm8960_switch_parts
,
620 static const struct qcom_rpm_reg smb208_smps
= {
621 .desc
.linear_ranges
= smb208_ranges
,
622 .desc
.n_linear_ranges
= ARRAY_SIZE(smb208_ranges
),
623 .desc
.n_voltages
= 235,
625 .parts
= &rpm8960_smps_parts
,
626 .supports_force_mode_auto
= false,
627 .supports_force_mode_bypass
= false,
630 static int rpm_reg_set(struct qcom_rpm_reg
*vreg
,
631 const struct request_member
*req
,
634 if (req
->mask
== 0 || (value
<< req
->shift
) & ~req
->mask
)
637 vreg
->val
[req
->word
] &= ~req
->mask
;
638 vreg
->val
[req
->word
] |= value
<< req
->shift
;
643 static int rpm_reg_of_parse_freq(struct device
*dev
,
644 struct device_node
*node
,
645 struct qcom_rpm_reg
*vreg
)
647 static const int freq_table
[] = {
648 19200000, 9600000, 6400000, 4800000, 3840000, 3200000, 2740000,
649 2400000, 2130000, 1920000, 1750000, 1600000, 1480000, 1370000,
658 key
= "qcom,switch-mode-frequency";
659 ret
= of_property_read_u32(node
, key
, &freq
);
661 dev_err(dev
, "regulator requires %s property\n", key
);
665 for (i
= 0; i
< ARRAY_SIZE(freq_table
); i
++) {
666 if (freq
== freq_table
[i
]) {
667 rpm_reg_set(vreg
, &vreg
->parts
->freq
, i
+ 1);
672 dev_err(dev
, "invalid frequency %d\n", freq
);
676 static int rpm_reg_of_parse(struct device_node
*node
,
677 const struct regulator_desc
*desc
,
678 struct regulator_config
*config
)
680 struct qcom_rpm_reg
*vreg
= config
->driver_data
;
681 struct device
*dev
= config
->dev
;
688 key
= "bias-pull-down";
689 if (of_property_read_bool(node
, key
)) {
690 ret
= rpm_reg_set(vreg
, &vreg
->parts
->pd
, 1);
692 dev_err(dev
, "%s is invalid", key
);
697 if (vreg
->parts
->freq
.mask
) {
698 ret
= rpm_reg_of_parse_freq(dev
, node
, vreg
);
703 if (vreg
->parts
->pm
.mask
) {
704 key
= "qcom,power-mode-hysteretic";
705 pwm
= !of_property_read_bool(node
, key
);
707 ret
= rpm_reg_set(vreg
, &vreg
->parts
->pm
, pwm
);
709 dev_err(dev
, "failed to set power mode\n");
714 if (vreg
->parts
->fm
.mask
) {
717 key
= "qcom,force-mode";
718 ret
= of_property_read_u32(node
, key
, &val
);
719 if (ret
== -EINVAL
) {
720 val
= QCOM_RPM_FORCE_MODE_NONE
;
721 } else if (ret
< 0) {
722 dev_err(dev
, "failed to read %s\n", key
);
727 * If force-mode is encoded as 2 bits then the
728 * possible register values are:
731 * NONE, LPM, AUTO, HPM, BYPASS
734 case QCOM_RPM_FORCE_MODE_NONE
:
737 case QCOM_RPM_FORCE_MODE_LPM
:
740 case QCOM_RPM_FORCE_MODE_HPM
:
741 if (FORCE_MODE_IS_2_BITS(vreg
))
746 case QCOM_RPM_FORCE_MODE_AUTO
:
747 if (vreg
->supports_force_mode_auto
)
750 case QCOM_RPM_FORCE_MODE_BYPASS
:
751 if (vreg
->supports_force_mode_bypass
)
756 if (force_mode
== -1) {
757 dev_err(dev
, "invalid force mode\n");
761 ret
= rpm_reg_set(vreg
, &vreg
->parts
->fm
, force_mode
);
763 dev_err(dev
, "failed to set force mode\n");
771 struct rpm_regulator_data
{
774 const struct qcom_rpm_reg
*template;
778 static const struct rpm_regulator_data rpm_pm8018_regulators
[] = {
779 { "s1", QCOM_RPM_PM8018_SMPS1
, &pm8018_smps
, "vdd_s1" },
780 { "s2", QCOM_RPM_PM8018_SMPS2
, &pm8018_smps
, "vdd_s2" },
781 { "s3", QCOM_RPM_PM8018_SMPS3
, &pm8018_smps
, "vdd_s3" },
782 { "s4", QCOM_RPM_PM8018_SMPS4
, &pm8018_smps
, "vdd_s4" },
783 { "s5", QCOM_RPM_PM8018_SMPS5
, &pm8018_smps
, "vdd_s5" },
785 { "l2", QCOM_RPM_PM8018_LDO2
, &pm8018_pldo
, "vdd_l2" },
786 { "l3", QCOM_RPM_PM8018_LDO3
, &pm8018_pldo
, "vdd_l3" },
787 { "l4", QCOM_RPM_PM8018_LDO4
, &pm8018_pldo
, "vdd_l4" },
788 { "l5", QCOM_RPM_PM8018_LDO5
, &pm8018_pldo
, "vdd_l5" },
789 { "l6", QCOM_RPM_PM8018_LDO6
, &pm8018_pldo
, "vdd_l7" },
790 { "l7", QCOM_RPM_PM8018_LDO7
, &pm8018_pldo
, "vdd_l7" },
791 { "l8", QCOM_RPM_PM8018_LDO8
, &pm8018_nldo
, "vdd_l8" },
792 { "l9", QCOM_RPM_PM8018_LDO9
, &pm8921_nldo1200
,
793 "vdd_l9_l10_l11_l12" },
794 { "l10", QCOM_RPM_PM8018_LDO10
, &pm8018_nldo
, "vdd_l9_l10_l11_l12" },
795 { "l11", QCOM_RPM_PM8018_LDO11
, &pm8018_nldo
, "vdd_l9_l10_l11_l12" },
796 { "l12", QCOM_RPM_PM8018_LDO12
, &pm8018_nldo
, "vdd_l9_l10_l11_l12" },
797 { "l14", QCOM_RPM_PM8018_LDO14
, &pm8018_pldo
, "vdd_l14" },
799 { "lvs1", QCOM_RPM_PM8018_LVS1
, &pm8018_switch
, "lvs1_in" },
804 static const struct rpm_regulator_data rpm_pm8058_regulators
[] = {
805 { "l0", QCOM_RPM_PM8058_LDO0
, &pm8058_nldo
, "vdd_l0_l1_lvs" },
806 { "l1", QCOM_RPM_PM8058_LDO1
, &pm8058_nldo
, "vdd_l0_l1_lvs" },
807 { "l2", QCOM_RPM_PM8058_LDO2
, &pm8058_pldo
, "vdd_l2_l11_l12" },
808 { "l3", QCOM_RPM_PM8058_LDO3
, &pm8058_pldo
, "vdd_l3_l4_l5" },
809 { "l4", QCOM_RPM_PM8058_LDO4
, &pm8058_pldo
, "vdd_l3_l4_l5" },
810 { "l5", QCOM_RPM_PM8058_LDO5
, &pm8058_pldo
, "vdd_l3_l4_l5" },
811 { "l6", QCOM_RPM_PM8058_LDO6
, &pm8058_pldo
, "vdd_l6_l7" },
812 { "l7", QCOM_RPM_PM8058_LDO7
, &pm8058_pldo
, "vdd_l6_l7" },
813 { "l8", QCOM_RPM_PM8058_LDO8
, &pm8058_pldo
, "vdd_l8" },
814 { "l9", QCOM_RPM_PM8058_LDO9
, &pm8058_pldo
, "vdd_l9" },
815 { "l10", QCOM_RPM_PM8058_LDO10
, &pm8058_pldo
, "vdd_l10" },
816 { "l11", QCOM_RPM_PM8058_LDO11
, &pm8058_pldo
, "vdd_l2_l11_l12" },
817 { "l12", QCOM_RPM_PM8058_LDO12
, &pm8058_pldo
, "vdd_l2_l11_l12" },
818 { "l13", QCOM_RPM_PM8058_LDO13
, &pm8058_pldo
, "vdd_l13_l16" },
819 { "l14", QCOM_RPM_PM8058_LDO14
, &pm8058_pldo
, "vdd_l14_l15" },
820 { "l15", QCOM_RPM_PM8058_LDO15
, &pm8058_pldo
, "vdd_l14_l15" },
821 { "l16", QCOM_RPM_PM8058_LDO16
, &pm8058_pldo
, "vdd_l13_l16" },
822 { "l17", QCOM_RPM_PM8058_LDO17
, &pm8058_pldo
, "vdd_l17_l18" },
823 { "l18", QCOM_RPM_PM8058_LDO18
, &pm8058_pldo
, "vdd_l17_l18" },
824 { "l19", QCOM_RPM_PM8058_LDO19
, &pm8058_pldo
, "vdd_l19_l20" },
825 { "l20", QCOM_RPM_PM8058_LDO20
, &pm8058_pldo
, "vdd_l19_l20" },
826 { "l21", QCOM_RPM_PM8058_LDO21
, &pm8058_nldo
, "vdd_l21" },
827 { "l22", QCOM_RPM_PM8058_LDO22
, &pm8058_nldo
, "vdd_l22" },
828 { "l23", QCOM_RPM_PM8058_LDO23
, &pm8058_nldo
, "vdd_l23_l24_l25" },
829 { "l24", QCOM_RPM_PM8058_LDO24
, &pm8058_nldo
, "vdd_l23_l24_l25" },
830 { "l25", QCOM_RPM_PM8058_LDO25
, &pm8058_nldo
, "vdd_l23_l24_l25" },
832 { "s0", QCOM_RPM_PM8058_SMPS0
, &pm8058_smps
, "vdd_s0" },
833 { "s1", QCOM_RPM_PM8058_SMPS1
, &pm8058_smps
, "vdd_s1" },
834 { "s2", QCOM_RPM_PM8058_SMPS2
, &pm8058_smps
, "vdd_s2" },
835 { "s3", QCOM_RPM_PM8058_SMPS3
, &pm8058_smps
, "vdd_s3" },
836 { "s4", QCOM_RPM_PM8058_SMPS4
, &pm8058_smps
, "vdd_s4" },
838 { "lvs0", QCOM_RPM_PM8058_LVS0
, &pm8058_switch
, "vdd_l0_l1_lvs" },
839 { "lvs1", QCOM_RPM_PM8058_LVS1
, &pm8058_switch
, "vdd_l0_l1_lvs" },
841 { "ncp", QCOM_RPM_PM8058_NCP
, &pm8058_ncp
, "vdd_ncp" },
845 static const struct rpm_regulator_data rpm_pm8901_regulators
[] = {
846 { "l0", QCOM_RPM_PM8901_LDO0
, &pm8901_nldo
, "vdd_l0" },
847 { "l1", QCOM_RPM_PM8901_LDO1
, &pm8901_pldo
, "vdd_l1" },
848 { "l2", QCOM_RPM_PM8901_LDO2
, &pm8901_pldo
, "vdd_l2" },
849 { "l3", QCOM_RPM_PM8901_LDO3
, &pm8901_pldo
, "vdd_l3" },
850 { "l4", QCOM_RPM_PM8901_LDO4
, &pm8901_pldo
, "vdd_l4" },
851 { "l5", QCOM_RPM_PM8901_LDO5
, &pm8901_pldo
, "vdd_l5" },
852 { "l6", QCOM_RPM_PM8901_LDO6
, &pm8901_pldo
, "vdd_l6" },
854 { "s0", QCOM_RPM_PM8901_SMPS0
, &pm8901_ftsmps
, "vdd_s0" },
855 { "s1", QCOM_RPM_PM8901_SMPS1
, &pm8901_ftsmps
, "vdd_s1" },
856 { "s2", QCOM_RPM_PM8901_SMPS2
, &pm8901_ftsmps
, "vdd_s2" },
857 { "s3", QCOM_RPM_PM8901_SMPS3
, &pm8901_ftsmps
, "vdd_s3" },
858 { "s4", QCOM_RPM_PM8901_SMPS4
, &pm8901_ftsmps
, "vdd_s4" },
860 { "lvs0", QCOM_RPM_PM8901_LVS0
, &pm8901_switch
, "lvs0_in" },
861 { "lvs1", QCOM_RPM_PM8901_LVS1
, &pm8901_switch
, "lvs1_in" },
862 { "lvs2", QCOM_RPM_PM8901_LVS2
, &pm8901_switch
, "lvs2_in" },
863 { "lvs3", QCOM_RPM_PM8901_LVS3
, &pm8901_switch
, "lvs3_in" },
865 { "mvs", QCOM_RPM_PM8901_MVS
, &pm8901_switch
, "mvs_in" },
869 static const struct rpm_regulator_data rpm_pm8921_regulators
[] = {
870 { "s1", QCOM_RPM_PM8921_SMPS1
, &pm8921_smps
, "vdd_s1" },
871 { "s2", QCOM_RPM_PM8921_SMPS2
, &pm8921_smps
, "vdd_s2" },
872 { "s3", QCOM_RPM_PM8921_SMPS3
, &pm8921_smps
},
873 { "s4", QCOM_RPM_PM8921_SMPS4
, &pm8921_smps
, "vdd_s4" },
874 { "s7", QCOM_RPM_PM8921_SMPS7
, &pm8921_smps
, "vdd_s7" },
875 { "s8", QCOM_RPM_PM8921_SMPS8
, &pm8921_smps
, "vdd_s8" },
877 { "l1", QCOM_RPM_PM8921_LDO1
, &pm8921_nldo
, "vdd_l1_l2_l12_l18" },
878 { "l2", QCOM_RPM_PM8921_LDO2
, &pm8921_nldo
, "vdd_l1_l2_l12_l18" },
879 { "l3", QCOM_RPM_PM8921_LDO3
, &pm8921_pldo
, "vdd_l3_l15_l17" },
880 { "l4", QCOM_RPM_PM8921_LDO4
, &pm8921_pldo
, "vdd_l4_l14" },
881 { "l5", QCOM_RPM_PM8921_LDO5
, &pm8921_pldo
, "vdd_l5_l8_l16" },
882 { "l6", QCOM_RPM_PM8921_LDO6
, &pm8921_pldo
, "vdd_l6_l7" },
883 { "l7", QCOM_RPM_PM8921_LDO7
, &pm8921_pldo
, "vdd_l6_l7" },
884 { "l8", QCOM_RPM_PM8921_LDO8
, &pm8921_pldo
, "vdd_l5_l8_l16" },
885 { "l9", QCOM_RPM_PM8921_LDO9
, &pm8921_pldo
, "vdd_l9_l11" },
886 { "l10", QCOM_RPM_PM8921_LDO10
, &pm8921_pldo
, "vdd_l10_l22" },
887 { "l11", QCOM_RPM_PM8921_LDO11
, &pm8921_pldo
, "vdd_l9_l11" },
888 { "l12", QCOM_RPM_PM8921_LDO12
, &pm8921_nldo
, "vdd_l1_l2_l12_l18" },
889 { "l14", QCOM_RPM_PM8921_LDO14
, &pm8921_pldo
, "vdd_l4_l14" },
890 { "l15", QCOM_RPM_PM8921_LDO15
, &pm8921_pldo
, "vdd_l3_l15_l17" },
891 { "l16", QCOM_RPM_PM8921_LDO16
, &pm8921_pldo
, "vdd_l5_l8_l16" },
892 { "l17", QCOM_RPM_PM8921_LDO17
, &pm8921_pldo
, "vdd_l3_l15_l17" },
893 { "l18", QCOM_RPM_PM8921_LDO18
, &pm8921_nldo
, "vdd_l1_l2_l12_l18" },
894 { "l21", QCOM_RPM_PM8921_LDO21
, &pm8921_pldo
, "vdd_l21_l23_l29" },
895 { "l22", QCOM_RPM_PM8921_LDO22
, &pm8921_pldo
, "vdd_l10_l22" },
896 { "l23", QCOM_RPM_PM8921_LDO23
, &pm8921_pldo
, "vdd_l21_l23_l29" },
897 { "l24", QCOM_RPM_PM8921_LDO24
, &pm8921_nldo1200
, "vdd_l24" },
898 { "l25", QCOM_RPM_PM8921_LDO25
, &pm8921_nldo1200
, "vdd_l25" },
899 { "l26", QCOM_RPM_PM8921_LDO26
, &pm8921_nldo1200
, "vdd_l26" },
900 { "l27", QCOM_RPM_PM8921_LDO27
, &pm8921_nldo1200
, "vdd_l27" },
901 { "l28", QCOM_RPM_PM8921_LDO28
, &pm8921_nldo1200
, "vdd_l28" },
902 { "l29", QCOM_RPM_PM8921_LDO29
, &pm8921_pldo
, "vdd_l21_l23_l29" },
904 { "lvs1", QCOM_RPM_PM8921_LVS1
, &pm8921_switch
, "vin_lvs1_3_6" },
905 { "lvs2", QCOM_RPM_PM8921_LVS2
, &pm8921_switch
, "vin_lvs2" },
906 { "lvs3", QCOM_RPM_PM8921_LVS3
, &pm8921_switch
, "vin_lvs1_3_6" },
907 { "lvs4", QCOM_RPM_PM8921_LVS4
, &pm8921_switch
, "vin_lvs4_5_7" },
908 { "lvs5", QCOM_RPM_PM8921_LVS5
, &pm8921_switch
, "vin_lvs4_5_7" },
909 { "lvs6", QCOM_RPM_PM8921_LVS6
, &pm8921_switch
, "vin_lvs1_3_6" },
910 { "lvs7", QCOM_RPM_PM8921_LVS7
, &pm8921_switch
, "vin_lvs4_5_7" },
912 { "usb-switch", QCOM_RPM_USB_OTG_SWITCH
, &pm8921_switch
, "vin_5vs" },
913 { "hdmi-switch", QCOM_RPM_HDMI_SWITCH
, &pm8921_switch
, "vin_5vs" },
914 { "ncp", QCOM_RPM_PM8921_NCP
, &pm8921_ncp
, "vdd_ncp" },
918 static const struct rpm_regulator_data rpm_smb208_regulators
[] = {
919 { "s1a", QCOM_RPM_SMB208_S1a
, &smb208_smps
, "vin_s1a" },
920 { "s1b", QCOM_RPM_SMB208_S1b
, &smb208_smps
, "vin_s1b" },
921 { "s2a", QCOM_RPM_SMB208_S2a
, &smb208_smps
, "vin_s2a" },
922 { "s2b", QCOM_RPM_SMB208_S2b
, &smb208_smps
, "vin_s2b" },
926 static const struct of_device_id rpm_of_match
[] = {
927 { .compatible
= "qcom,rpm-pm8018-regulators",
928 .data
= &rpm_pm8018_regulators
},
929 { .compatible
= "qcom,rpm-pm8058-regulators", .data
= &rpm_pm8058_regulators
},
930 { .compatible
= "qcom,rpm-pm8901-regulators", .data
= &rpm_pm8901_regulators
},
931 { .compatible
= "qcom,rpm-pm8921-regulators", .data
= &rpm_pm8921_regulators
},
932 { .compatible
= "qcom,rpm-smb208-regulators", .data
= &rpm_smb208_regulators
},
935 MODULE_DEVICE_TABLE(of
, rpm_of_match
);
937 static int rpm_reg_probe(struct platform_device
*pdev
)
939 const struct rpm_regulator_data
*reg
;
940 const struct of_device_id
*match
;
941 struct regulator_config config
= { };
942 struct regulator_dev
*rdev
;
943 struct qcom_rpm_reg
*vreg
;
944 struct qcom_rpm
*rpm
;
946 rpm
= dev_get_drvdata(pdev
->dev
.parent
);
948 dev_err(&pdev
->dev
, "unable to retrieve handle to rpm\n");
952 match
= of_match_device(rpm_of_match
, &pdev
->dev
);
954 dev_err(&pdev
->dev
, "failed to match device\n");
958 for (reg
= match
->data
; reg
->name
; reg
++) {
959 vreg
= devm_kmalloc(&pdev
->dev
, sizeof(*vreg
), GFP_KERNEL
);
963 memcpy(vreg
, reg
->template, sizeof(*vreg
));
964 mutex_init(&vreg
->lock
);
966 vreg
->dev
= &pdev
->dev
;
967 vreg
->resource
= reg
->resource
;
971 vreg
->desc
.owner
= THIS_MODULE
;
972 vreg
->desc
.type
= REGULATOR_VOLTAGE
;
973 vreg
->desc
.name
= reg
->name
;
974 vreg
->desc
.supply_name
= reg
->supply
;
975 vreg
->desc
.of_match
= reg
->name
;
976 vreg
->desc
.of_parse_cb
= rpm_reg_of_parse
;
978 config
.dev
= &pdev
->dev
;
979 config
.driver_data
= vreg
;
980 rdev
= devm_regulator_register(&pdev
->dev
, &vreg
->desc
, &config
);
982 dev_err(&pdev
->dev
, "failed to register %s\n", reg
->name
);
983 return PTR_ERR(rdev
);
990 static struct platform_driver rpm_reg_driver
= {
991 .probe
= rpm_reg_probe
,
993 .name
= "qcom_rpm_reg",
994 .of_match_table
= of_match_ptr(rpm_of_match
),
998 static int __init
rpm_reg_init(void)
1000 return platform_driver_register(&rpm_reg_driver
);
1002 subsys_initcall(rpm_reg_init
);
1004 static void __exit
rpm_reg_exit(void)
1006 platform_driver_unregister(&rpm_reg_driver
);
1008 module_exit(rpm_reg_exit
)
1010 MODULE_DESCRIPTION("Qualcomm RPM regulator driver");
1011 MODULE_LICENSE("GPL v2");