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
, DCDC5
, DCDC6
, LDO1
};
32 #define TPS65218_REGULATOR(_name, _id, _ops, _n, _vr, _vm, _er, _em, _t, \
39 .type = REGULATOR_VOLTAGE, \
40 .owner = THIS_MODULE, \
46 .linear_ranges = _lr, \
47 .n_linear_ranges = _nlr, \
48 .ramp_delay = _delay, \
51 #define TPS65218_INFO(_id, _nm, _min, _max) \
59 static const struct regulator_linear_range dcdc1_dcdc2_ranges
[] = {
60 REGULATOR_LINEAR_RANGE(850000, 0x0, 0x32, 10000),
61 REGULATOR_LINEAR_RANGE(1375000, 0x33, 0x3f, 25000),
64 static const struct regulator_linear_range ldo1_dcdc3_ranges
[] = {
65 REGULATOR_LINEAR_RANGE(900000, 0x0, 0x1a, 25000),
66 REGULATOR_LINEAR_RANGE(1600000, 0x1b, 0x3f, 50000),
69 static const struct regulator_linear_range dcdc4_ranges
[] = {
70 REGULATOR_LINEAR_RANGE(1175000, 0x0, 0xf, 25000),
71 REGULATOR_LINEAR_RANGE(1550000, 0x10, 0x34, 50000),
74 static struct tps_info tps65218_pmic_regs
[] = {
75 TPS65218_INFO(0, "DCDC1", 850000, 167500),
76 TPS65218_INFO(1, "DCDC2", 850000, 1675000),
77 TPS65218_INFO(2, "DCDC3", 900000, 3400000),
78 TPS65218_INFO(3, "DCDC4", 1175000, 3400000),
79 TPS65218_INFO(4, "DCDC5", 1000000, 1000000),
80 TPS65218_INFO(5, "DCDC6", 1800000, 1800000),
81 TPS65218_INFO(6, "LDO1", 900000, 3400000),
84 #define TPS65218_OF_MATCH(comp, label) \
90 static const struct of_device_id tps65218_of_match
[] = {
91 TPS65218_OF_MATCH("ti,tps65218-dcdc1", tps65218_pmic_regs
[DCDC1
]),
92 TPS65218_OF_MATCH("ti,tps65218-dcdc2", tps65218_pmic_regs
[DCDC2
]),
93 TPS65218_OF_MATCH("ti,tps65218-dcdc3", tps65218_pmic_regs
[DCDC3
]),
94 TPS65218_OF_MATCH("ti,tps65218-dcdc4", tps65218_pmic_regs
[DCDC4
]),
95 TPS65218_OF_MATCH("ti,tps65218-dcdc5", tps65218_pmic_regs
[DCDC5
]),
96 TPS65218_OF_MATCH("ti,tps65218-dcdc6", tps65218_pmic_regs
[DCDC6
]),
97 TPS65218_OF_MATCH("ti,tps65218-ldo1", tps65218_pmic_regs
[LDO1
]),
100 MODULE_DEVICE_TABLE(of
, tps65218_of_match
);
102 static int tps65218_pmic_set_voltage_sel(struct regulator_dev
*dev
,
106 struct tps65218
*tps
= rdev_get_drvdata(dev
);
107 unsigned int rid
= rdev_get_id(dev
);
109 /* Set the voltage based on vsel value and write protect level is 2 */
110 ret
= tps65218_set_bits(tps
, dev
->desc
->vsel_reg
, dev
->desc
->vsel_mask
,
111 selector
, TPS65218_PROTECT_L1
);
113 /* Set GO bit for DCDC1/2 to initiate voltage transistion */
115 case TPS65218_DCDC_1
:
116 case TPS65218_DCDC_2
:
117 ret
= tps65218_set_bits(tps
, TPS65218_REG_CONTRL_SLEW_RATE
,
118 TPS65218_SLEW_RATE_GO
,
119 TPS65218_SLEW_RATE_GO
,
120 TPS65218_PROTECT_L1
);
127 static int tps65218_pmic_enable(struct regulator_dev
*dev
)
129 struct tps65218
*tps
= rdev_get_drvdata(dev
);
130 unsigned int rid
= rdev_get_id(dev
);
132 if (rid
< TPS65218_DCDC_1
|| rid
> TPS65218_LDO_1
)
135 /* Enable the regulator and password protection is level 1 */
136 return tps65218_set_bits(tps
, dev
->desc
->enable_reg
,
137 dev
->desc
->enable_mask
, dev
->desc
->enable_mask
,
138 TPS65218_PROTECT_L1
);
141 static int tps65218_pmic_disable(struct regulator_dev
*dev
)
143 struct tps65218
*tps
= rdev_get_drvdata(dev
);
144 unsigned int rid
= rdev_get_id(dev
);
146 if (rid
< TPS65218_DCDC_1
|| rid
> TPS65218_LDO_1
)
149 /* Disable the regulator and password protection is level 1 */
150 return tps65218_clear_bits(tps
, dev
->desc
->enable_reg
,
151 dev
->desc
->enable_mask
, TPS65218_PROTECT_L1
);
154 /* Operations permitted on DCDC1, DCDC2 */
155 static struct regulator_ops tps65218_dcdc12_ops
= {
156 .is_enabled
= regulator_is_enabled_regmap
,
157 .enable
= tps65218_pmic_enable
,
158 .disable
= tps65218_pmic_disable
,
159 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
160 .set_voltage_sel
= tps65218_pmic_set_voltage_sel
,
161 .list_voltage
= regulator_list_voltage_linear_range
,
162 .map_voltage
= regulator_map_voltage_linear_range
,
163 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
166 /* Operations permitted on DCDC3, DCDC4 and LDO1 */
167 static struct regulator_ops tps65218_ldo1_dcdc34_ops
= {
168 .is_enabled
= regulator_is_enabled_regmap
,
169 .enable
= tps65218_pmic_enable
,
170 .disable
= tps65218_pmic_disable
,
171 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
172 .set_voltage_sel
= tps65218_pmic_set_voltage_sel
,
173 .list_voltage
= regulator_list_voltage_linear_range
,
174 .map_voltage
= regulator_map_voltage_linear_range
,
177 /* Operations permitted on DCDC5, DCDC6 */
178 static struct regulator_ops tps65218_dcdc56_pmic_ops
= {
179 .is_enabled
= regulator_is_enabled_regmap
,
180 .enable
= tps65218_pmic_enable
,
181 .disable
= tps65218_pmic_disable
,
184 static const struct regulator_desc regulators
[] = {
185 TPS65218_REGULATOR("DCDC1", TPS65218_DCDC_1
, tps65218_dcdc12_ops
, 64,
186 TPS65218_REG_CONTROL_DCDC1
,
187 TPS65218_CONTROL_DCDC1_MASK
,
188 TPS65218_REG_ENABLE1
, TPS65218_ENABLE1_DC1_EN
, NULL
,
189 dcdc1_dcdc2_ranges
, 2, 4000),
190 TPS65218_REGULATOR("DCDC2", TPS65218_DCDC_2
, tps65218_dcdc12_ops
, 64,
191 TPS65218_REG_CONTROL_DCDC2
,
192 TPS65218_CONTROL_DCDC2_MASK
,
193 TPS65218_REG_ENABLE1
, TPS65218_ENABLE1_DC2_EN
, NULL
,
194 dcdc1_dcdc2_ranges
, 2, 4000),
195 TPS65218_REGULATOR("DCDC3", TPS65218_DCDC_3
, tps65218_ldo1_dcdc34_ops
,
196 64, TPS65218_REG_CONTROL_DCDC3
,
197 TPS65218_CONTROL_DCDC3_MASK
, TPS65218_REG_ENABLE1
,
198 TPS65218_ENABLE1_DC3_EN
, NULL
,
199 ldo1_dcdc3_ranges
, 2, 0),
200 TPS65218_REGULATOR("DCDC4", TPS65218_DCDC_4
, tps65218_ldo1_dcdc34_ops
,
201 53, TPS65218_REG_CONTROL_DCDC4
,
202 TPS65218_CONTROL_DCDC4_MASK
,
203 TPS65218_REG_ENABLE1
, TPS65218_ENABLE1_DC4_EN
, NULL
,
205 TPS65218_REGULATOR("DCDC5", TPS65218_DCDC_5
, tps65218_dcdc56_pmic_ops
,
206 1, -1, -1, TPS65218_REG_ENABLE1
,
207 TPS65218_ENABLE1_DC5_EN
, NULL
, NULL
, 0, 0),
208 TPS65218_REGULATOR("DCDC6", TPS65218_DCDC_6
, tps65218_dcdc56_pmic_ops
,
209 1, -1, -1, TPS65218_REG_ENABLE1
,
210 TPS65218_ENABLE1_DC6_EN
, NULL
, NULL
, 0, 0),
211 TPS65218_REGULATOR("LDO1", TPS65218_LDO_1
, tps65218_ldo1_dcdc34_ops
, 64,
212 TPS65218_REG_CONTROL_DCDC4
,
213 TPS65218_CONTROL_LDO1_MASK
, TPS65218_REG_ENABLE2
,
214 TPS65218_ENABLE2_LDO1_EN
, NULL
, ldo1_dcdc3_ranges
,
218 static int tps65218_regulator_probe(struct platform_device
*pdev
)
220 struct tps65218
*tps
= dev_get_drvdata(pdev
->dev
.parent
);
221 struct regulator_init_data
*init_data
;
222 const struct tps_info
*template;
223 struct regulator_dev
*rdev
;
224 const struct of_device_id
*match
;
225 struct regulator_config config
= { };
228 match
= of_match_device(tps65218_of_match
, &pdev
->dev
);
232 template = match
->data
;
234 init_data
= of_get_regulator_init_data(&pdev
->dev
, pdev
->dev
.of_node
);
236 platform_set_drvdata(pdev
, tps
);
238 tps
->info
[id
] = &tps65218_pmic_regs
[id
];
239 config
.dev
= &pdev
->dev
;
240 config
.init_data
= init_data
;
241 config
.driver_data
= tps
;
242 config
.regmap
= tps
->regmap
;
244 rdev
= devm_regulator_register(&pdev
->dev
, ®ulators
[id
], &config
);
246 dev_err(tps
->dev
, "failed to register %s regulator\n",
248 return PTR_ERR(rdev
);
254 static struct platform_driver tps65218_regulator_driver
= {
256 .name
= "tps65218-pmic",
257 .owner
= THIS_MODULE
,
258 .of_match_table
= tps65218_of_match
,
260 .probe
= tps65218_regulator_probe
,
263 module_platform_driver(tps65218_regulator_driver
);
265 MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
266 MODULE_DESCRIPTION("TPS65218 voltage regulator driver");
267 MODULE_ALIAS("platform:tps65218-pmic");
268 MODULE_LICENSE("GPL v2");