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 ncp_ranges
[] = {
187 REGULATOR_LINEAR_RANGE(1500000, 0, 31, 50000),
190 static int rpm_reg_write(struct qcom_rpm_reg
*vreg
,
191 const struct request_member
*req
,
194 if (WARN_ON((value
<< req
->shift
) & ~req
->mask
))
197 vreg
->val
[req
->word
] &= ~req
->mask
;
198 vreg
->val
[req
->word
] |= value
<< req
->shift
;
200 return qcom_rpm_write(vreg
->rpm
,
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
);
224 if (vreg
->is_enabled
)
225 ret
= rpm_reg_write(vreg
, req
, vreg
->uV
/ 1000);
226 mutex_unlock(&vreg
->lock
);
231 static int rpm_reg_set_uV_sel(struct regulator_dev
*rdev
,
234 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
235 const struct rpm_reg_parts
*parts
= vreg
->parts
;
236 const struct request_member
*req
= &parts
->uV
;
243 uV
= regulator_list_voltage_linear_range(rdev
, selector
);
247 mutex_lock(&vreg
->lock
);
249 if (vreg
->is_enabled
)
250 ret
= rpm_reg_write(vreg
, req
, vreg
->uV
);
251 mutex_unlock(&vreg
->lock
);
256 static int rpm_reg_get_voltage(struct regulator_dev
*rdev
)
258 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
263 static int rpm_reg_mV_enable(struct regulator_dev
*rdev
)
265 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
266 const struct rpm_reg_parts
*parts
= vreg
->parts
;
267 const struct request_member
*req
= &parts
->mV
;
273 mutex_lock(&vreg
->lock
);
274 ret
= rpm_reg_write(vreg
, req
, vreg
->uV
/ 1000);
276 vreg
->is_enabled
= 1;
277 mutex_unlock(&vreg
->lock
);
282 static int rpm_reg_uV_enable(struct regulator_dev
*rdev
)
284 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
285 const struct rpm_reg_parts
*parts
= vreg
->parts
;
286 const struct request_member
*req
= &parts
->uV
;
292 mutex_lock(&vreg
->lock
);
293 ret
= rpm_reg_write(vreg
, req
, vreg
->uV
);
295 vreg
->is_enabled
= 1;
296 mutex_unlock(&vreg
->lock
);
301 static int rpm_reg_switch_enable(struct regulator_dev
*rdev
)
303 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
304 const struct rpm_reg_parts
*parts
= vreg
->parts
;
305 const struct request_member
*req
= &parts
->enable_state
;
311 mutex_lock(&vreg
->lock
);
312 ret
= rpm_reg_write(vreg
, req
, 1);
314 vreg
->is_enabled
= 1;
315 mutex_unlock(&vreg
->lock
);
320 static int rpm_reg_mV_disable(struct regulator_dev
*rdev
)
322 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
323 const struct rpm_reg_parts
*parts
= vreg
->parts
;
324 const struct request_member
*req
= &parts
->mV
;
330 mutex_lock(&vreg
->lock
);
331 ret
= rpm_reg_write(vreg
, req
, 0);
333 vreg
->is_enabled
= 0;
334 mutex_unlock(&vreg
->lock
);
339 static int rpm_reg_uV_disable(struct regulator_dev
*rdev
)
341 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
342 const struct rpm_reg_parts
*parts
= vreg
->parts
;
343 const struct request_member
*req
= &parts
->uV
;
349 mutex_lock(&vreg
->lock
);
350 ret
= rpm_reg_write(vreg
, req
, 0);
352 vreg
->is_enabled
= 0;
353 mutex_unlock(&vreg
->lock
);
358 static int rpm_reg_switch_disable(struct regulator_dev
*rdev
)
360 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
361 const struct rpm_reg_parts
*parts
= vreg
->parts
;
362 const struct request_member
*req
= &parts
->enable_state
;
368 mutex_lock(&vreg
->lock
);
369 ret
= rpm_reg_write(vreg
, req
, 0);
371 vreg
->is_enabled
= 0;
372 mutex_unlock(&vreg
->lock
);
377 static int rpm_reg_is_enabled(struct regulator_dev
*rdev
)
379 struct qcom_rpm_reg
*vreg
= rdev_get_drvdata(rdev
);
381 return vreg
->is_enabled
;
384 static struct regulator_ops uV_ops
= {
385 .list_voltage
= regulator_list_voltage_linear_range
,
387 .set_voltage_sel
= rpm_reg_set_uV_sel
,
388 .get_voltage
= rpm_reg_get_voltage
,
390 .enable
= rpm_reg_uV_enable
,
391 .disable
= rpm_reg_uV_disable
,
392 .is_enabled
= rpm_reg_is_enabled
,
395 static struct regulator_ops mV_ops
= {
396 .list_voltage
= regulator_list_voltage_linear_range
,
398 .set_voltage_sel
= rpm_reg_set_mV_sel
,
399 .get_voltage
= rpm_reg_get_voltage
,
401 .enable
= rpm_reg_mV_enable
,
402 .disable
= rpm_reg_mV_disable
,
403 .is_enabled
= rpm_reg_is_enabled
,
406 static struct regulator_ops switch_ops
= {
407 .enable
= rpm_reg_switch_enable
,
408 .disable
= rpm_reg_switch_disable
,
409 .is_enabled
= rpm_reg_is_enabled
,
415 static const struct qcom_rpm_reg pm8058_pldo
= {
416 .desc
.linear_ranges
= pldo_ranges
,
417 .desc
.n_linear_ranges
= ARRAY_SIZE(pldo_ranges
),
418 .desc
.n_voltages
= 161,
420 .parts
= &rpm8660_ldo_parts
,
421 .supports_force_mode_auto
= false,
422 .supports_force_mode_bypass
= false,
425 static const struct qcom_rpm_reg pm8058_nldo
= {
426 .desc
.linear_ranges
= nldo_ranges
,
427 .desc
.n_linear_ranges
= ARRAY_SIZE(nldo_ranges
),
428 .desc
.n_voltages
= 64,
430 .parts
= &rpm8660_ldo_parts
,
431 .supports_force_mode_auto
= false,
432 .supports_force_mode_bypass
= false,
435 static const struct qcom_rpm_reg pm8058_smps
= {
436 .desc
.linear_ranges
= smps_ranges
,
437 .desc
.n_linear_ranges
= ARRAY_SIZE(smps_ranges
),
438 .desc
.n_voltages
= 154,
440 .parts
= &rpm8660_smps_parts
,
441 .supports_force_mode_auto
= false,
442 .supports_force_mode_bypass
= false,
445 static const struct qcom_rpm_reg pm8058_ncp
= {
446 .desc
.linear_ranges
= ncp_ranges
,
447 .desc
.n_linear_ranges
= ARRAY_SIZE(ncp_ranges
),
448 .desc
.n_voltages
= 32,
450 .parts
= &rpm8660_ncp_parts
,
453 static const struct qcom_rpm_reg pm8058_switch
= {
454 .desc
.ops
= &switch_ops
,
455 .parts
= &rpm8660_switch_parts
,
461 static const struct qcom_rpm_reg pm8901_pldo
= {
462 .desc
.linear_ranges
= pldo_ranges
,
463 .desc
.n_linear_ranges
= ARRAY_SIZE(pldo_ranges
),
464 .desc
.n_voltages
= 161,
466 .parts
= &rpm8660_ldo_parts
,
467 .supports_force_mode_auto
= false,
468 .supports_force_mode_bypass
= true,
471 static const struct qcom_rpm_reg pm8901_nldo
= {
472 .desc
.linear_ranges
= nldo_ranges
,
473 .desc
.n_linear_ranges
= ARRAY_SIZE(nldo_ranges
),
474 .desc
.n_voltages
= 64,
476 .parts
= &rpm8660_ldo_parts
,
477 .supports_force_mode_auto
= false,
478 .supports_force_mode_bypass
= true,
481 static const struct qcom_rpm_reg pm8901_ftsmps
= {
482 .desc
.linear_ranges
= ftsmps_ranges
,
483 .desc
.n_linear_ranges
= ARRAY_SIZE(ftsmps_ranges
),
484 .desc
.n_voltages
= 101,
486 .parts
= &rpm8660_smps_parts
,
487 .supports_force_mode_auto
= true,
488 .supports_force_mode_bypass
= false,
491 static const struct qcom_rpm_reg pm8901_switch
= {
492 .desc
.ops
= &switch_ops
,
493 .parts
= &rpm8660_switch_parts
,
499 static const struct qcom_rpm_reg pm8921_pldo
= {
500 .desc
.linear_ranges
= pldo_ranges
,
501 .desc
.n_linear_ranges
= ARRAY_SIZE(pldo_ranges
),
502 .desc
.n_voltages
= 161,
504 .parts
= &rpm8960_ldo_parts
,
505 .supports_force_mode_auto
= false,
506 .supports_force_mode_bypass
= true,
509 static const struct qcom_rpm_reg pm8921_nldo
= {
510 .desc
.linear_ranges
= nldo_ranges
,
511 .desc
.n_linear_ranges
= ARRAY_SIZE(nldo_ranges
),
512 .desc
.n_voltages
= 64,
514 .parts
= &rpm8960_ldo_parts
,
515 .supports_force_mode_auto
= false,
516 .supports_force_mode_bypass
= true,
519 static const struct qcom_rpm_reg pm8921_nldo1200
= {
520 .desc
.linear_ranges
= nldo1200_ranges
,
521 .desc
.n_linear_ranges
= ARRAY_SIZE(nldo1200_ranges
),
522 .desc
.n_voltages
= 124,
524 .parts
= &rpm8960_ldo_parts
,
525 .supports_force_mode_auto
= false,
526 .supports_force_mode_bypass
= true,
529 static const struct qcom_rpm_reg pm8921_smps
= {
530 .desc
.linear_ranges
= smps_ranges
,
531 .desc
.n_linear_ranges
= ARRAY_SIZE(smps_ranges
),
532 .desc
.n_voltages
= 154,
534 .parts
= &rpm8960_smps_parts
,
535 .supports_force_mode_auto
= true,
536 .supports_force_mode_bypass
= false,
539 static const struct qcom_rpm_reg pm8921_ftsmps
= {
540 .desc
.linear_ranges
= ftsmps_ranges
,
541 .desc
.n_linear_ranges
= ARRAY_SIZE(ftsmps_ranges
),
542 .desc
.n_voltages
= 101,
544 .parts
= &rpm8960_smps_parts
,
545 .supports_force_mode_auto
= true,
546 .supports_force_mode_bypass
= false,
549 static const struct qcom_rpm_reg pm8921_ncp
= {
550 .desc
.linear_ranges
= ncp_ranges
,
551 .desc
.n_linear_ranges
= ARRAY_SIZE(ncp_ranges
),
552 .desc
.n_voltages
= 32,
554 .parts
= &rpm8960_ncp_parts
,
557 static const struct qcom_rpm_reg pm8921_switch
= {
558 .desc
.ops
= &switch_ops
,
559 .parts
= &rpm8960_switch_parts
,
562 static const struct of_device_id rpm_of_match
[] = {
563 { .compatible
= "qcom,rpm-pm8058-pldo", .data
= &pm8058_pldo
},
564 { .compatible
= "qcom,rpm-pm8058-nldo", .data
= &pm8058_nldo
},
565 { .compatible
= "qcom,rpm-pm8058-smps", .data
= &pm8058_smps
},
566 { .compatible
= "qcom,rpm-pm8058-ncp", .data
= &pm8058_ncp
},
567 { .compatible
= "qcom,rpm-pm8058-switch", .data
= &pm8058_switch
},
569 { .compatible
= "qcom,rpm-pm8901-pldo", .data
= &pm8901_pldo
},
570 { .compatible
= "qcom,rpm-pm8901-nldo", .data
= &pm8901_nldo
},
571 { .compatible
= "qcom,rpm-pm8901-ftsmps", .data
= &pm8901_ftsmps
},
572 { .compatible
= "qcom,rpm-pm8901-switch", .data
= &pm8901_switch
},
574 { .compatible
= "qcom,rpm-pm8921-pldo", .data
= &pm8921_pldo
},
575 { .compatible
= "qcom,rpm-pm8921-nldo", .data
= &pm8921_nldo
},
576 { .compatible
= "qcom,rpm-pm8921-nldo1200", .data
= &pm8921_nldo1200
},
577 { .compatible
= "qcom,rpm-pm8921-smps", .data
= &pm8921_smps
},
578 { .compatible
= "qcom,rpm-pm8921-ftsmps", .data
= &pm8921_ftsmps
},
579 { .compatible
= "qcom,rpm-pm8921-ncp", .data
= &pm8921_ncp
},
580 { .compatible
= "qcom,rpm-pm8921-switch", .data
= &pm8921_switch
},
583 MODULE_DEVICE_TABLE(of
, rpm_of_match
);
585 static int rpm_reg_set(struct qcom_rpm_reg
*vreg
,
586 const struct request_member
*req
,
589 if (req
->mask
== 0 || (value
<< req
->shift
) & ~req
->mask
)
592 vreg
->val
[req
->word
] &= ~req
->mask
;
593 vreg
->val
[req
->word
] |= value
<< req
->shift
;
598 static int rpm_reg_of_parse_freq(struct device
*dev
, struct qcom_rpm_reg
*vreg
)
600 static const int freq_table
[] = {
601 19200000, 9600000, 6400000, 4800000, 3840000, 3200000, 2740000,
602 2400000, 2130000, 1920000, 1750000, 1600000, 1480000, 1370000,
611 key
= "qcom,switch-mode-frequency";
612 ret
= of_property_read_u32(dev
->of_node
, key
, &freq
);
614 dev_err(dev
, "regulator requires %s property\n", key
);
618 for (i
= 0; i
< ARRAY_SIZE(freq_table
); i
++) {
619 if (freq
== freq_table
[i
]) {
620 rpm_reg_set(vreg
, &vreg
->parts
->freq
, i
+ 1);
625 dev_err(dev
, "invalid frequency %d\n", freq
);
629 static int rpm_reg_probe(struct platform_device
*pdev
)
631 struct regulator_init_data
*initdata
;
632 const struct qcom_rpm_reg
*template;
633 const struct of_device_id
*match
;
634 struct regulator_config config
= { };
635 struct regulator_dev
*rdev
;
636 struct qcom_rpm_reg
*vreg
;
643 match
= of_match_device(rpm_of_match
, &pdev
->dev
);
644 template = match
->data
;
646 initdata
= of_get_regulator_init_data(&pdev
->dev
, pdev
->dev
.of_node
);
650 vreg
= devm_kmalloc(&pdev
->dev
, sizeof(*vreg
), GFP_KERNEL
);
652 dev_err(&pdev
->dev
, "failed to allocate vreg\n");
655 memcpy(vreg
, template, sizeof(*vreg
));
656 mutex_init(&vreg
->lock
);
657 vreg
->dev
= &pdev
->dev
;
659 vreg
->desc
.owner
= THIS_MODULE
;
660 vreg
->desc
.type
= REGULATOR_VOLTAGE
;
661 vreg
->desc
.name
= pdev
->dev
.of_node
->name
;
663 vreg
->rpm
= dev_get_drvdata(pdev
->dev
.parent
);
665 dev_err(&pdev
->dev
, "unable to retrieve handle to rpm\n");
670 ret
= of_property_read_u32(pdev
->dev
.of_node
, key
, &val
);
672 dev_err(&pdev
->dev
, "failed to read %s\n", key
);
675 vreg
->resource
= val
;
677 if ((vreg
->parts
->uV
.mask
|| vreg
->parts
->mV
.mask
) &&
678 (!initdata
->constraints
.min_uV
|| !initdata
->constraints
.max_uV
)) {
679 dev_err(&pdev
->dev
, "no voltage specified for regulator\n");
683 key
= "bias-pull-down";
684 if (of_property_read_bool(pdev
->dev
.of_node
, key
)) {
685 ret
= rpm_reg_set(vreg
, &vreg
->parts
->pd
, 1);
687 dev_err(&pdev
->dev
, "%s is invalid", key
);
692 if (vreg
->parts
->freq
.mask
) {
693 ret
= rpm_reg_of_parse_freq(&pdev
->dev
, vreg
);
698 if (vreg
->parts
->pm
.mask
) {
699 key
= "qcom,power-mode-hysteretic";
700 pwm
= !of_property_read_bool(pdev
->dev
.of_node
, key
);
702 ret
= rpm_reg_set(vreg
, &vreg
->parts
->pm
, pwm
);
704 dev_err(&pdev
->dev
, "failed to set power mode\n");
709 if (vreg
->parts
->fm
.mask
) {
712 key
= "qcom,force-mode";
713 ret
= of_property_read_u32(pdev
->dev
.of_node
, key
, &val
);
714 if (ret
== -EINVAL
) {
715 val
= QCOM_RPM_FORCE_MODE_NONE
;
716 } else if (ret
< 0) {
717 dev_err(&pdev
->dev
, "failed to read %s\n", key
);
722 * If force-mode is encoded as 2 bits then the
723 * possible register values are:
726 * NONE, LPM, AUTO, HPM, BYPASS
729 case QCOM_RPM_FORCE_MODE_NONE
:
732 case QCOM_RPM_FORCE_MODE_LPM
:
735 case QCOM_RPM_FORCE_MODE_HPM
:
736 if (FORCE_MODE_IS_2_BITS(vreg
))
741 case QCOM_RPM_FORCE_MODE_AUTO
:
742 if (vreg
->supports_force_mode_auto
)
745 case QCOM_RPM_FORCE_MODE_BYPASS
:
746 if (vreg
->supports_force_mode_bypass
)
751 if (force_mode
< 0) {
752 dev_err(&pdev
->dev
, "invalid force mode\n");
756 ret
= rpm_reg_set(vreg
, &vreg
->parts
->fm
, force_mode
);
758 dev_err(&pdev
->dev
, "failed to set force mode\n");
763 config
.dev
= &pdev
->dev
;
764 config
.init_data
= initdata
;
765 config
.driver_data
= vreg
;
766 config
.of_node
= pdev
->dev
.of_node
;
767 rdev
= devm_regulator_register(&pdev
->dev
, &vreg
->desc
, &config
);
769 dev_err(&pdev
->dev
, "can't register regulator\n");
770 return PTR_ERR(rdev
);
776 static struct platform_driver rpm_reg_driver
= {
777 .probe
= rpm_reg_probe
,
779 .name
= "qcom_rpm_reg",
780 .owner
= THIS_MODULE
,
781 .of_match_table
= of_match_ptr(rpm_of_match
),
785 static int __init
rpm_reg_init(void)
787 return platform_driver_register(&rpm_reg_driver
);
789 subsys_initcall(rpm_reg_init
);
791 static void __exit
rpm_reg_exit(void)
793 platform_driver_unregister(&rpm_reg_driver
);
795 module_exit(rpm_reg_exit
)
797 MODULE_DESCRIPTION("Qualcomm RPM regulator driver");
798 MODULE_LICENSE("GPL v2");