4 * Regulator driver for TPS65218 PMIC
6 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
13 * kind, whether expressed or implied; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License version 2 for more details.
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/device.h>
21 #include <linux/init.h>
22 #include <linux/err.h>
23 #include <linux/platform_device.h>
24 #include <linux/of_device.h>
25 #include <linux/regulator/of_regulator.h>
26 #include <linux/regulator/driver.h>
27 #include <linux/regulator/machine.h>
28 #include <linux/mfd/tps65218.h>
30 enum tps65218_regulators
{ DCDC1
, DCDC2
, DCDC3
, DCDC4
,
31 DCDC5
, DCDC6
, LDO1
, LS3
};
33 #define TPS65218_REGULATOR(_name, _id, _type, _ops, _n, _vr, _vm, _er, _em, \
34 _cr, _cm, _lr, _nlr, _delay, _fuv, _sr, _sm) \
41 .owner = THIS_MODULE, \
49 .linear_ranges = _lr, \
50 .n_linear_ranges = _nlr, \
51 .ramp_delay = _delay, \
57 #define TPS65218_INFO(_id, _nm, _min, _max) \
65 static const struct regulator_linear_range dcdc1_dcdc2_ranges
[] = {
66 REGULATOR_LINEAR_RANGE(850000, 0x0, 0x32, 10000),
67 REGULATOR_LINEAR_RANGE(1375000, 0x33, 0x3f, 25000),
70 static const struct regulator_linear_range ldo1_dcdc3_ranges
[] = {
71 REGULATOR_LINEAR_RANGE(900000, 0x0, 0x1a, 25000),
72 REGULATOR_LINEAR_RANGE(1600000, 0x1b, 0x3f, 50000),
75 static const struct regulator_linear_range dcdc4_ranges
[] = {
76 REGULATOR_LINEAR_RANGE(1175000, 0x0, 0xf, 25000),
77 REGULATOR_LINEAR_RANGE(1600000, 0x10, 0x34, 50000),
80 static struct tps_info tps65218_pmic_regs
[] = {
81 TPS65218_INFO(DCDC1
, "DCDC1", 850000, 1675000),
82 TPS65218_INFO(DCDC2
, "DCDC2", 850000, 1675000),
83 TPS65218_INFO(DCDC3
, "DCDC3", 900000, 3400000),
84 TPS65218_INFO(DCDC4
, "DCDC4", 1175000, 3400000),
85 TPS65218_INFO(DCDC5
, "DCDC5", 1000000, 1000000),
86 TPS65218_INFO(DCDC6
, "DCDC6", 1800000, 1800000),
87 TPS65218_INFO(LDO1
, "LDO1", 900000, 3400000),
88 TPS65218_INFO(LS3
, "LS3", -1, -1),
91 #define TPS65218_OF_MATCH(comp, label) \
97 static const struct of_device_id tps65218_of_match
[] = {
98 TPS65218_OF_MATCH("ti,tps65218-dcdc1", tps65218_pmic_regs
[DCDC1
]),
99 TPS65218_OF_MATCH("ti,tps65218-dcdc2", tps65218_pmic_regs
[DCDC2
]),
100 TPS65218_OF_MATCH("ti,tps65218-dcdc3", tps65218_pmic_regs
[DCDC3
]),
101 TPS65218_OF_MATCH("ti,tps65218-dcdc4", tps65218_pmic_regs
[DCDC4
]),
102 TPS65218_OF_MATCH("ti,tps65218-dcdc5", tps65218_pmic_regs
[DCDC5
]),
103 TPS65218_OF_MATCH("ti,tps65218-dcdc6", tps65218_pmic_regs
[DCDC6
]),
104 TPS65218_OF_MATCH("ti,tps65218-ldo1", tps65218_pmic_regs
[LDO1
]),
105 TPS65218_OF_MATCH("ti,tps65218-ls3", tps65218_pmic_regs
[LS3
]),
108 MODULE_DEVICE_TABLE(of
, tps65218_of_match
);
110 static int tps65218_pmic_set_voltage_sel(struct regulator_dev
*dev
,
114 struct tps65218
*tps
= rdev_get_drvdata(dev
);
115 unsigned int rid
= rdev_get_id(dev
);
117 /* Set the voltage based on vsel value and write protect level is 2 */
118 ret
= tps65218_set_bits(tps
, dev
->desc
->vsel_reg
, dev
->desc
->vsel_mask
,
119 selector
, TPS65218_PROTECT_L1
);
121 /* Set GO bit for DCDC1/2 to initiate voltage transistion */
123 case TPS65218_DCDC_1
:
124 case TPS65218_DCDC_2
:
125 ret
= tps65218_set_bits(tps
, TPS65218_REG_CONTRL_SLEW_RATE
,
126 TPS65218_SLEW_RATE_GO
,
127 TPS65218_SLEW_RATE_GO
,
128 TPS65218_PROTECT_L1
);
135 static int tps65218_pmic_enable(struct regulator_dev
*dev
)
137 struct tps65218
*tps
= rdev_get_drvdata(dev
);
138 int rid
= rdev_get_id(dev
);
140 if (rid
< TPS65218_DCDC_1
|| rid
> TPS65218_LDO_1
)
143 /* Enable the regulator and password protection is level 1 */
144 return tps65218_set_bits(tps
, dev
->desc
->enable_reg
,
145 dev
->desc
->enable_mask
, dev
->desc
->enable_mask
,
146 TPS65218_PROTECT_L1
);
149 static int tps65218_pmic_disable(struct regulator_dev
*dev
)
151 struct tps65218
*tps
= rdev_get_drvdata(dev
);
152 int rid
= rdev_get_id(dev
);
154 if (rid
< TPS65218_DCDC_1
|| rid
> TPS65218_LDO_1
)
157 /* Disable the regulator and password protection is level 1 */
158 return tps65218_clear_bits(tps
, dev
->desc
->enable_reg
,
159 dev
->desc
->enable_mask
, TPS65218_PROTECT_L1
);
162 static int tps65218_pmic_set_suspend_enable(struct regulator_dev
*dev
)
164 struct tps65218
*tps
= rdev_get_drvdata(dev
);
165 unsigned int rid
= rdev_get_id(dev
);
167 if (rid
< TPS65218_DCDC_1
|| rid
> TPS65218_LDO_1
)
170 return tps65218_clear_bits(tps
, dev
->desc
->bypass_reg
,
171 dev
->desc
->bypass_mask
,
172 TPS65218_PROTECT_L1
);
175 static int tps65218_pmic_set_suspend_disable(struct regulator_dev
*dev
)
177 struct tps65218
*tps
= rdev_get_drvdata(dev
);
178 unsigned int rid
= rdev_get_id(dev
);
180 if (rid
< TPS65218_DCDC_1
|| rid
> TPS65218_LDO_1
)
183 if (!tps
->info
[rid
]->strobe
) {
184 if (rid
== TPS65218_DCDC_3
)
185 tps
->info
[rid
]->strobe
= 3;
190 return tps65218_set_bits(tps
, dev
->desc
->bypass_reg
,
191 dev
->desc
->bypass_mask
,
192 tps
->info
[rid
]->strobe
,
193 TPS65218_PROTECT_L1
);
196 /* Operations permitted on DCDC1, DCDC2 */
197 static struct regulator_ops tps65218_dcdc12_ops
= {
198 .is_enabled
= regulator_is_enabled_regmap
,
199 .enable
= tps65218_pmic_enable
,
200 .disable
= tps65218_pmic_disable
,
201 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
202 .set_voltage_sel
= tps65218_pmic_set_voltage_sel
,
203 .list_voltage
= regulator_list_voltage_linear_range
,
204 .map_voltage
= regulator_map_voltage_linear_range
,
205 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
206 .set_suspend_enable
= tps65218_pmic_set_suspend_enable
,
207 .set_suspend_disable
= tps65218_pmic_set_suspend_disable
,
210 /* Operations permitted on DCDC3, DCDC4 and LDO1 */
211 static struct regulator_ops tps65218_ldo1_dcdc34_ops
= {
212 .is_enabled
= regulator_is_enabled_regmap
,
213 .enable
= tps65218_pmic_enable
,
214 .disable
= tps65218_pmic_disable
,
215 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
216 .set_voltage_sel
= tps65218_pmic_set_voltage_sel
,
217 .list_voltage
= regulator_list_voltage_linear_range
,
218 .map_voltage
= regulator_map_voltage_linear_range
,
219 .set_suspend_enable
= tps65218_pmic_set_suspend_enable
,
220 .set_suspend_disable
= tps65218_pmic_set_suspend_disable
,
223 static const int ls3_currents
[] = { 100, 200, 500, 1000 };
225 static int tps65218_pmic_set_input_current_lim(struct regulator_dev
*dev
,
228 unsigned int index
= 0;
229 unsigned int num_currents
= ARRAY_SIZE(ls3_currents
);
230 struct tps65218
*tps
= rdev_get_drvdata(dev
);
232 while (index
< num_currents
&& ls3_currents
[index
] != lim_uA
)
235 if (index
== num_currents
)
238 return tps65218_set_bits(tps
, dev
->desc
->csel_reg
, dev
->desc
->csel_mask
,
239 index
<< 2, TPS65218_PROTECT_L1
);
242 static int tps65218_pmic_set_current_limit(struct regulator_dev
*dev
,
243 int min_uA
, int max_uA
)
246 unsigned int num_currents
= ARRAY_SIZE(ls3_currents
);
247 struct tps65218
*tps
= rdev_get_drvdata(dev
);
249 while (index
< num_currents
&& ls3_currents
[index
] < max_uA
)
254 if (index
< 0 || ls3_currents
[index
] < min_uA
)
257 return tps65218_set_bits(tps
, dev
->desc
->csel_reg
, dev
->desc
->csel_mask
,
258 index
<< 2, TPS65218_PROTECT_L1
);
261 static int tps65218_pmic_get_current_limit(struct regulator_dev
*dev
)
265 struct tps65218
*tps
= rdev_get_drvdata(dev
);
267 retval
= tps65218_reg_read(tps
, dev
->desc
->csel_reg
, &index
);
271 index
= (index
& dev
->desc
->csel_mask
) >> 2;
273 return ls3_currents
[index
];
276 static struct regulator_ops tps65218_ls3_ops
= {
277 .is_enabled
= regulator_is_enabled_regmap
,
278 .enable
= tps65218_pmic_enable
,
279 .disable
= tps65218_pmic_disable
,
280 .set_input_current_limit
= tps65218_pmic_set_input_current_lim
,
281 .set_current_limit
= tps65218_pmic_set_current_limit
,
282 .get_current_limit
= tps65218_pmic_get_current_limit
,
285 /* Operations permitted on DCDC5, DCDC6 */
286 static struct regulator_ops tps65218_dcdc56_pmic_ops
= {
287 .is_enabled
= regulator_is_enabled_regmap
,
288 .enable
= tps65218_pmic_enable
,
289 .disable
= tps65218_pmic_disable
,
290 .set_suspend_enable
= tps65218_pmic_set_suspend_enable
,
291 .set_suspend_disable
= tps65218_pmic_set_suspend_disable
,
294 static const struct regulator_desc regulators
[] = {
295 TPS65218_REGULATOR("DCDC1", TPS65218_DCDC_1
, REGULATOR_VOLTAGE
,
296 tps65218_dcdc12_ops
, 64, TPS65218_REG_CONTROL_DCDC1
,
297 TPS65218_CONTROL_DCDC1_MASK
, TPS65218_REG_ENABLE1
,
298 TPS65218_ENABLE1_DC1_EN
, 0, 0, dcdc1_dcdc2_ranges
,
299 2, 4000, 0, TPS65218_REG_SEQ3
,
300 TPS65218_SEQ3_DC1_SEQ_MASK
),
301 TPS65218_REGULATOR("DCDC2", TPS65218_DCDC_2
, REGULATOR_VOLTAGE
,
302 tps65218_dcdc12_ops
, 64, TPS65218_REG_CONTROL_DCDC2
,
303 TPS65218_CONTROL_DCDC2_MASK
, TPS65218_REG_ENABLE1
,
304 TPS65218_ENABLE1_DC2_EN
, 0, 0, dcdc1_dcdc2_ranges
,
305 2, 4000, 0, TPS65218_REG_SEQ3
,
306 TPS65218_SEQ3_DC2_SEQ_MASK
),
307 TPS65218_REGULATOR("DCDC3", TPS65218_DCDC_3
, REGULATOR_VOLTAGE
,
308 tps65218_ldo1_dcdc34_ops
, 64,
309 TPS65218_REG_CONTROL_DCDC3
,
310 TPS65218_CONTROL_DCDC3_MASK
, TPS65218_REG_ENABLE1
,
311 TPS65218_ENABLE1_DC3_EN
, 0, 0, ldo1_dcdc3_ranges
, 2,
312 0, 0, TPS65218_REG_SEQ4
, TPS65218_SEQ4_DC3_SEQ_MASK
),
313 TPS65218_REGULATOR("DCDC4", TPS65218_DCDC_4
, REGULATOR_VOLTAGE
,
314 tps65218_ldo1_dcdc34_ops
, 53,
315 TPS65218_REG_CONTROL_DCDC4
,
316 TPS65218_CONTROL_DCDC4_MASK
, TPS65218_REG_ENABLE1
,
317 TPS65218_ENABLE1_DC4_EN
, 0, 0, dcdc4_ranges
, 2,
318 0, 0, TPS65218_REG_SEQ4
, TPS65218_SEQ4_DC4_SEQ_MASK
),
319 TPS65218_REGULATOR("DCDC5", TPS65218_DCDC_5
, REGULATOR_VOLTAGE
,
320 tps65218_dcdc56_pmic_ops
, 1, -1, -1,
321 TPS65218_REG_ENABLE1
, TPS65218_ENABLE1_DC5_EN
, 0, 0,
322 NULL
, 0, 0, 1000000, TPS65218_REG_SEQ5
,
323 TPS65218_SEQ5_DC5_SEQ_MASK
),
324 TPS65218_REGULATOR("DCDC6", TPS65218_DCDC_6
, REGULATOR_VOLTAGE
,
325 tps65218_dcdc56_pmic_ops
, 1, -1, -1,
326 TPS65218_REG_ENABLE1
, TPS65218_ENABLE1_DC6_EN
, 0, 0,
327 NULL
, 0, 0, 1800000, TPS65218_REG_SEQ5
,
328 TPS65218_SEQ5_DC6_SEQ_MASK
),
329 TPS65218_REGULATOR("LDO1", TPS65218_LDO_1
, REGULATOR_VOLTAGE
,
330 tps65218_ldo1_dcdc34_ops
, 64,
331 TPS65218_REG_CONTROL_LDO1
,
332 TPS65218_CONTROL_LDO1_MASK
, TPS65218_REG_ENABLE2
,
333 TPS65218_ENABLE2_LDO1_EN
, 0, 0, ldo1_dcdc3_ranges
,
334 2, 0, 0, TPS65218_REG_SEQ6
,
335 TPS65218_SEQ6_LDO1_SEQ_MASK
),
336 TPS65218_REGULATOR("LS3", TPS65218_LS_3
, REGULATOR_CURRENT
,
337 tps65218_ls3_ops
, 0, 0, 0, TPS65218_REG_ENABLE2
,
338 TPS65218_ENABLE2_LS3_EN
, TPS65218_REG_CONFIG2
,
339 TPS65218_CONFIG2_LS3ILIM_MASK
, NULL
, 0, 0, 0, 0, 0),
342 static int tps65218_regulator_probe(struct platform_device
*pdev
)
344 struct tps65218
*tps
= dev_get_drvdata(pdev
->dev
.parent
);
345 struct regulator_init_data
*init_data
;
346 const struct tps_info
*template;
347 struct regulator_dev
*rdev
;
348 const struct of_device_id
*match
;
349 struct regulator_config config
= { };
353 match
= of_match_device(tps65218_of_match
, &pdev
->dev
);
357 template = match
->data
;
359 init_data
= of_get_regulator_init_data(&pdev
->dev
, pdev
->dev
.of_node
,
362 platform_set_drvdata(pdev
, tps
);
364 tps
->info
[id
] = &tps65218_pmic_regs
[id
];
365 config
.dev
= &pdev
->dev
;
366 config
.init_data
= init_data
;
367 config
.driver_data
= tps
;
368 config
.regmap
= tps
->regmap
;
369 config
.of_node
= pdev
->dev
.of_node
;
371 rdev
= devm_regulator_register(&pdev
->dev
, ®ulators
[id
], &config
);
373 dev_err(tps
->dev
, "failed to register %s regulator\n",
375 return PTR_ERR(rdev
);
378 ret
= tps65218_reg_read(tps
, regulators
[id
].bypass_reg
, &val
);
382 tps
->info
[id
]->strobe
= val
& regulators
[id
].bypass_mask
;
387 static struct platform_driver tps65218_regulator_driver
= {
389 .name
= "tps65218-pmic",
390 .of_match_table
= tps65218_of_match
,
392 .probe
= tps65218_regulator_probe
,
395 module_platform_driver(tps65218_regulator_driver
);
397 MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
398 MODULE_DESCRIPTION("TPS65218 voltage regulator driver");
399 MODULE_ALIAS("platform:tps65218-pmic");
400 MODULE_LICENSE("GPL v2");