Blame view
drivers/regulator/tps65218-regulator.c
11.9 KB
90e7d5262 regulator: tps652... |
1 2 3 4 5 |
/* * tps65218-regulator.c * * Regulator driver for TPS65218 PMIC * |
2ca76b3e4 regulator: Replac... |
6 |
* Copyright (C) 2014 Texas Instruments Incorporated - https://www.ti.com/ |
90e7d5262 regulator: tps652... |
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
* * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed "as is" WITHOUT ANY WARRANTY of any * kind, whether expressed or implied; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License version 2 for more details. */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/device.h> #include <linux/init.h> #include <linux/err.h> #include <linux/platform_device.h> #include <linux/of_device.h> |
0aced3557 mfd: tps65218: Re... |
25 |
#include <linux/regmap.h> |
90e7d5262 regulator: tps652... |
26 27 28 29 |
#include <linux/regulator/of_regulator.h> #include <linux/regulator/driver.h> #include <linux/regulator/machine.h> #include <linux/mfd/tps65218.h> |
2dc494036 regulator: tps652... |
30 |
#define TPS65218_REGULATOR(_name, _of, _id, _type, _ops, _n, _vr, _vm, _er, \ |
7cfcecfb8 regulator: tps652... |
31 32 |
_em, _cr, _cm, _lr, _nlr, _delay, _fuv, _sr, _sm, \ _ct, _ncl) \ |
90e7d5262 regulator: tps652... |
33 34 |
{ \ .name = _name, \ |
2dc494036 regulator: tps652... |
35 |
.of_match = _of, \ |
90e7d5262 regulator: tps652... |
36 37 38 |
.id = _id, \ .ops = &_ops, \ .n_voltages = _n, \ |
c0ea88b89 regulator: tps652... |
39 |
.type = _type, \ |
90e7d5262 regulator: tps652... |
40 41 42 |
.owner = THIS_MODULE, \ .vsel_reg = _vr, \ .vsel_mask = _vm, \ |
c0ea88b89 regulator: tps652... |
43 44 |
.csel_reg = _cr, \ .csel_mask = _cm, \ |
7cfcecfb8 regulator: tps652... |
45 46 |
.curr_table = _ct, \ .n_current_limits = _ncl, \ |
90e7d5262 regulator: tps652... |
47 48 |
.enable_reg = _er, \ .enable_mask = _em, \ |
dd648ef24 regulator: tps652... |
49 |
.volt_table = NULL, \ |
90e7d5262 regulator: tps652... |
50 51 |
.linear_ranges = _lr, \ .n_linear_ranges = _nlr, \ |
5ab9be427 regulator: tps652... |
52 |
.ramp_delay = _delay, \ |
b9a0d3594 regulator: tps652... |
53 54 55 |
.fixed_uV = _fuv, \ .bypass_reg = _sr, \ .bypass_mask = _sm, \ |
90e7d5262 regulator: tps652... |
56 |
} \ |
60ab7f415 regulator: use li... |
57 |
static const struct linear_range dcdc1_dcdc2_ranges[] = { |
90e7d5262 regulator: tps652... |
58 59 60 |
REGULATOR_LINEAR_RANGE(850000, 0x0, 0x32, 10000), REGULATOR_LINEAR_RANGE(1375000, 0x33, 0x3f, 25000), }; |
60ab7f415 regulator: use li... |
61 |
static const struct linear_range ldo1_dcdc3_ranges[] = { |
90e7d5262 regulator: tps652... |
62 63 64 |
REGULATOR_LINEAR_RANGE(900000, 0x0, 0x1a, 25000), REGULATOR_LINEAR_RANGE(1600000, 0x1b, 0x3f, 50000), }; |
60ab7f415 regulator: use li... |
65 |
static const struct linear_range dcdc4_ranges[] = { |
90e7d5262 regulator: tps652... |
66 |
REGULATOR_LINEAR_RANGE(1175000, 0x0, 0xf, 25000), |
42ab0f391 regulator: tps652... |
67 |
REGULATOR_LINEAR_RANGE(1600000, 0x10, 0x34, 50000), |
90e7d5262 regulator: tps652... |
68 |
}; |
90e7d5262 regulator: tps652... |
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
static int tps65218_pmic_set_voltage_sel(struct regulator_dev *dev, unsigned selector) { int ret; struct tps65218 *tps = rdev_get_drvdata(dev); unsigned int rid = rdev_get_id(dev); /* Set the voltage based on vsel value and write protect level is 2 */ ret = tps65218_set_bits(tps, dev->desc->vsel_reg, dev->desc->vsel_mask, selector, TPS65218_PROTECT_L1); /* Set GO bit for DCDC1/2 to initiate voltage transistion */ switch (rid) { case TPS65218_DCDC_1: case TPS65218_DCDC_2: ret = tps65218_set_bits(tps, TPS65218_REG_CONTRL_SLEW_RATE, TPS65218_SLEW_RATE_GO, TPS65218_SLEW_RATE_GO, TPS65218_PROTECT_L1); break; } return ret; } static int tps65218_pmic_enable(struct regulator_dev *dev) { struct tps65218 *tps = rdev_get_drvdata(dev); |
5f986f7c2 regulator: tps652... |
97 |
int rid = rdev_get_id(dev); |
90e7d5262 regulator: tps652... |
98 99 100 101 102 103 104 105 106 107 108 109 110 |
if (rid < TPS65218_DCDC_1 || rid > TPS65218_LDO_1) return -EINVAL; /* Enable the regulator and password protection is level 1 */ return tps65218_set_bits(tps, dev->desc->enable_reg, dev->desc->enable_mask, dev->desc->enable_mask, TPS65218_PROTECT_L1); } static int tps65218_pmic_disable(struct regulator_dev *dev) { struct tps65218 *tps = rdev_get_drvdata(dev); |
5f986f7c2 regulator: tps652... |
111 |
int rid = rdev_get_id(dev); |
90e7d5262 regulator: tps652... |
112 113 114 115 116 117 118 119 |
if (rid < TPS65218_DCDC_1 || rid > TPS65218_LDO_1) return -EINVAL; /* Disable the regulator and password protection is level 1 */ return tps65218_clear_bits(tps, dev->desc->enable_reg, dev->desc->enable_mask, TPS65218_PROTECT_L1); } |
b9a0d3594 regulator: tps652... |
120 121 122 123 |
static int tps65218_pmic_set_suspend_enable(struct regulator_dev *dev) { struct tps65218 *tps = rdev_get_drvdata(dev); unsigned int rid = rdev_get_id(dev); |
02d888631 regulator: tps652... |
124 |
if (rid > TPS65218_LDO_1) |
b9a0d3594 regulator: tps652... |
125 126 127 128 129 130 131 132 133 134 135 |
return -EINVAL; return tps65218_clear_bits(tps, dev->desc->bypass_reg, dev->desc->bypass_mask, TPS65218_PROTECT_L1); } static int tps65218_pmic_set_suspend_disable(struct regulator_dev *dev) { struct tps65218 *tps = rdev_get_drvdata(dev); unsigned int rid = rdev_get_id(dev); |
02d888631 regulator: tps652... |
136 |
if (rid > TPS65218_LDO_1) |
b9a0d3594 regulator: tps652... |
137 |
return -EINVAL; |
23a34f9d0 regulator: tps652... |
138 139 140 141 142 143 144 |
/* * Certain revisions of TPS65218 will need to have DCDC3 regulator * enabled always, otherwise an immediate system reboot will occur * during poweroff. */ if (rid == TPS65218_DCDC_3 && tps->rev == TPS65218_REV_2_1) return 0; |
2dc494036 regulator: tps652... |
145 |
if (!tps->strobes[rid]) { |
3fb2ef111 regulator: tps652... |
146 |
if (rid == TPS65218_DCDC_3) |
efeb88c68 regulator: tps652... |
147 |
tps->strobes[rid] = 3; |
3fb2ef111 regulator: tps652... |
148 149 150 |
else return -EINVAL; } |
b9a0d3594 regulator: tps652... |
151 152 153 |
return tps65218_set_bits(tps, dev->desc->bypass_reg, dev->desc->bypass_mask, |
2dc494036 regulator: tps652... |
154 |
tps->strobes[rid], TPS65218_PROTECT_L1); |
b9a0d3594 regulator: tps652... |
155 |
} |
90e7d5262 regulator: tps652... |
156 |
/* Operations permitted on DCDC1, DCDC2 */ |
d1030b439 regulator: tps652... |
157 |
static const struct regulator_ops tps65218_dcdc12_ops = { |
90e7d5262 regulator: tps652... |
158 159 160 161 162 163 164 |
.is_enabled = regulator_is_enabled_regmap, .enable = tps65218_pmic_enable, .disable = tps65218_pmic_disable, .get_voltage_sel = regulator_get_voltage_sel_regmap, .set_voltage_sel = tps65218_pmic_set_voltage_sel, .list_voltage = regulator_list_voltage_linear_range, .map_voltage = regulator_map_voltage_linear_range, |
5ab9be427 regulator: tps652... |
165 |
.set_voltage_time_sel = regulator_set_voltage_time_sel, |
b9a0d3594 regulator: tps652... |
166 167 |
.set_suspend_enable = tps65218_pmic_set_suspend_enable, .set_suspend_disable = tps65218_pmic_set_suspend_disable, |
90e7d5262 regulator: tps652... |
168 169 170 |
}; /* Operations permitted on DCDC3, DCDC4 and LDO1 */ |
d1030b439 regulator: tps652... |
171 |
static const struct regulator_ops tps65218_ldo1_dcdc34_ops = { |
90e7d5262 regulator: tps652... |
172 173 174 175 176 177 178 |
.is_enabled = regulator_is_enabled_regmap, .enable = tps65218_pmic_enable, .disable = tps65218_pmic_disable, .get_voltage_sel = regulator_get_voltage_sel_regmap, .set_voltage_sel = tps65218_pmic_set_voltage_sel, .list_voltage = regulator_list_voltage_linear_range, .map_voltage = regulator_map_voltage_linear_range, |
b9a0d3594 regulator: tps652... |
179 180 |
.set_suspend_enable = tps65218_pmic_set_suspend_enable, .set_suspend_disable = tps65218_pmic_set_suspend_disable, |
90e7d5262 regulator: tps652... |
181 |
}; |
7cfcecfb8 regulator: tps652... |
182 |
static const unsigned int ls3_currents[] = { 100000, 200000, 500000, 1000000 }; |
c0ea88b89 regulator: tps652... |
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
static int tps65218_pmic_set_input_current_lim(struct regulator_dev *dev, int lim_uA) { unsigned int index = 0; unsigned int num_currents = ARRAY_SIZE(ls3_currents); struct tps65218 *tps = rdev_get_drvdata(dev); while (index < num_currents && ls3_currents[index] != lim_uA) index++; if (index == num_currents) return -EINVAL; return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask, |
e5c8ba063 regulator: tps652... |
198 199 |
index << __builtin_ctz(dev->desc->csel_mask), TPS65218_PROTECT_L1); |
c0ea88b89 regulator: tps652... |
200 201 202 203 204 205 206 207 |
} static int tps65218_pmic_set_current_limit(struct regulator_dev *dev, int min_uA, int max_uA) { int index = 0; unsigned int num_currents = ARRAY_SIZE(ls3_currents); struct tps65218 *tps = rdev_get_drvdata(dev); |
71a64ba20 regulator: tps652... |
208 |
while (index < num_currents && ls3_currents[index] <= max_uA) |
c0ea88b89 regulator: tps652... |
209 210 211 212 213 214 215 216 |
index++; index--; if (index < 0 || ls3_currents[index] < min_uA) return -EINVAL; return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask, |
e5c8ba063 regulator: tps652... |
217 218 |
index << __builtin_ctz(dev->desc->csel_mask), TPS65218_PROTECT_L1); |
c0ea88b89 regulator: tps652... |
219 |
} |
d1030b439 regulator: tps652... |
220 |
static const struct regulator_ops tps65218_ls23_ops = { |
c0ea88b89 regulator: tps652... |
221 222 223 224 225 |
.is_enabled = regulator_is_enabled_regmap, .enable = tps65218_pmic_enable, .disable = tps65218_pmic_disable, .set_input_current_limit = tps65218_pmic_set_input_current_lim, .set_current_limit = tps65218_pmic_set_current_limit, |
7cfcecfb8 regulator: tps652... |
226 |
.get_current_limit = regulator_get_current_limit_regmap, |
c0ea88b89 regulator: tps652... |
227 |
}; |
90e7d5262 regulator: tps652... |
228 |
/* Operations permitted on DCDC5, DCDC6 */ |
d1030b439 regulator: tps652... |
229 |
static const struct regulator_ops tps65218_dcdc56_pmic_ops = { |
90e7d5262 regulator: tps652... |
230 231 232 |
.is_enabled = regulator_is_enabled_regmap, .enable = tps65218_pmic_enable, .disable = tps65218_pmic_disable, |
b9a0d3594 regulator: tps652... |
233 234 |
.set_suspend_enable = tps65218_pmic_set_suspend_enable, .set_suspend_disable = tps65218_pmic_set_suspend_disable, |
90e7d5262 regulator: tps652... |
235 236 237 |
}; static const struct regulator_desc regulators[] = { |
2dc494036 regulator: tps652... |
238 239 240 |
TPS65218_REGULATOR("DCDC1", "regulator-dcdc1", TPS65218_DCDC_1, REGULATOR_VOLTAGE, tps65218_dcdc12_ops, 64, TPS65218_REG_CONTROL_DCDC1, |
c0ea88b89 regulator: tps652... |
241 242 |
TPS65218_CONTROL_DCDC1_MASK, TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC1_EN, 0, 0, dcdc1_dcdc2_ranges, |
b9a0d3594 regulator: tps652... |
243 |
2, 4000, 0, TPS65218_REG_SEQ3, |
7cfcecfb8 regulator: tps652... |
244 |
TPS65218_SEQ3_DC1_SEQ_MASK, NULL, 0), |
2dc494036 regulator: tps652... |
245 246 247 |
TPS65218_REGULATOR("DCDC2", "regulator-dcdc2", TPS65218_DCDC_2, REGULATOR_VOLTAGE, tps65218_dcdc12_ops, 64, TPS65218_REG_CONTROL_DCDC2, |
c0ea88b89 regulator: tps652... |
248 249 |
TPS65218_CONTROL_DCDC2_MASK, TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC2_EN, 0, 0, dcdc1_dcdc2_ranges, |
b9a0d3594 regulator: tps652... |
250 |
2, 4000, 0, TPS65218_REG_SEQ3, |
7cfcecfb8 regulator: tps652... |
251 |
TPS65218_SEQ3_DC2_SEQ_MASK, NULL, 0), |
2dc494036 regulator: tps652... |
252 253 |
TPS65218_REGULATOR("DCDC3", "regulator-dcdc3", TPS65218_DCDC_3, REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 64, |
c0ea88b89 regulator: tps652... |
254 |
TPS65218_REG_CONTROL_DCDC3, |
90e7d5262 regulator: tps652... |
255 |
TPS65218_CONTROL_DCDC3_MASK, TPS65218_REG_ENABLE1, |
c0ea88b89 regulator: tps652... |
256 |
TPS65218_ENABLE1_DC3_EN, 0, 0, ldo1_dcdc3_ranges, 2, |
7cfcecfb8 regulator: tps652... |
257 258 |
0, 0, TPS65218_REG_SEQ4, TPS65218_SEQ4_DC3_SEQ_MASK, NULL, 0), |
2dc494036 regulator: tps652... |
259 260 |
TPS65218_REGULATOR("DCDC4", "regulator-dcdc4", TPS65218_DCDC_4, REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 53, |
c0ea88b89 regulator: tps652... |
261 262 263 |
TPS65218_REG_CONTROL_DCDC4, TPS65218_CONTROL_DCDC4_MASK, TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC4_EN, 0, 0, dcdc4_ranges, 2, |
7cfcecfb8 regulator: tps652... |
264 265 |
0, 0, TPS65218_REG_SEQ4, TPS65218_SEQ4_DC4_SEQ_MASK, NULL, 0), |
2dc494036 regulator: tps652... |
266 267 268 269 |
TPS65218_REGULATOR("DCDC5", "regulator-dcdc5", TPS65218_DCDC_5, REGULATOR_VOLTAGE, tps65218_dcdc56_pmic_ops, 1, -1, -1, TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC5_EN, 0, 0, NULL, 0, 0, 1000000, TPS65218_REG_SEQ5, |
7cfcecfb8 regulator: tps652... |
270 |
TPS65218_SEQ5_DC5_SEQ_MASK, NULL, 0), |
2dc494036 regulator: tps652... |
271 272 273 274 |
TPS65218_REGULATOR("DCDC6", "regulator-dcdc6", TPS65218_DCDC_6, REGULATOR_VOLTAGE, tps65218_dcdc56_pmic_ops, 1, -1, -1, TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC6_EN, 0, 0, NULL, 0, 0, 1800000, TPS65218_REG_SEQ5, |
7cfcecfb8 regulator: tps652... |
275 |
TPS65218_SEQ5_DC6_SEQ_MASK, NULL, 0), |
2dc494036 regulator: tps652... |
276 277 |
TPS65218_REGULATOR("LDO1", "regulator-ldo1", TPS65218_LDO_1, REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 64, |
0eada6a1f regulator: tps652... |
278 |
TPS65218_REG_CONTROL_LDO1, |
90e7d5262 regulator: tps652... |
279 |
TPS65218_CONTROL_LDO1_MASK, TPS65218_REG_ENABLE2, |
c0ea88b89 regulator: tps652... |
280 |
TPS65218_ENABLE2_LDO1_EN, 0, 0, ldo1_dcdc3_ranges, |
b9a0d3594 regulator: tps652... |
281 |
2, 0, 0, TPS65218_REG_SEQ6, |
7cfcecfb8 regulator: tps652... |
282 |
TPS65218_SEQ6_LDO1_SEQ_MASK, NULL, 0), |
e5c8ba063 regulator: tps652... |
283 284 285 286 |
TPS65218_REGULATOR("LS2", "regulator-ls2", TPS65218_LS_2, REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0, TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS2_EN, TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS2ILIM_MASK, |
7cfcecfb8 regulator: tps652... |
287 288 |
NULL, 0, 0, 0, 0, 0, ls3_currents, ARRAY_SIZE(ls3_currents)), |
2dc494036 regulator: tps652... |
289 |
TPS65218_REGULATOR("LS3", "regulator-ls3", TPS65218_LS_3, |
e5c8ba063 regulator: tps652... |
290 |
REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0, |
2dc494036 regulator: tps652... |
291 292 |
TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS3_EN, TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS3ILIM_MASK, |
7cfcecfb8 regulator: tps652... |
293 294 |
NULL, 0, 0, 0, 0, 0, ls3_currents, ARRAY_SIZE(ls3_currents)), |
90e7d5262 regulator: tps652... |
295 296 297 298 299 |
}; static int tps65218_regulator_probe(struct platform_device *pdev) { struct tps65218 *tps = dev_get_drvdata(pdev->dev.parent); |
90e7d5262 regulator: tps652... |
300 |
struct regulator_dev *rdev; |
90e7d5262 regulator: tps652... |
301 |
struct regulator_config config = { }; |
2dc494036 regulator: tps652... |
302 |
int i, ret; |
b9a0d3594 regulator: tps652... |
303 |
unsigned int val; |
90e7d5262 regulator: tps652... |
304 |
|
90e7d5262 regulator: tps652... |
305 |
config.dev = &pdev->dev; |
2dc494036 regulator: tps652... |
306 |
config.dev->of_node = tps->dev->of_node; |
90e7d5262 regulator: tps652... |
307 308 |
config.driver_data = tps; config.regmap = tps->regmap; |
2dc494036 regulator: tps652... |
309 |
/* Allocate memory for strobes */ |
a86854d0c treewide: devm_kz... |
310 311 312 |
tps->strobes = devm_kcalloc(&pdev->dev, TPS65218_NUM_REGULATOR, sizeof(u8), GFP_KERNEL); |
5597bfb47 regulator: tps652... |
313 314 |
if (!tps->strobes) return -ENOMEM; |
90e7d5262 regulator: tps652... |
315 |
|
2dc494036 regulator: tps652... |
316 317 318 319 320 321 322 323 324 |
for (i = 0; i < ARRAY_SIZE(regulators); i++) { rdev = devm_regulator_register(&pdev->dev, ®ulators[i], &config); if (IS_ERR(rdev)) { dev_err(tps->dev, "failed to register %s regulator ", pdev->name); return PTR_ERR(rdev); } |
b9a0d3594 regulator: tps652... |
325 |
|
2dc494036 regulator: tps652... |
326 327 328 329 330 331 |
ret = regmap_read(tps->regmap, regulators[i].bypass_reg, &val); if (ret) return ret; tps->strobes[i] = val & regulators[i].bypass_mask; } |
b9a0d3594 regulator: tps652... |
332 |
|
90e7d5262 regulator: tps652... |
333 334 |
return 0; } |
2dc494036 regulator: tps652... |
335 336 337 338 339 |
static const struct platform_device_id tps65218_regulator_id_table[] = { { "tps65218-regulator", }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(platform, tps65218_regulator_id_table); |
90e7d5262 regulator: tps652... |
340 341 342 |
static struct platform_driver tps65218_regulator_driver = { .driver = { .name = "tps65218-pmic", |
90e7d5262 regulator: tps652... |
343 344 |
}, .probe = tps65218_regulator_probe, |
2dc494036 regulator: tps652... |
345 |
.id_table = tps65218_regulator_id_table, |
90e7d5262 regulator: tps652... |
346 347 348 349 350 351 352 353 |
}; module_platform_driver(tps65218_regulator_driver); MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>"); MODULE_DESCRIPTION("TPS65218 voltage regulator driver"); MODULE_ALIAS("platform:tps65218-pmic"); MODULE_LICENSE("GPL v2"); |