2 * Copyright (c) 2014, Sony Mobile Communications AB.
3 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 and
7 * only version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <linux/module.h>
16 #include <linux/platform_device.h>
18 #include <linux/of_device.h>
19 #include <linux/regulator/driver.h>
20 #include <linux/regulator/machine.h>
21 #include <linux/regulator/of_regulator.h>
22 #include <linux/mfd/qcom_rpm.h>
24 #include <dt-bindings/mfd/qcom-rpm.h>
26 #define MAX_REQUEST_LEN 2
28 struct request_member
{
34 struct rpm_reg_parts
{
35 struct request_member mV
; /* used if voltage is in mV */
36 struct request_member uV
; /* used if voltage is in uV */
37 struct request_member ip
; /* peak current in mA */
38 struct request_member pd
; /* pull down enable */
39 struct request_member ia
; /* average current in mA */
40 struct request_member fm
; /* force mode */
41 struct request_member pm
; /* power mode */
42 struct request_member pc
; /* pin control */
43 struct request_member pf
; /* pin function */
44 struct request_member enable_state
; /* NCP and switch */
45 struct request_member comp_mode
; /* NCP */
46 struct request_member freq
; /* frequency: NCP and SMPS */
47 struct request_member freq_clk_src
; /* clock source: SMPS */
48 struct request_member hpm
; /* switch: control OCP and SS */
52 #define FORCE_MODE_IS_2_BITS(reg) \
53 (((reg)->parts->fm.mask >> (reg)->parts->fm.shift) == 3)
60 struct regulator_desc desc
;
61 const struct rpm_reg_parts
*parts
;
64 u32 val
[MAX_REQUEST_LEN
];
69 bool supports_force_mode_auto
;
70 bool supports_force_mode_bypass
;
73 static const struct rpm_reg_parts rpm8660_ldo_parts
= {
75 .mV
= { 0, 0x00000FFF, 0 },
76 .ip
= { 0, 0x00FFF000, 12 },
77 .fm
= { 0, 0x03000000, 24 },
78 .pc
= { 0, 0x3C000000, 26 },
79 .pf
= { 0, 0xC0000000, 30 },
80 .pd
= { 1, 0x00000001, 0 },
81 .ia
= { 1, 0x00001FFE, 1 },
84 static const struct rpm_reg_parts rpm8660_smps_parts
= {
86 .mV
= { 0, 0x00000FFF, 0 },
87 .ip
= { 0, 0x00FFF000, 12 },
88 .fm
= { 0, 0x03000000, 24 },
89 .pc
= { 0, 0x3C000000, 26 },
90 .pf
= { 0, 0xC0000000, 30 },
91 .pd
= { 1, 0x00000001, 0 },
92 .ia
= { 1, 0x00001FFE, 1 },
93 .freq
= { 1, 0x001FE000, 13 },
94 .freq_clk_src
= { 1, 0x00600000, 21 },
97 static const struct rpm_reg_parts rpm8660_switch_parts
= {
99 .enable_state
= { 0, 0x00000001, 0 },
100 .pd
= { 0, 0x00000002, 1 },
101 .pc
= { 0, 0x0000003C, 2 },
102 .pf
= { 0, 0x000000C0, 6 },
103 .hpm
= { 0, 0x00000300, 8 },
106 static const struct rpm_reg_parts rpm8660_ncp_parts
= {
108 .mV
= { 0, 0x00000FFF, 0 },
109 .enable_state
= { 0, 0x00001000, 12 },
110 .comp_mode
= { 0, 0x00002000, 13 },
111 .freq
= { 0, 0x003FC000, 14 },
114 static const struct rpm_reg_parts rpm8960_ldo_parts
= {
116 .uV
= { 0, 0x007FFFFF, 0 },
117 .pd
= { 0, 0x00800000, 23 },
118 .pc
= { 0, 0x0F000000, 24 },
119 .pf
= { 0, 0xF0000000, 28 },
120 .ip
= { 1, 0x000003FF, 0 },
121 .ia
= { 1, 0x000FFC00, 10 },
122 .fm
= { 1, 0x00700000, 20 },
125 static const struct rpm_reg_parts rpm8960_smps_parts
= {
127 .uV
= { 0, 0x007FFFFF, 0 },
128 .pd
= { 0, 0x00800000, 23 },
129 .pc
= { 0, 0x0F000000, 24 },
130 .pf
= { 0, 0xF0000000, 28 },
131 .ip
= { 1, 0x000003FF, 0 },
132 .ia
= { 1, 0x000FFC00, 10 },
133 .fm
= { 1, 0x00700000, 20 },
134 .pm
= { 1, 0x00800000, 23 },
135 .freq
= { 1, 0x1F000000, 24 },
136 .freq_clk_src
= { 1, 0x60000000, 29 },
139 static const struct rpm_reg_parts rpm8960_switch_parts
= {
141 .enable_state
= { 0, 0x00000001, 0 },
142 .pd
= { 0, 0x00000002, 1 },
143 .pc
= { 0, 0x0000003C, 2 },
144 .pf
= { 0, 0x000003C0, 6 },
145 .hpm
= { 0, 0x00000C00, 10 },
148 static const struct rpm_reg_parts rpm8960_ncp_parts
= {
150 .uV
= { 0, 0x007FFFFF, 0 },
151 .enable_state
= { 0, 0x00800000, 23 },
152 .comp_mode
= { 0, 0x01000000, 24 },
153 .freq
= { 0, 0x3E000000, 25 },
157 * Physically available PMIC regulator voltage ranges
159 static const struct regulator_linear_range pldo_ranges
[] = {
160 REGULATOR_LINEAR_RANGE( 750000, 0, 59, 12500),
161 REGULATOR_LINEAR_RANGE(1500000, 60, 123, 25000),
162 REGULATOR_LINEAR_RANGE(3100000, 124, 160, 50000),
165 static const struct regulator_linear_range nldo_ranges
[] = {
166 REGULATOR_LINEAR_RANGE( 750000, 0, 63, 12500),
169 static const struct regulator_linear_range nldo1200_ranges
[] = {
170 REGULATOR_LINEAR_RANGE( 375000, 0, 59, 6250),
171 REGULATOR_LINEAR_RANGE( 750000, 60, 123, 12500),
174 static const struct regulator_linear_range smps_ranges
[] = {
175 REGULATOR_LINEAR_RANGE( 375000, 0, 29, 12500),
176 REGULATOR_LINEAR_RANGE( 750000, 30, 89, 12500),
177 REGULATOR_LINEAR_RANGE(1500000, 90, 153, 25000),
180 static const struct regulator_linear_range ftsmps_ranges
[] = {
181 REGULATOR_LINEAR_RANGE( 350000, 0, 6, 50000),
182 REGULATOR_LINEAR_RANGE( 700000, 7, 63, 12500),
183 REGULATOR_LINEAR_RANGE(1500000, 64, 100, 50000),
186 static const struct regulator_linear_range smb208_ranges
[] = {
187 REGULATOR_LINEAR_RANGE( 375000, 0, 29, 12500),
188 REGULATOR_LINEAR_RANGE( 750000, 30, 89, 12500),
189 REGULATOR_LINEAR_RANGE(1500000, 90, 153, 25000),
190 REGULATOR_LINEAR_RANGE(3100000, 154, 234, 25000),
193 static const struct regulator_linear_range ncp_ranges
[] = {
194 REGULATOR_LINEAR_RANGE(1500000, 0, 31, 50000),
197 static int rpm_reg_write(struct qcom_rpm_reg
*vreg
,
198 const struct request_member
*req
,
201 if (WARN_ON((value
<< req
->shift
) & ~req
->mask
))
204 vreg
->val
[req
->word
] &= ~req
->mask
;
205 vreg
->val
[req
->word
] |= value
<< req
->shift
;
207 return qcom_rpm_write(vreg
->rpm
,
208 QCOM_RPM_ACTIVE_STATE
,
211 vreg
->parts
->request_len
);
214 static int rpm_reg_set_mV_sel(struct regulator_dev
*rdev
,
217 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
218 const struct rpm_reg_parts
*parts
= vreg
->parts
;
219 const struct request_member
*req
= &parts
->mV
;
226 uV
= regulator_list_voltage_linear_range(rdev
, selector
);
230 mutex_lock(&vreg
->lock
);
231 if (vreg
->is_enabled
)
232 ret
= rpm_reg_write(vreg
, req
, uV
/ 1000);
236 mutex_unlock(&vreg
->lock
);
241 static int rpm_reg_set_uV_sel(struct regulator_dev
*rdev
,
244 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
245 const struct rpm_reg_parts
*parts
= vreg
->parts
;
246 const struct request_member
*req
= &parts
->uV
;
253 uV
= regulator_list_voltage_linear_range(rdev
, selector
);
257 mutex_lock(&vreg
->lock
);
258 if (vreg
->is_enabled
)
259 ret
= rpm_reg_write(vreg
, req
, uV
);
263 mutex_unlock(&vreg
->lock
);
268 static int rpm_reg_get_voltage(struct regulator_dev
*rdev
)
270 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
275 static int rpm_reg_mV_enable(struct regulator_dev
*rdev
)
277 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
278 const struct rpm_reg_parts
*parts
= vreg
->parts
;
279 const struct request_member
*req
= &parts
->mV
;
285 mutex_lock(&vreg
->lock
);
286 ret
= rpm_reg_write(vreg
, req
, vreg
->uV
/ 1000);
288 vreg
->is_enabled
= 1;
289 mutex_unlock(&vreg
->lock
);
294 static int rpm_reg_uV_enable(struct regulator_dev
*rdev
)
296 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
297 const struct rpm_reg_parts
*parts
= vreg
->parts
;
298 const struct request_member
*req
= &parts
->uV
;
304 mutex_lock(&vreg
->lock
);
305 ret
= rpm_reg_write(vreg
, req
, vreg
->uV
);
307 vreg
->is_enabled
= 1;
308 mutex_unlock(&vreg
->lock
);
313 static int rpm_reg_switch_enable(struct regulator_dev
*rdev
)
315 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
316 const struct rpm_reg_parts
*parts
= vreg
->parts
;
317 const struct request_member
*req
= &parts
->enable_state
;
323 mutex_lock(&vreg
->lock
);
324 ret
= rpm_reg_write(vreg
, req
, 1);
326 vreg
->is_enabled
= 1;
327 mutex_unlock(&vreg
->lock
);
332 static int rpm_reg_mV_disable(struct regulator_dev
*rdev
)
334 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
335 const struct rpm_reg_parts
*parts
= vreg
->parts
;
336 const struct request_member
*req
= &parts
->mV
;
342 mutex_lock(&vreg
->lock
);
343 ret
= rpm_reg_write(vreg
, req
, 0);
345 vreg
->is_enabled
= 0;
346 mutex_unlock(&vreg
->lock
);
351 static int rpm_reg_uV_disable(struct regulator_dev
*rdev
)
353 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
354 const struct rpm_reg_parts
*parts
= vreg
->parts
;
355 const struct request_member
*req
= &parts
->uV
;
361 mutex_lock(&vreg
->lock
);
362 ret
= rpm_reg_write(vreg
, req
, 0);
364 vreg
->is_enabled
= 0;
365 mutex_unlock(&vreg
->lock
);
370 static int rpm_reg_switch_disable(struct regulator_dev
*rdev
)
372 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
373 const struct rpm_reg_parts
*parts
= vreg
->parts
;
374 const struct request_member
*req
= &parts
->enable_state
;
380 mutex_lock(&vreg
->lock
);
381 ret
= rpm_reg_write(vreg
, req
, 0);
383 vreg
->is_enabled
= 0;
384 mutex_unlock(&vreg
->lock
);
389 static int rpm_reg_is_enabled(struct regulator_dev
*rdev
)
391 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
393 return vreg
->is_enabled
;
396 static int rpm_reg_set_load(struct regulator_dev
*rdev
, int load_uA
)
398 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
399 const struct rpm_reg_parts
*parts
= vreg
->parts
;
400 const struct request_member
*req
= &parts
->ia
;
401 int load_mA
= load_uA
/ 1000;
402 int max_mA
= req
->mask
>> req
->shift
;
408 if (load_mA
> max_mA
)
411 mutex_lock(&vreg
->lock
);
412 ret
= rpm_reg_write(vreg
, req
, load_mA
);
413 mutex_unlock(&vreg
->lock
);
418 static struct regulator_ops uV_ops
= {
419 .list_voltage
= regulator_list_voltage_linear_range
,
421 .set_voltage_sel
= rpm_reg_set_uV_sel
,
422 .get_voltage
= rpm_reg_get_voltage
,
424 .enable
= rpm_reg_uV_enable
,
425 .disable
= rpm_reg_uV_disable
,
426 .is_enabled
= rpm_reg_is_enabled
,
428 .set_load
= rpm_reg_set_load
,
431 static struct regulator_ops mV_ops
= {
432 .list_voltage
= regulator_list_voltage_linear_range
,
434 .set_voltage_sel
= rpm_reg_set_mV_sel
,
435 .get_voltage
= rpm_reg_get_voltage
,
437 .enable
= rpm_reg_mV_enable
,
438 .disable
= rpm_reg_mV_disable
,
439 .is_enabled
= rpm_reg_is_enabled
,
441 .set_load
= rpm_reg_set_load
,
444 static struct regulator_ops switch_ops
= {
445 .enable
= rpm_reg_switch_enable
,
446 .disable
= rpm_reg_switch_disable
,
447 .is_enabled
= rpm_reg_is_enabled
,
453 static const struct qcom_rpm_reg pm8058_pldo
= {
454 .desc
.linear_ranges
= pldo_ranges
,
455 .desc
.n_linear_ranges
= ARRAY_SIZE(pldo_ranges
),
456 .desc
.n_voltages
= 161,
458 .parts
= &rpm8660_ldo_parts
,
459 .supports_force_mode_auto
= false,
460 .supports_force_mode_bypass
= false,
463 static const struct qcom_rpm_reg pm8058_nldo
= {
464 .desc
.linear_ranges
= nldo_ranges
,
465 .desc
.n_linear_ranges
= ARRAY_SIZE(nldo_ranges
),
466 .desc
.n_voltages
= 64,
468 .parts
= &rpm8660_ldo_parts
,
469 .supports_force_mode_auto
= false,
470 .supports_force_mode_bypass
= false,
473 static const struct qcom_rpm_reg pm8058_smps
= {
474 .desc
.linear_ranges
= smps_ranges
,
475 .desc
.n_linear_ranges
= ARRAY_SIZE(smps_ranges
),
476 .desc
.n_voltages
= 154,
478 .parts
= &rpm8660_smps_parts
,
479 .supports_force_mode_auto
= false,
480 .supports_force_mode_bypass
= false,
483 static const struct qcom_rpm_reg pm8058_ncp
= {
484 .desc
.linear_ranges
= ncp_ranges
,
485 .desc
.n_linear_ranges
= ARRAY_SIZE(ncp_ranges
),
486 .desc
.n_voltages
= 32,
488 .parts
= &rpm8660_ncp_parts
,
491 static const struct qcom_rpm_reg pm8058_switch
= {
492 .desc
.ops
= &switch_ops
,
493 .parts
= &rpm8660_switch_parts
,
499 static const struct qcom_rpm_reg pm8901_pldo
= {
500 .desc
.linear_ranges
= pldo_ranges
,
501 .desc
.n_linear_ranges
= ARRAY_SIZE(pldo_ranges
),
502 .desc
.n_voltages
= 161,
504 .parts
= &rpm8660_ldo_parts
,
505 .supports_force_mode_auto
= false,
506 .supports_force_mode_bypass
= true,
509 static const struct qcom_rpm_reg pm8901_nldo
= {
510 .desc
.linear_ranges
= nldo_ranges
,
511 .desc
.n_linear_ranges
= ARRAY_SIZE(nldo_ranges
),
512 .desc
.n_voltages
= 64,
514 .parts
= &rpm8660_ldo_parts
,
515 .supports_force_mode_auto
= false,
516 .supports_force_mode_bypass
= true,
519 static const struct qcom_rpm_reg pm8901_ftsmps
= {
520 .desc
.linear_ranges
= ftsmps_ranges
,
521 .desc
.n_linear_ranges
= ARRAY_SIZE(ftsmps_ranges
),
522 .desc
.n_voltages
= 101,
524 .parts
= &rpm8660_smps_parts
,
525 .supports_force_mode_auto
= true,
526 .supports_force_mode_bypass
= false,
529 static const struct qcom_rpm_reg pm8901_switch
= {
530 .desc
.ops
= &switch_ops
,
531 .parts
= &rpm8660_switch_parts
,
537 static const struct qcom_rpm_reg pm8921_pldo
= {
538 .desc
.linear_ranges
= pldo_ranges
,
539 .desc
.n_linear_ranges
= ARRAY_SIZE(pldo_ranges
),
540 .desc
.n_voltages
= 161,
542 .parts
= &rpm8960_ldo_parts
,
543 .supports_force_mode_auto
= false,
544 .supports_force_mode_bypass
= true,
547 static const struct qcom_rpm_reg pm8921_nldo
= {
548 .desc
.linear_ranges
= nldo_ranges
,
549 .desc
.n_linear_ranges
= ARRAY_SIZE(nldo_ranges
),
550 .desc
.n_voltages
= 64,
552 .parts
= &rpm8960_ldo_parts
,
553 .supports_force_mode_auto
= false,
554 .supports_force_mode_bypass
= true,
557 static const struct qcom_rpm_reg pm8921_nldo1200
= {
558 .desc
.linear_ranges
= nldo1200_ranges
,
559 .desc
.n_linear_ranges
= ARRAY_SIZE(nldo1200_ranges
),
560 .desc
.n_voltages
= 124,
562 .parts
= &rpm8960_ldo_parts
,
563 .supports_force_mode_auto
= false,
564 .supports_force_mode_bypass
= true,
567 static const struct qcom_rpm_reg pm8921_smps
= {
568 .desc
.linear_ranges
= smps_ranges
,
569 .desc
.n_linear_ranges
= ARRAY_SIZE(smps_ranges
),
570 .desc
.n_voltages
= 154,
572 .parts
= &rpm8960_smps_parts
,
573 .supports_force_mode_auto
= true,
574 .supports_force_mode_bypass
= false,
577 static const struct qcom_rpm_reg pm8921_ftsmps
= {
578 .desc
.linear_ranges
= ftsmps_ranges
,
579 .desc
.n_linear_ranges
= ARRAY_SIZE(ftsmps_ranges
),
580 .desc
.n_voltages
= 101,
582 .parts
= &rpm8960_smps_parts
,
583 .supports_force_mode_auto
= true,
584 .supports_force_mode_bypass
= false,
587 static const struct qcom_rpm_reg pm8921_ncp
= {
588 .desc
.linear_ranges
= ncp_ranges
,
589 .desc
.n_linear_ranges
= ARRAY_SIZE(ncp_ranges
),
590 .desc
.n_voltages
= 32,
592 .parts
= &rpm8960_ncp_parts
,
595 static const struct qcom_rpm_reg pm8921_switch
= {
596 .desc
.ops
= &switch_ops
,
597 .parts
= &rpm8960_switch_parts
,
600 static const struct qcom_rpm_reg smb208_smps
= {
601 .desc
.linear_ranges
= smb208_ranges
,
602 .desc
.n_linear_ranges
= ARRAY_SIZE(smb208_ranges
),
603 .desc
.n_voltages
= 235,
605 .parts
= &rpm8960_smps_parts
,
606 .supports_force_mode_auto
= false,
607 .supports_force_mode_bypass
= false,
610 static int rpm_reg_set(struct qcom_rpm_reg
*vreg
,
611 const struct request_member
*req
,
614 if (req
->mask
== 0 || (value
<< req
->shift
) & ~req
->mask
)
617 vreg
->val
[req
->word
] &= ~req
->mask
;
618 vreg
->val
[req
->word
] |= value
<< req
->shift
;
623 static int rpm_reg_of_parse_freq(struct device
*dev
,
624 struct device_node
*node
,
625 struct qcom_rpm_reg
*vreg
)
627 static const int freq_table
[] = {
628 19200000, 9600000, 6400000, 4800000, 3840000, 3200000, 2740000,
629 2400000, 2130000, 1920000, 1750000, 1600000, 1480000, 1370000,
638 key
= "qcom,switch-mode-frequency";
639 ret
= of_property_read_u32(node
, key
, &freq
);
641 dev_err(dev
, "regulator requires %s property\n", key
);
645 for (i
= 0; i
< ARRAY_SIZE(freq_table
); i
++) {
646 if (freq
== freq_table
[i
]) {
647 rpm_reg_set(vreg
, &vreg
->parts
->freq
, i
+ 1);
652 dev_err(dev
, "invalid frequency %d\n", freq
);
656 static int rpm_reg_of_parse(struct device_node
*node
,
657 const struct regulator_desc
*desc
,
658 struct regulator_config
*config
)
660 struct qcom_rpm_reg
*vreg
= config
->driver_data
;
661 struct device
*dev
= config
->dev
;
668 key
= "bias-pull-down";
669 if (of_property_read_bool(node
, key
)) {
670 ret
= rpm_reg_set(vreg
, &vreg
->parts
->pd
, 1);
672 dev_err(dev
, "%s is invalid", key
);
677 if (vreg
->parts
->freq
.mask
) {
678 ret
= rpm_reg_of_parse_freq(dev
, node
, vreg
);
683 if (vreg
->parts
->pm
.mask
) {
684 key
= "qcom,power-mode-hysteretic";
685 pwm
= !of_property_read_bool(node
, key
);
687 ret
= rpm_reg_set(vreg
, &vreg
->parts
->pm
, pwm
);
689 dev_err(dev
, "failed to set power mode\n");
694 if (vreg
->parts
->fm
.mask
) {
697 key
= "qcom,force-mode";
698 ret
= of_property_read_u32(node
, key
, &val
);
699 if (ret
== -EINVAL
) {
700 val
= QCOM_RPM_FORCE_MODE_NONE
;
701 } else if (ret
< 0) {
702 dev_err(dev
, "failed to read %s\n", key
);
707 * If force-mode is encoded as 2 bits then the
708 * possible register values are:
711 * NONE, LPM, AUTO, HPM, BYPASS
714 case QCOM_RPM_FORCE_MODE_NONE
:
717 case QCOM_RPM_FORCE_MODE_LPM
:
720 case QCOM_RPM_FORCE_MODE_HPM
:
721 if (FORCE_MODE_IS_2_BITS(vreg
))
726 case QCOM_RPM_FORCE_MODE_AUTO
:
727 if (vreg
->supports_force_mode_auto
)
730 case QCOM_RPM_FORCE_MODE_BYPASS
:
731 if (vreg
->supports_force_mode_bypass
)
736 if (force_mode
== -1) {
737 dev_err(dev
, "invalid force mode\n");
741 ret
= rpm_reg_set(vreg
, &vreg
->parts
->fm
, force_mode
);
743 dev_err(dev
, "failed to set force mode\n");
751 struct rpm_regulator_data
{
754 const struct qcom_rpm_reg
*template;
758 static const struct rpm_regulator_data rpm_pm8058_regulators
[] = {
759 { "l0", QCOM_RPM_PM8058_LDO0
, &pm8058_nldo
, "vdd_l0_l1_lvs" },
760 { "l1", QCOM_RPM_PM8058_LDO1
, &pm8058_nldo
, "vdd_l0_l1_lvs" },
761 { "l2", QCOM_RPM_PM8058_LDO2
, &pm8058_pldo
, "vdd_l2_l11_l12" },
762 { "l3", QCOM_RPM_PM8058_LDO3
, &pm8058_pldo
, "vdd_l3_l4_l5" },
763 { "l4", QCOM_RPM_PM8058_LDO4
, &pm8058_pldo
, "vdd_l3_l4_l5" },
764 { "l5", QCOM_RPM_PM8058_LDO5
, &pm8058_pldo
, "vdd_l3_l4_l5" },
765 { "l6", QCOM_RPM_PM8058_LDO6
, &pm8058_pldo
, "vdd_l6_l7" },
766 { "l7", QCOM_RPM_PM8058_LDO7
, &pm8058_pldo
, "vdd_l6_l7" },
767 { "l8", QCOM_RPM_PM8058_LDO8
, &pm8058_pldo
, "vdd_l8" },
768 { "l9", QCOM_RPM_PM8058_LDO9
, &pm8058_pldo
, "vdd_l9" },
769 { "l10", QCOM_RPM_PM8058_LDO10
, &pm8058_pldo
, "vdd_l10" },
770 { "l11", QCOM_RPM_PM8058_LDO11
, &pm8058_pldo
, "vdd_l2_l11_l12" },
771 { "l12", QCOM_RPM_PM8058_LDO12
, &pm8058_pldo
, "vdd_l2_l11_l12" },
772 { "l13", QCOM_RPM_PM8058_LDO13
, &pm8058_pldo
, "vdd_l13_l16" },
773 { "l14", QCOM_RPM_PM8058_LDO14
, &pm8058_pldo
, "vdd_l14_l15" },
774 { "l15", QCOM_RPM_PM8058_LDO15
, &pm8058_pldo
, "vdd_l14_l15" },
775 { "l16", QCOM_RPM_PM8058_LDO16
, &pm8058_pldo
, "vdd_l13_l16" },
776 { "l17", QCOM_RPM_PM8058_LDO17
, &pm8058_pldo
, "vdd_l17_l18" },
777 { "l18", QCOM_RPM_PM8058_LDO18
, &pm8058_pldo
, "vdd_l17_l18" },
778 { "l19", QCOM_RPM_PM8058_LDO19
, &pm8058_pldo
, "vdd_l19_l20" },
779 { "l20", QCOM_RPM_PM8058_LDO20
, &pm8058_pldo
, "vdd_l19_l20" },
780 { "l21", QCOM_RPM_PM8058_LDO21
, &pm8058_nldo
, "vdd_l21" },
781 { "l22", QCOM_RPM_PM8058_LDO22
, &pm8058_nldo
, "vdd_l22" },
782 { "l23", QCOM_RPM_PM8058_LDO23
, &pm8058_nldo
, "vdd_l23_l24_l25" },
783 { "l24", QCOM_RPM_PM8058_LDO24
, &pm8058_nldo
, "vdd_l23_l24_l25" },
784 { "l25", QCOM_RPM_PM8058_LDO25
, &pm8058_nldo
, "vdd_l23_l24_l25" },
786 { "s0", QCOM_RPM_PM8058_SMPS0
, &pm8058_smps
, "vdd_s0" },
787 { "s1", QCOM_RPM_PM8058_SMPS1
, &pm8058_smps
, "vdd_s1" },
788 { "s2", QCOM_RPM_PM8058_SMPS2
, &pm8058_smps
, "vdd_s2" },
789 { "s3", QCOM_RPM_PM8058_SMPS3
, &pm8058_smps
, "vdd_s3" },
790 { "s4", QCOM_RPM_PM8058_SMPS4
, &pm8058_smps
, "vdd_s4" },
792 { "lvs0", QCOM_RPM_PM8058_LVS0
, &pm8058_switch
, "vdd_l0_l1_lvs" },
793 { "lvs1", QCOM_RPM_PM8058_LVS1
, &pm8058_switch
, "vdd_l0_l1_lvs" },
795 { "ncp", QCOM_RPM_PM8058_NCP
, &pm8058_ncp
, "vdd_ncp" },
799 static const struct rpm_regulator_data rpm_pm8901_regulators
[] = {
800 { "l0", QCOM_RPM_PM8901_LDO0
, &pm8901_nldo
, "vdd_l0" },
801 { "l1", QCOM_RPM_PM8901_LDO1
, &pm8901_pldo
, "vdd_l1" },
802 { "l2", QCOM_RPM_PM8901_LDO2
, &pm8901_pldo
, "vdd_l2" },
803 { "l3", QCOM_RPM_PM8901_LDO3
, &pm8901_pldo
, "vdd_l3" },
804 { "l4", QCOM_RPM_PM8901_LDO4
, &pm8901_pldo
, "vdd_l4" },
805 { "l5", QCOM_RPM_PM8901_LDO5
, &pm8901_pldo
, "vdd_l5" },
806 { "l6", QCOM_RPM_PM8901_LDO6
, &pm8901_pldo
, "vdd_l6" },
808 { "s0", QCOM_RPM_PM8901_SMPS0
, &pm8901_ftsmps
, "vdd_s0" },
809 { "s1", QCOM_RPM_PM8901_SMPS1
, &pm8901_ftsmps
, "vdd_s1" },
810 { "s2", QCOM_RPM_PM8901_SMPS2
, &pm8901_ftsmps
, "vdd_s2" },
811 { "s3", QCOM_RPM_PM8901_SMPS3
, &pm8901_ftsmps
, "vdd_s3" },
812 { "s4", QCOM_RPM_PM8901_SMPS4
, &pm8901_ftsmps
, "vdd_s4" },
814 { "lvs0", QCOM_RPM_PM8901_LVS0
, &pm8901_switch
, "lvs0_in" },
815 { "lvs1", QCOM_RPM_PM8901_LVS1
, &pm8901_switch
, "lvs1_in" },
816 { "lvs2", QCOM_RPM_PM8901_LVS2
, &pm8901_switch
, "lvs2_in" },
817 { "lvs3", QCOM_RPM_PM8901_LVS3
, &pm8901_switch
, "lvs3_in" },
819 { "mvs", QCOM_RPM_PM8901_MVS
, &pm8901_switch
, "mvs_in" },
823 static const struct rpm_regulator_data rpm_pm8921_regulators
[] = {
824 { "s1", QCOM_RPM_PM8921_SMPS1
, &pm8921_smps
, "vdd_s1" },
825 { "s2", QCOM_RPM_PM8921_SMPS2
, &pm8921_smps
, "vdd_s2" },
826 { "s3", QCOM_RPM_PM8921_SMPS3
, &pm8921_smps
},
827 { "s4", QCOM_RPM_PM8921_SMPS4
, &pm8921_smps
, "vdd_s4" },
828 { "s7", QCOM_RPM_PM8921_SMPS7
, &pm8921_smps
, "vdd_s7" },
829 { "s8", QCOM_RPM_PM8921_SMPS8
, &pm8921_smps
, "vdd_s8" },
831 { "l1", QCOM_RPM_PM8921_LDO1
, &pm8921_nldo
, "vdd_l1_l2_l12_l18" },
832 { "l2", QCOM_RPM_PM8921_LDO2
, &pm8921_nldo
, "vdd_l1_l2_l12_l18" },
833 { "l3", QCOM_RPM_PM8921_LDO3
, &pm8921_pldo
, "vdd_l3_l15_l17" },
834 { "l4", QCOM_RPM_PM8921_LDO4
, &pm8921_pldo
, "vdd_l4_l14" },
835 { "l5", QCOM_RPM_PM8921_LDO5
, &pm8921_pldo
, "vdd_l5_l8_l16" },
836 { "l6", QCOM_RPM_PM8921_LDO6
, &pm8921_pldo
, "vdd_l6_l7" },
837 { "l7", QCOM_RPM_PM8921_LDO7
, &pm8921_pldo
, "vdd_l6_l7" },
838 { "l8", QCOM_RPM_PM8921_LDO8
, &pm8921_pldo
, "vdd_l5_l8_l16" },
839 { "l9", QCOM_RPM_PM8921_LDO9
, &pm8921_pldo
, "vdd_l9_l11" },
840 { "l10", QCOM_RPM_PM8921_LDO10
, &pm8921_pldo
, "vdd_l10_l22" },
841 { "l11", QCOM_RPM_PM8921_LDO11
, &pm8921_pldo
, "vdd_l9_l11" },
842 { "l12", QCOM_RPM_PM8921_LDO12
, &pm8921_nldo
, "vdd_l1_l2_l12_l18" },
843 { "l14", QCOM_RPM_PM8921_LDO14
, &pm8921_pldo
, "vdd_l4_l14" },
844 { "l15", QCOM_RPM_PM8921_LDO15
, &pm8921_pldo
, "vdd_l3_l15_l17" },
845 { "l16", QCOM_RPM_PM8921_LDO16
, &pm8921_pldo
, "vdd_l5_l8_l16" },
846 { "l17", QCOM_RPM_PM8921_LDO17
, &pm8921_pldo
, "vdd_l3_l15_l17" },
847 { "l18", QCOM_RPM_PM8921_LDO18
, &pm8921_nldo
, "vdd_l1_l2_l12_l18" },
848 { "l21", QCOM_RPM_PM8921_LDO21
, &pm8921_pldo
, "vdd_l21_l23_l29" },
849 { "l22", QCOM_RPM_PM8921_LDO22
, &pm8921_pldo
, "vdd_l10_l22" },
850 { "l23", QCOM_RPM_PM8921_LDO23
, &pm8921_pldo
, "vdd_l21_l23_l29" },
851 { "l24", QCOM_RPM_PM8921_LDO24
, &pm8921_nldo1200
, "vdd_l24" },
852 { "l25", QCOM_RPM_PM8921_LDO25
, &pm8921_nldo1200
, "vdd_l25" },
853 { "l26", QCOM_RPM_PM8921_LDO26
, &pm8921_nldo1200
, "vdd_l26" },
854 { "l27", QCOM_RPM_PM8921_LDO27
, &pm8921_nldo1200
, "vdd_l27" },
855 { "l28", QCOM_RPM_PM8921_LDO28
, &pm8921_nldo1200
, "vdd_l28" },
856 { "l29", QCOM_RPM_PM8921_LDO29
, &pm8921_pldo
, "vdd_l21_l23_l29" },
858 { "lvs1", QCOM_RPM_PM8921_LVS1
, &pm8921_switch
, "vin_lvs1_3_6" },
859 { "lvs2", QCOM_RPM_PM8921_LVS2
, &pm8921_switch
, "vin_lvs2" },
860 { "lvs3", QCOM_RPM_PM8921_LVS3
, &pm8921_switch
, "vin_lvs1_3_6" },
861 { "lvs4", QCOM_RPM_PM8921_LVS4
, &pm8921_switch
, "vin_lvs4_5_7" },
862 { "lvs5", QCOM_RPM_PM8921_LVS5
, &pm8921_switch
, "vin_lvs4_5_7" },
863 { "lvs6", QCOM_RPM_PM8921_LVS6
, &pm8921_switch
, "vin_lvs1_3_6" },
864 { "lvs7", QCOM_RPM_PM8921_LVS7
, &pm8921_switch
, "vin_lvs4_5_7" },
866 { "usb-switch", QCOM_RPM_USB_OTG_SWITCH
, &pm8921_switch
, "vin_5vs" },
867 { "hdmi-switch", QCOM_RPM_HDMI_SWITCH
, &pm8921_switch
, "vin_5vs" },
868 { "ncp", QCOM_RPM_PM8921_NCP
, &pm8921_ncp
, "vdd_ncp" },
872 static const struct of_device_id rpm_of_match
[] = {
873 { .compatible
= "qcom,rpm-pm8058-regulators", .data
= &rpm_pm8058_regulators
},
874 { .compatible
= "qcom,rpm-pm8901-regulators", .data
= &rpm_pm8901_regulators
},
875 { .compatible
= "qcom,rpm-pm8921-regulators", .data
= &rpm_pm8921_regulators
},
878 MODULE_DEVICE_TABLE(of
, rpm_of_match
);
880 static int rpm_reg_probe(struct platform_device
*pdev
)
882 const struct rpm_regulator_data
*reg
;
883 const struct of_device_id
*match
;
884 struct regulator_config config
= { };
885 struct regulator_dev
*rdev
;
886 struct qcom_rpm_reg
*vreg
;
887 struct qcom_rpm
*rpm
;
889 rpm
= dev_get_drvdata(pdev
->dev
.parent
);
891 dev_err(&pdev
->dev
, "unable to retrieve handle to rpm\n");
895 match
= of_match_device(rpm_of_match
, &pdev
->dev
);
896 for (reg
= match
->data
; reg
->name
; reg
++) {
897 vreg
= devm_kmalloc(&pdev
->dev
, sizeof(*vreg
), GFP_KERNEL
);
901 memcpy(vreg
, reg
->template, sizeof(*vreg
));
902 mutex_init(&vreg
->lock
);
904 vreg
->dev
= &pdev
->dev
;
905 vreg
->resource
= reg
->resource
;
909 vreg
->desc
.owner
= THIS_MODULE
;
910 vreg
->desc
.type
= REGULATOR_VOLTAGE
;
911 vreg
->desc
.name
= reg
->name
;
912 vreg
->desc
.supply_name
= reg
->supply
;
913 vreg
->desc
.of_match
= reg
->name
;
914 vreg
->desc
.of_parse_cb
= rpm_reg_of_parse
;
916 config
.dev
= &pdev
->dev
;
917 config
.driver_data
= vreg
;
918 rdev
= devm_regulator_register(&pdev
->dev
, &vreg
->desc
, &config
);
920 dev_err(&pdev
->dev
, "failed to register %s\n", reg
->name
);
921 return PTR_ERR(rdev
);
928 static struct platform_driver rpm_reg_driver
= {
929 .probe
= rpm_reg_probe
,
931 .name
= "qcom_rpm_reg",
932 .of_match_table
= of_match_ptr(rpm_of_match
),
936 static int __init
rpm_reg_init(void)
938 return platform_driver_register(&rpm_reg_driver
);
940 subsys_initcall(rpm_reg_init
);
942 static void __exit
rpm_reg_exit(void)
944 platform_driver_unregister(&rpm_reg_driver
);
946 module_exit(rpm_reg_exit
)
948 MODULE_DESCRIPTION("Qualcomm RPM regulator driver");
949 MODULE_LICENSE("GPL v2");