2 * tps80031-regulator.c -- TI TPS80031 regulator driver.
4 * Regulator driver for TI TPS80031/TPS80032 Fully Integrated Power
5 * Management with Power Path and Battery Charger.
7 * Copyright (c) 2012, NVIDIA Corporation.
9 * Author: Laxman Dewangan <ldewangan@nvidia.com>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation version 2.
15 * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
16 * whether express or implied; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 #include <linux/delay.h>
27 #include <linux/err.h>
28 #include <linux/init.h>
29 #include <linux/kernel.h>
30 #include <linux/mfd/tps80031.h>
31 #include <linux/module.h>
32 #include <linux/platform_device.h>
33 #include <linux/regulator/driver.h>
34 #include <linux/regulator/machine.h>
35 #include <linux/slab.h>
37 /* Flags for DCDC Voltage reading */
38 #define DCDC_OFFSET_EN BIT(0)
39 #define DCDC_EXTENDED_EN BIT(1)
40 #define TRACK_MODE_ENABLE BIT(2)
42 #define SMPS_MULTOFFSET_VIO BIT(1)
43 #define SMPS_MULTOFFSET_SMPS1 BIT(3)
44 #define SMPS_MULTOFFSET_SMPS2 BIT(4)
45 #define SMPS_MULTOFFSET_SMPS3 BIT(6)
46 #define SMPS_MULTOFFSET_SMPS4 BIT(0)
48 #define SMPS_CMD_MASK 0xC0
49 #define SMPS_VSEL_MASK 0x3F
50 #define LDO_VSEL_MASK 0x1F
51 #define LDO_TRACK_VSEL_MASK 0x3F
53 #define MISC2_LDOUSB_IN_VSYS BIT(4)
54 #define MISC2_LDOUSB_IN_PMID BIT(3)
55 #define MISC2_LDOUSB_IN_MASK 0x18
57 #define MISC2_LDO3_SEL_VIB_VAL BIT(0)
58 #define MISC2_LDO3_SEL_VIB_MASK 0x1
60 #define BOOST_HW_PWR_EN BIT(5)
61 #define BOOST_HW_PWR_EN_MASK BIT(5)
63 #define OPA_MODE_EN BIT(6)
64 #define OPA_MODE_EN_MASK BIT(6)
66 #define USB_VBUS_CTRL_SET 0x04
67 #define USB_VBUS_CTRL_CLR 0x05
68 #define VBUS_DISCHRG 0x20
70 struct tps80031_regulator_info
{
71 /* Regulator register address.*/
78 /*Power request bits */
81 /* used by regulator core */
82 struct regulator_desc desc
;
86 struct tps80031_regulator
{
88 struct regulator_dev
*rdev
;
89 struct tps80031_regulator_info
*rinfo
;
92 unsigned int config_flags
;
93 unsigned int ext_ctrl_flag
;
96 static inline struct device
*to_tps80031_dev(struct regulator_dev
*rdev
)
98 return rdev_get_dev(rdev
)->parent
->parent
;
101 static int tps80031_reg_is_enabled(struct regulator_dev
*rdev
)
103 struct tps80031_regulator
*ri
= rdev_get_drvdata(rdev
);
104 struct device
*parent
= to_tps80031_dev(rdev
);
108 if (ri
->ext_ctrl_flag
& TPS80031_EXT_PWR_REQ
)
111 ret
= tps80031_read(parent
, TPS80031_SLAVE_ID1
, ri
->rinfo
->state_reg
,
114 dev_err(&rdev
->dev
, "Reg 0x%02x read failed, err = %d\n",
115 ri
->rinfo
->state_reg
, ret
);
118 return (reg_val
& TPS80031_STATE_MASK
) == TPS80031_STATE_ON
;
121 static int tps80031_reg_enable(struct regulator_dev
*rdev
)
123 struct tps80031_regulator
*ri
= rdev_get_drvdata(rdev
);
124 struct device
*parent
= to_tps80031_dev(rdev
);
127 if (ri
->ext_ctrl_flag
& TPS80031_EXT_PWR_REQ
)
130 ret
= tps80031_update(parent
, TPS80031_SLAVE_ID1
, ri
->rinfo
->state_reg
,
131 TPS80031_STATE_ON
, TPS80031_STATE_MASK
);
133 dev_err(&rdev
->dev
, "Reg 0x%02x update failed, err = %d\n",
134 ri
->rinfo
->state_reg
, ret
);
140 static int tps80031_reg_disable(struct regulator_dev
*rdev
)
142 struct tps80031_regulator
*ri
= rdev_get_drvdata(rdev
);
143 struct device
*parent
= to_tps80031_dev(rdev
);
146 if (ri
->ext_ctrl_flag
& TPS80031_EXT_PWR_REQ
)
149 ret
= tps80031_update(parent
, TPS80031_SLAVE_ID1
, ri
->rinfo
->state_reg
,
150 TPS80031_STATE_OFF
, TPS80031_STATE_MASK
);
152 dev_err(&rdev
->dev
, "Reg 0x%02x update failed, err = %d\n",
153 ri
->rinfo
->state_reg
, ret
);
157 /* DCDC voltages for the selector of 58 to 63 */
158 static int tps80031_dcdc_voltages
[4][5] = {
159 { 1350, 1500, 1800, 1900, 2100},
160 { 1350, 1500, 1800, 1900, 2100},
161 { 2084, 2315, 2778, 2932, 3241},
162 { 4167, 2315, 2778, 2932, 3241},
165 static int tps80031_dcdc_list_voltage(struct regulator_dev
*rdev
, unsigned sel
)
167 struct tps80031_regulator
*ri
= rdev_get_drvdata(rdev
);
168 int volt_index
= ri
->device_flags
& 0x3;
173 return regulator_list_voltage_linear(rdev
, sel
- 1);
175 return tps80031_dcdc_voltages
[volt_index
][sel
- 58] * 1000;
178 static int tps80031_dcdc_set_voltage_sel(struct regulator_dev
*rdev
,
181 struct tps80031_regulator
*ri
= rdev_get_drvdata(rdev
);
182 struct device
*parent
= to_tps80031_dev(rdev
);
186 if (ri
->rinfo
->force_reg
) {
187 ret
= tps80031_read(parent
, ri
->rinfo
->volt_id
,
188 ri
->rinfo
->force_reg
, ®_val
);
190 dev_err(ri
->dev
, "reg 0x%02x read failed, e = %d\n",
191 ri
->rinfo
->force_reg
, ret
);
194 if (!(reg_val
& SMPS_CMD_MASK
)) {
195 ret
= tps80031_update(parent
, ri
->rinfo
->volt_id
,
196 ri
->rinfo
->force_reg
, vsel
, SMPS_VSEL_MASK
);
199 "reg 0x%02x update failed, e = %d\n",
200 ri
->rinfo
->force_reg
, ret
);
204 ret
= tps80031_update(parent
, ri
->rinfo
->volt_id
,
205 ri
->rinfo
->volt_reg
, vsel
, SMPS_VSEL_MASK
);
207 dev_err(ri
->dev
, "reg 0x%02x update failed, e = %d\n",
208 ri
->rinfo
->volt_reg
, ret
);
212 static int tps80031_dcdc_get_voltage_sel(struct regulator_dev
*rdev
)
214 struct tps80031_regulator
*ri
= rdev_get_drvdata(rdev
);
215 struct device
*parent
= to_tps80031_dev(rdev
);
219 if (ri
->rinfo
->force_reg
) {
220 ret
= tps80031_read(parent
, ri
->rinfo
->volt_id
,
221 ri
->rinfo
->force_reg
, &vsel
);
223 dev_err(ri
->dev
, "reg 0x%02x read failed, e = %d\n",
224 ri
->rinfo
->force_reg
, ret
);
228 if (!(vsel
& SMPS_CMD_MASK
))
229 return vsel
& SMPS_VSEL_MASK
;
231 ret
= tps80031_read(parent
, ri
->rinfo
->volt_id
,
232 ri
->rinfo
->volt_reg
, &vsel
);
234 dev_err(ri
->dev
, "reg 0x%02x read failed, e = %d\n",
235 ri
->rinfo
->volt_reg
, ret
);
238 return vsel
& SMPS_VSEL_MASK
;
241 static int tps80031_ldo_list_voltage(struct regulator_dev
*rdev
,
244 struct tps80031_regulator
*ri
= rdev_get_drvdata(rdev
);
245 struct device
*parent
= to_tps80031_dev(rdev
);
247 /* Check for valid setting for TPS80031 or TPS80032-ES1.0 */
248 if ((ri
->rinfo
->desc
.id
== TPS80031_REGULATOR_LDO2
) &&
249 (ri
->device_flags
& TRACK_MODE_ENABLE
)) {
250 unsigned nvsel
= (sel
) & 0x1F;
251 if (((tps80031_get_chip_info(parent
) == TPS80031
) ||
252 ((tps80031_get_chip_info(parent
) == TPS80032
) &&
253 (tps80031_get_pmu_version(parent
) == 0x0))) &&
254 ((nvsel
== 0x0) || (nvsel
>= 0x19 && nvsel
<= 0x1F))) {
256 "Invalid sel %d in track mode LDO2\n",
262 return regulator_list_voltage_linear(rdev
, sel
);
265 static int tps80031_ldo_map_voltage(struct regulator_dev
*rdev
,
266 int min_uV
, int max_uV
)
268 struct tps80031_regulator
*ri
= rdev_get_drvdata(rdev
);
269 struct device
*parent
= to_tps80031_dev(rdev
);
271 /* Check for valid setting for TPS80031 or TPS80032-ES1.0 */
272 if ((ri
->rinfo
->desc
.id
== TPS80031_REGULATOR_LDO2
) &&
273 (ri
->device_flags
& TRACK_MODE_ENABLE
)) {
274 if (((tps80031_get_chip_info(parent
) == TPS80031
) ||
275 ((tps80031_get_chip_info(parent
) == TPS80032
) &&
276 (tps80031_get_pmu_version(parent
) == 0x0)))) {
277 return regulator_map_voltage_iterate(rdev
, min_uV
,
282 return regulator_map_voltage_linear(rdev
, min_uV
, max_uV
);
285 static int tps80031_vbus_is_enabled(struct regulator_dev
*rdev
)
287 struct tps80031_regulator
*ri
= rdev_get_drvdata(rdev
);
288 struct device
*parent
= to_tps80031_dev(rdev
);
293 ret
= tps80031_read(parent
, TPS80031_SLAVE_ID2
,
294 TPS80031_CHARGERUSB_CTRL1
, &ctrl1
);
296 dev_err(ri
->dev
, "reg 0x%02x read failed, e = %d\n",
297 TPS80031_CHARGERUSB_CTRL1
, ret
);
300 ret
= tps80031_read(parent
, TPS80031_SLAVE_ID2
,
301 TPS80031_CHARGERUSB_CTRL3
, &ctrl3
);
303 dev_err(ri
->dev
, "reg 0x%02x read failed, e = %d\n",
304 TPS80031_CHARGERUSB_CTRL3
, ret
);
307 if ((ctrl1
& OPA_MODE_EN
) && (ctrl3
& BOOST_HW_PWR_EN
))
312 static int tps80031_vbus_enable(struct regulator_dev
*rdev
)
314 struct tps80031_regulator
*ri
= rdev_get_drvdata(rdev
);
315 struct device
*parent
= to_tps80031_dev(rdev
);
318 ret
= tps80031_set_bits(parent
, TPS80031_SLAVE_ID2
,
319 TPS80031_CHARGERUSB_CTRL1
, OPA_MODE_EN
);
321 dev_err(ri
->dev
, "reg 0x%02x read failed, e = %d\n",
322 TPS80031_CHARGERUSB_CTRL1
, ret
);
326 ret
= tps80031_set_bits(parent
, TPS80031_SLAVE_ID2
,
327 TPS80031_CHARGERUSB_CTRL3
, BOOST_HW_PWR_EN
);
329 dev_err(ri
->dev
, "reg 0x%02x read failed, e = %d\n",
330 TPS80031_CHARGERUSB_CTRL3
, ret
);
336 static int tps80031_vbus_disable(struct regulator_dev
*rdev
)
338 struct tps80031_regulator
*ri
= rdev_get_drvdata(rdev
);
339 struct device
*parent
= to_tps80031_dev(rdev
);
342 if (ri
->config_flags
& TPS80031_VBUS_DISCHRG_EN_PDN
) {
343 ret
= tps80031_write(parent
, TPS80031_SLAVE_ID2
,
344 USB_VBUS_CTRL_SET
, VBUS_DISCHRG
);
346 dev_err(ri
->dev
, "reg 0x%02x write failed, e = %d\n",
347 USB_VBUS_CTRL_SET
, ret
);
352 ret
= tps80031_clr_bits(parent
, TPS80031_SLAVE_ID2
,
353 TPS80031_CHARGERUSB_CTRL1
, OPA_MODE_EN
);
355 dev_err(ri
->dev
, "reg 0x%02x clearbit failed, e = %d\n",
356 TPS80031_CHARGERUSB_CTRL1
, ret
);
360 ret
= tps80031_clr_bits(parent
, TPS80031_SLAVE_ID2
,
361 TPS80031_CHARGERUSB_CTRL3
, BOOST_HW_PWR_EN
);
363 dev_err(ri
->dev
, "reg 0x%02x clearbit failed, e = %d\n",
364 TPS80031_CHARGERUSB_CTRL3
, ret
);
368 mdelay(DIV_ROUND_UP(ri
->rinfo
->desc
.enable_time
, 1000));
369 if (ri
->config_flags
& TPS80031_VBUS_DISCHRG_EN_PDN
) {
370 ret
= tps80031_write(parent
, TPS80031_SLAVE_ID2
,
371 USB_VBUS_CTRL_CLR
, VBUS_DISCHRG
);
373 dev_err(ri
->dev
, "reg 0x%02x write failed, e = %d\n",
374 USB_VBUS_CTRL_CLR
, ret
);
381 static struct regulator_ops tps80031_dcdc_ops
= {
382 .list_voltage
= tps80031_dcdc_list_voltage
,
383 .set_voltage_sel
= tps80031_dcdc_set_voltage_sel
,
384 .get_voltage_sel
= tps80031_dcdc_get_voltage_sel
,
385 .enable
= tps80031_reg_enable
,
386 .disable
= tps80031_reg_disable
,
387 .is_enabled
= tps80031_reg_is_enabled
,
390 static struct regulator_ops tps80031_ldo_ops
= {
391 .list_voltage
= tps80031_ldo_list_voltage
,
392 .map_voltage
= tps80031_ldo_map_voltage
,
393 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
394 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
395 .enable
= tps80031_reg_enable
,
396 .disable
= tps80031_reg_disable
,
397 .is_enabled
= tps80031_reg_is_enabled
,
400 static struct regulator_ops tps80031_vbus_sw_ops
= {
401 .list_voltage
= regulator_list_voltage_linear
,
402 .enable
= tps80031_vbus_enable
,
403 .disable
= tps80031_vbus_disable
,
404 .is_enabled
= tps80031_vbus_is_enabled
,
407 static struct regulator_ops tps80031_vbus_hw_ops
= {
408 .list_voltage
= regulator_list_voltage_linear
,
411 static struct regulator_ops tps80031_ext_reg_ops
= {
412 .list_voltage
= regulator_list_voltage_linear
,
413 .enable
= tps80031_reg_enable
,
414 .disable
= tps80031_reg_disable
,
415 .is_enabled
= tps80031_reg_is_enabled
,
418 /* Non-exiting default definition for some register */
419 #define TPS80031_SMPS3_CFG_FORCE 0
420 #define TPS80031_SMPS4_CFG_FORCE 0
422 #define TPS80031_VBUS_CFG_TRANS 0
423 #define TPS80031_VBUS_CFG_STATE 0
425 #define TPS80031_REG_SMPS(_id, _volt_id, _pbit) \
427 .trans_reg = TPS80031_##_id##_CFG_TRANS, \
428 .state_reg = TPS80031_##_id##_CFG_STATE, \
429 .force_reg = TPS80031_##_id##_CFG_FORCE, \
430 .volt_reg = TPS80031_##_id##_CFG_VOLTAGE, \
431 .volt_id = TPS80031_SLAVE_##_volt_id, \
434 .name = "tps80031_"#_id, \
435 .id = TPS80031_REGULATOR_##_id, \
437 .ops = &tps80031_dcdc_ops, \
438 .type = REGULATOR_VOLTAGE, \
439 .owner = THIS_MODULE, \
440 .enable_time = 500, \
444 #define TPS80031_REG_LDO(_id, _preq_bit) \
446 .trans_reg = TPS80031_##_id##_CFG_TRANS, \
447 .state_reg = TPS80031_##_id##_CFG_STATE, \
448 .volt_reg = TPS80031_##_id##_CFG_VOLTAGE, \
449 .volt_id = TPS80031_SLAVE_ID1, \
450 .preq_bit = _preq_bit, \
452 .owner = THIS_MODULE, \
453 .name = "tps80031_"#_id, \
454 .id = TPS80031_REGULATOR_##_id, \
455 .ops = &tps80031_ldo_ops, \
456 .type = REGULATOR_VOLTAGE, \
459 .linear_min_sel = 1, \
461 .vsel_reg = TPS80031_##_id##_CFG_VOLTAGE, \
462 .vsel_mask = LDO_VSEL_MASK, \
463 .enable_time = 500, \
467 #define TPS80031_REG_FIXED(_id, max_mV, _ops, _delay, _pbit) \
469 .trans_reg = TPS80031_##_id##_CFG_TRANS, \
470 .state_reg = TPS80031_##_id##_CFG_STATE, \
471 .volt_id = TPS80031_SLAVE_ID1, \
474 .name = "tps80031_"#_id, \
475 .id = TPS80031_REGULATOR_##_id, \
476 .min_uV = max_mV * 1000, \
479 .type = REGULATOR_VOLTAGE, \
480 .owner = THIS_MODULE, \
481 .enable_time = _delay, \
485 static struct tps80031_regulator_info tps80031_rinfo
[TPS80031_REGULATOR_MAX
] = {
486 TPS80031_REG_SMPS(VIO
, ID0
, 4),
487 TPS80031_REG_SMPS(SMPS1
, ID0
, 0),
488 TPS80031_REG_SMPS(SMPS2
, ID0
, 1),
489 TPS80031_REG_SMPS(SMPS3
, ID1
, 2),
490 TPS80031_REG_SMPS(SMPS4
, ID1
, 3),
491 TPS80031_REG_LDO(VANA
, -1),
492 TPS80031_REG_LDO(LDO1
, 8),
493 TPS80031_REG_LDO(LDO2
, 9),
494 TPS80031_REG_LDO(LDO3
, 10),
495 TPS80031_REG_LDO(LDO4
, 11),
496 TPS80031_REG_LDO(LDO5
, 12),
497 TPS80031_REG_LDO(LDO6
, 13),
498 TPS80031_REG_LDO(LDO7
, 14),
499 TPS80031_REG_LDO(LDOLN
, 15),
500 TPS80031_REG_LDO(LDOUSB
, 5),
501 TPS80031_REG_FIXED(VBUS
, 5000, tps80031_vbus_hw_ops
, 100000, -1),
502 TPS80031_REG_FIXED(REGEN1
, 3300, tps80031_ext_reg_ops
, 0, 16),
503 TPS80031_REG_FIXED(REGEN2
, 3300, tps80031_ext_reg_ops
, 0, 17),
504 TPS80031_REG_FIXED(SYSEN
, 3300, tps80031_ext_reg_ops
, 0, 18),
507 static int tps80031_power_req_config(struct device
*parent
,
508 struct tps80031_regulator
*ri
,
509 struct tps80031_regulator_platform_data
*tps80031_pdata
)
513 if (ri
->rinfo
->preq_bit
< 0)
514 goto skip_pwr_req_config
;
516 ret
= tps80031_ext_power_req_config(parent
, ri
->ext_ctrl_flag
,
517 ri
->rinfo
->preq_bit
, ri
->rinfo
->state_reg
,
518 ri
->rinfo
->trans_reg
);
520 dev_err(ri
->dev
, "ext powerreq config failed, err = %d\n", ret
);
525 if (tps80031_pdata
->ext_ctrl_flag
& TPS80031_PWR_ON_ON_SLEEP
) {
526 ret
= tps80031_update(parent
, TPS80031_SLAVE_ID1
,
527 ri
->rinfo
->trans_reg
, TPS80031_TRANS_SLEEP_ON
,
528 TPS80031_TRANS_SLEEP_MASK
);
530 dev_err(ri
->dev
, "Reg 0x%02x update failed, e %d\n",
531 ri
->rinfo
->trans_reg
, ret
);
538 static int tps80031_regulator_config(struct device
*parent
,
539 struct tps80031_regulator
*ri
,
540 struct tps80031_regulator_platform_data
*tps80031_pdata
)
544 switch (ri
->rinfo
->desc
.id
) {
545 case TPS80031_REGULATOR_LDOUSB
:
546 if (ri
->config_flags
& (TPS80031_USBLDO_INPUT_VSYS
|
547 TPS80031_USBLDO_INPUT_PMID
)) {
549 if (ri
->config_flags
& TPS80031_USBLDO_INPUT_VSYS
)
550 val
= MISC2_LDOUSB_IN_VSYS
;
552 val
= MISC2_LDOUSB_IN_PMID
;
554 ret
= tps80031_update(parent
, TPS80031_SLAVE_ID1
,
556 MISC2_LDOUSB_IN_MASK
);
559 "LDOUSB config failed, e= %d\n", ret
);
565 case TPS80031_REGULATOR_LDO3
:
566 if (ri
->config_flags
& TPS80031_LDO3_OUTPUT_VIB
) {
567 ret
= tps80031_update(parent
, TPS80031_SLAVE_ID1
,
568 TPS80031_MISC2
, MISC2_LDO3_SEL_VIB_VAL
,
569 MISC2_LDO3_SEL_VIB_MASK
);
572 "LDO3 config failed, e = %d\n", ret
);
578 case TPS80031_REGULATOR_VBUS
:
579 /* Provide SW control Ops if VBUS is SW control */
580 if (!(ri
->config_flags
& TPS80031_VBUS_SW_ONLY
))
581 ri
->rinfo
->desc
.ops
= &tps80031_vbus_sw_ops
;
587 /* Configure Active state to ON, SLEEP to OFF and OFF_state to OFF */
588 ret
= tps80031_update(parent
, TPS80031_SLAVE_ID1
, ri
->rinfo
->trans_reg
,
589 TPS80031_TRANS_ACTIVE_ON
| TPS80031_TRANS_SLEEP_OFF
|
590 TPS80031_TRANS_OFF_OFF
, TPS80031_TRANS_ACTIVE_MASK
|
591 TPS80031_TRANS_SLEEP_MASK
| TPS80031_TRANS_OFF_MASK
);
593 dev_err(ri
->dev
, "trans reg update failed, e %d\n", ret
);
600 static int check_smps_mode_mult(struct device
*parent
,
601 struct tps80031_regulator
*ri
)
608 ret
= tps80031_read(parent
, TPS80031_SLAVE_ID1
,
609 TPS80031_SMPS_OFFSET
, &smps_offset
);
611 dev_err(parent
, "Error in reading smps offset register\n");
615 ret
= tps80031_read(parent
, TPS80031_SLAVE_ID1
,
616 TPS80031_SMPS_MULT
, &smps_mult
);
618 dev_err(parent
, "Error in reading smps mult register\n");
622 switch (ri
->rinfo
->desc
.id
) {
623 case TPS80031_REGULATOR_VIO
:
624 mult_offset
= SMPS_MULTOFFSET_VIO
;
626 case TPS80031_REGULATOR_SMPS1
:
627 mult_offset
= SMPS_MULTOFFSET_SMPS1
;
629 case TPS80031_REGULATOR_SMPS2
:
630 mult_offset
= SMPS_MULTOFFSET_SMPS2
;
632 case TPS80031_REGULATOR_SMPS3
:
633 mult_offset
= SMPS_MULTOFFSET_SMPS3
;
635 case TPS80031_REGULATOR_SMPS4
:
636 mult_offset
= SMPS_MULTOFFSET_SMPS4
;
638 case TPS80031_REGULATOR_LDO2
:
639 ri
->device_flags
= smps_mult
& BIT(5) ? TRACK_MODE_ENABLE
: 0;
640 /* TRACK mode the ldo2 varies from 600mV to 1300mV */
641 if (ri
->device_flags
& TRACK_MODE_ENABLE
) {
642 ri
->rinfo
->desc
.min_uV
= 600000;
643 ri
->rinfo
->desc
.uV_step
= 12500;
644 ri
->rinfo
->desc
.n_voltages
= 57;
645 ri
->rinfo
->desc
.vsel_mask
= LDO_TRACK_VSEL_MASK
;
652 ri
->device_flags
= (smps_offset
& mult_offset
) ? DCDC_OFFSET_EN
: 0;
653 ri
->device_flags
|= (smps_mult
& mult_offset
) ? DCDC_EXTENDED_EN
: 0;
654 switch (ri
->device_flags
) {
656 ri
->rinfo
->desc
.min_uV
= 607700;
657 ri
->rinfo
->desc
.uV_step
= 12660;
660 ri
->rinfo
->desc
.min_uV
= 700000;
661 ri
->rinfo
->desc
.uV_step
= 12500;
663 case DCDC_EXTENDED_EN
:
664 ri
->rinfo
->desc
.min_uV
= 1852000;
665 ri
->rinfo
->desc
.uV_step
= 38600;
667 case DCDC_OFFSET_EN
| DCDC_EXTENDED_EN
:
668 ri
->rinfo
->desc
.min_uV
= 2161000;
669 ri
->rinfo
->desc
.uV_step
= 38600;
675 static int tps80031_regulator_probe(struct platform_device
*pdev
)
677 struct tps80031_platform_data
*pdata
;
678 struct tps80031_regulator_platform_data
*tps_pdata
;
679 struct tps80031_regulator
*ri
;
680 struct tps80031_regulator
*pmic
;
681 struct regulator_dev
*rdev
;
682 struct regulator_config config
= { };
683 struct tps80031
*tps80031_mfd
= dev_get_drvdata(pdev
->dev
.parent
);
687 pdata
= dev_get_platdata(pdev
->dev
.parent
);
690 dev_err(&pdev
->dev
, "No platform data\n");
694 pmic
= devm_kzalloc(&pdev
->dev
,
695 TPS80031_REGULATOR_MAX
* sizeof(*pmic
), GFP_KERNEL
);
699 for (num
= 0; num
< TPS80031_REGULATOR_MAX
; ++num
) {
700 tps_pdata
= pdata
->regulator_pdata
[num
];
702 ri
->rinfo
= &tps80031_rinfo
[num
];
703 ri
->dev
= &pdev
->dev
;
705 check_smps_mode_mult(pdev
->dev
.parent
, ri
);
706 config
.dev
= &pdev
->dev
;
707 config
.init_data
= NULL
;
708 config
.driver_data
= ri
;
709 config
.regmap
= tps80031_mfd
->regmap
[ri
->rinfo
->volt_id
];
712 config
.init_data
= tps_pdata
->reg_init_data
;
713 ri
->config_flags
= tps_pdata
->config_flags
;
714 ri
->ext_ctrl_flag
= tps_pdata
->ext_ctrl_flag
;
715 ret
= tps80031_regulator_config(pdev
->dev
.parent
,
719 "regulator config failed, e %d\n", ret
);
723 ret
= tps80031_power_req_config(pdev
->dev
.parent
,
727 "pwr_req config failed, err %d\n", ret
);
731 rdev
= devm_regulator_register(&pdev
->dev
, &ri
->rinfo
->desc
,
735 "register regulator failed %s\n",
736 ri
->rinfo
->desc
.name
);
737 return PTR_ERR(rdev
);
742 platform_set_drvdata(pdev
, pmic
);
746 static struct platform_driver tps80031_regulator_driver
= {
748 .name
= "tps80031-pmic",
749 .owner
= THIS_MODULE
,
751 .probe
= tps80031_regulator_probe
,
754 static int __init
tps80031_regulator_init(void)
756 return platform_driver_register(&tps80031_regulator_driver
);
758 subsys_initcall(tps80031_regulator_init
);
760 static void __exit
tps80031_regulator_exit(void)
762 platform_driver_unregister(&tps80031_regulator_driver
);
764 module_exit(tps80031_regulator_exit
);
766 MODULE_ALIAS("platform:tps80031-regulator");
767 MODULE_DESCRIPTION("Regulator Driver for TI TPS80031/TPS80032 PMIC");
768 MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
769 MODULE_LICENSE("GPL v2");