18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/device.h>
30 #define TPS65217_REGULATOR(_name, _id, _ops, _n, _vr, _vm, _em, _t) \
36 .type = REGULATOR_VOLTAGE, \
37 .owner = THIS_MODULE, \
40 .enable_reg = TPS65217_REG_ENABLE, \
45 #define TPS65217_INFO(_nm, _min, _max, _f1, _f2) \
54 static const unsigned int LDO1_VSEL_table[] = {
55 1000000, 1100000, 1200000, 1250000,
56 1300000, 1350000, 1400000, 1500000,
57 1600000, 1800000, 2500000, 2750000,
58 2800000, 3000000, 3100000, 3300000,
61 static int tps65217_vsel_to_uv1(
unsigned int vsel)
69 uV = vsel * 25000 + 900000;
71 uV = (vsel - 24) * 50000 + 1500000;
73 uV = (vsel - 52) * 100000 + 2900000;
80 static int tps65217_uv_to_vsel1(
int uV,
unsigned int *vsel)
82 if (uV < 0 || uV > 3300000)
87 else if (uV <= 2900000)
89 else if (uV < 3300000)
97 static int tps65217_vsel_to_uv2(
unsigned int vsel)
105 uV = vsel * 50000 + 1500000;
107 uV = (vsel - 8) * 100000 + 1900000;
109 uV = (vsel - 13) * 50000 + 2400000;
114 static int tps65217_uv_to_vsel2(
int uV,
unsigned int *vsel)
116 if (uV < 0 || uV > 3300000)
121 else if (uV <= 2400000)
129 static struct tps_info tps65217_pmic_regs[] = {
130 TPS65217_INFO(
"DCDC1", 900000, 1800000, tps65217_vsel_to_uv1,
131 tps65217_uv_to_vsel1),
132 TPS65217_INFO(
"DCDC2", 900000, 3300000, tps65217_vsel_to_uv1,
133 tps65217_uv_to_vsel1),
134 TPS65217_INFO(
"DCDC3", 900000, 1500000, tps65217_vsel_to_uv1,
135 tps65217_uv_to_vsel1),
138 tps65217_uv_to_vsel1),
139 TPS65217_INFO(
"LDO3", 1800000, 3300000, tps65217_vsel_to_uv2,
140 tps65217_uv_to_vsel2),
141 TPS65217_INFO(
"LDO4", 1800000, 3300000, tps65217_vsel_to_uv2,
142 tps65217_uv_to_vsel2),
155 dev->
desc->enable_mask, dev->
desc->enable_mask,
172 static int tps65217_pmic_set_voltage_sel(
struct regulator_dev *dev,
195 static int tps65217_pmic_map_voltage(
struct regulator_dev *dev,
196 int min_uV,
int max_uV)
210 if (min_uV < tps->
info[rid]->min_uV)
211 min_uV = tps->
info[rid]->min_uV;
213 if (max_uV < tps->
info[rid]->min_uV || min_uV > tps->
info[rid]->max_uV)
216 ret = tps->
info[rid]->uv_to_vsel(min_uV, &sel);
223 static int tps65217_pmic_list_voltage(
struct regulator_dev *dev,
229 if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
232 if (selector >= dev->
desc->n_voltages)
235 return tps->
info[rid]->vsel_to_uv(selector);
241 .enable = tps65217_pmic_enable,
242 .disable = tps65217_pmic_disable,
244 .set_voltage_sel = tps65217_pmic_set_voltage_sel,
245 .list_voltage = tps65217_pmic_list_voltage,
246 .map_voltage = tps65217_pmic_map_voltage,
252 .enable = tps65217_pmic_enable,
253 .disable = tps65217_pmic_disable,
255 .set_voltage_sel = tps65217_pmic_set_voltage_sel,
293 { .name =
"ldo4", .driver_data = (
void *)TPS65217_LDO_4 },
318 for (i = 0; i <
count; i++) {
319 if (!reg_matches[i].init_data || !reg_matches[i].of_node)
344 if (tps->
dev->of_node)
345 pdata = tps65217_parse_dt(pdev);
348 dev_err(&pdev->
dev,
"Platform data not found\n");
352 if (tps65217_chip_id(tps) !=
TPS65217) {
353 dev_err(&pdev->
dev,
"Invalid tps chip version\n");
357 platform_set_drvdata(pdev, tps);
371 tps->
info[
i] = &tps65217_pmic_regs[
i];
377 if (tps->
dev->of_node)
382 dev_err(tps->
dev,
"failed to register %s regulator\n",
385 goto err_unregister_regulator;
393 err_unregister_regulator:
402 struct tps65217 *tps = platform_get_drvdata(pdev);
408 platform_set_drvdata(pdev,
NULL);
415 .name =
"tps65217-pmic",
417 .probe = tps65217_regulator_probe,
421 static int __init tps65217_regulator_init(
void)
427 static void __exit tps65217_regulator_exit(
void)