Skip to content

Commit 0fc31d8

Browse files
jwrdegoedebroonie
authored andcommitted
regulator: Introduce tps68470-regulator driver
The TPS68470 PMIC provides Clocks, GPIOs and Regulators. At present in the kernel the Regulators and Clocks are controlled by an OpRegion driver designed to work with power control methods defined in ACPI, but some platforms lack those methods, meaning drivers need to be able to consume the resources of these chips through the usual frameworks. This commit adds a driver for the regulators provided by the tps68470, and is designed to bind to the platform_device registered by the intel_skl_int3472 module. This is based on this out of tree driver written by Intel: https://github.com/intel/linux-intel-lts/blob/4.14/base/drivers/regulator/tps68470-regulator.c with various cleanups added. Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 13aad34 commit 0fc31d8

File tree

3 files changed

+211
-0
lines changed

3 files changed

+211
-0
lines changed

drivers/regulator/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,15 @@ config REGULATOR_TPS65912
13391339
help
13401340
This driver supports TPS65912 voltage regulator chip.
13411341

1342+
config REGULATOR_TPS68470
1343+
tristate "TI TPS68470 PMIC Regulators Driver"
1344+
depends on INTEL_SKL_INT3472 || COMPILE_TEST
1345+
help
1346+
This driver adds support for the TPS68470 PMIC to register
1347+
regulators against the usual framework.
1348+
1349+
The module will be called "tps68470-regulator".
1350+
13421351
config REGULATOR_TWL4030
13431352
tristate "TI TWL4030/TWL5030/TWL6030/TPS659x0 PMIC"
13441353
depends on TWL4030_CORE

drivers/regulator/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o
159159
obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o
160160
obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o
161161
obj-$(CONFIG_REGULATOR_TPS65132) += tps65132-regulator.o
162+
obj-$(CONFIG_REGULATOR_TPS68470) += tps68470-regulator.o
162163
obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o twl6030-regulator.o
163164
obj-$(CONFIG_REGULATOR_UNIPHIER) += uniphier-regulator.o
164165
obj-$(CONFIG_REGULATOR_VCTRL) += vctrl-regulator.o
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
//
3+
// Regulator driver for TPS68470 PMIC
4+
//
5+
// Copyright (c) 2021 Red Hat Inc.
6+
// Copyright (C) 2018 Intel Corporation
7+
//
8+
// Authors:
9+
// Hans de Goede <[email protected]>
10+
// Zaikuo Wang <[email protected]>
11+
// Tianshu Qiu <[email protected]>
12+
// Jian Xu Zheng <[email protected]>
13+
// Yuning Pu <[email protected]>
14+
// Rajmohan Mani <[email protected]>
15+
16+
#include <linux/clk.h>
17+
#include <linux/device.h>
18+
#include <linux/err.h>
19+
#include <linux/init.h>
20+
#include <linux/kernel.h>
21+
#include <linux/mfd/tps68470.h>
22+
#include <linux/module.h>
23+
#include <linux/platform_data/tps68470.h>
24+
#include <linux/platform_device.h>
25+
#include <linux/regulator/driver.h>
26+
#include <linux/regulator/machine.h>
27+
28+
struct tps68470_regulator_data {
29+
struct clk *clk;
30+
};
31+
32+
#define TPS68470_REGULATOR(_name, _id, _ops, _n, \
33+
_vr, _vm, _er, _em, _lr, _nlr) \
34+
[TPS68470_ ## _name] = { \
35+
.name = # _name, \
36+
.id = _id, \
37+
.ops = &_ops, \
38+
.n_voltages = _n, \
39+
.type = REGULATOR_VOLTAGE, \
40+
.owner = THIS_MODULE, \
41+
.vsel_reg = _vr, \
42+
.vsel_mask = _vm, \
43+
.enable_reg = _er, \
44+
.enable_mask = _em, \
45+
.linear_ranges = _lr, \
46+
.n_linear_ranges = _nlr, \
47+
}
48+
49+
static const struct linear_range tps68470_ldo_ranges[] = {
50+
REGULATOR_LINEAR_RANGE(875000, 0, 125, 17800),
51+
};
52+
53+
static const struct linear_range tps68470_core_ranges[] = {
54+
REGULATOR_LINEAR_RANGE(900000, 0, 42, 25000),
55+
};
56+
57+
static int tps68470_regulator_enable(struct regulator_dev *rdev)
58+
{
59+
struct tps68470_regulator_data *data = rdev->reg_data;
60+
int ret;
61+
62+
/* The Core buck regulator needs the PMIC's PLL to be enabled */
63+
if (rdev->desc->id == TPS68470_CORE) {
64+
ret = clk_prepare_enable(data->clk);
65+
if (ret) {
66+
dev_err(&rdev->dev, "Error enabling TPS68470 clock\n");
67+
return ret;
68+
}
69+
}
70+
71+
return regulator_enable_regmap(rdev);
72+
}
73+
74+
static int tps68470_regulator_disable(struct regulator_dev *rdev)
75+
{
76+
struct tps68470_regulator_data *data = rdev->reg_data;
77+
78+
if (rdev->desc->id == TPS68470_CORE)
79+
clk_disable_unprepare(data->clk);
80+
81+
return regulator_disable_regmap(rdev);
82+
}
83+
84+
/* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */
85+
static const struct regulator_ops tps68470_regulator_ops = {
86+
.is_enabled = regulator_is_enabled_regmap,
87+
.enable = tps68470_regulator_enable,
88+
.disable = tps68470_regulator_disable,
89+
.get_voltage_sel = regulator_get_voltage_sel_regmap,
90+
.set_voltage_sel = regulator_set_voltage_sel_regmap,
91+
.list_voltage = regulator_list_voltage_linear_range,
92+
.map_voltage = regulator_map_voltage_linear_range,
93+
};
94+
95+
static const struct regulator_ops tps68470_always_on_reg_ops = {
96+
.get_voltage_sel = regulator_get_voltage_sel_regmap,
97+
.set_voltage_sel = regulator_set_voltage_sel_regmap,
98+
.list_voltage = regulator_list_voltage_linear_range,
99+
.map_voltage = regulator_map_voltage_linear_range,
100+
};
101+
102+
static const struct regulator_desc regulators[] = {
103+
TPS68470_REGULATOR(CORE, TPS68470_CORE, tps68470_regulator_ops, 43,
104+
TPS68470_REG_VDVAL, TPS68470_VDVAL_DVOLT_MASK,
105+
TPS68470_REG_VDCTL, TPS68470_VDCTL_EN_MASK,
106+
tps68470_core_ranges, ARRAY_SIZE(tps68470_core_ranges)),
107+
TPS68470_REGULATOR(ANA, TPS68470_ANA, tps68470_regulator_ops, 126,
108+
TPS68470_REG_VAVAL, TPS68470_VAVAL_AVOLT_MASK,
109+
TPS68470_REG_VACTL, TPS68470_VACTL_EN_MASK,
110+
tps68470_ldo_ranges, ARRAY_SIZE(tps68470_ldo_ranges)),
111+
TPS68470_REGULATOR(VCM, TPS68470_VCM, tps68470_regulator_ops, 126,
112+
TPS68470_REG_VCMVAL, TPS68470_VCMVAL_VCVOLT_MASK,
113+
TPS68470_REG_VCMCTL, TPS68470_VCMCTL_EN_MASK,
114+
tps68470_ldo_ranges, ARRAY_SIZE(tps68470_ldo_ranges)),
115+
TPS68470_REGULATOR(VIO, TPS68470_VIO, tps68470_always_on_reg_ops, 126,
116+
TPS68470_REG_VIOVAL, TPS68470_VIOVAL_IOVOLT_MASK,
117+
0, 0,
118+
tps68470_ldo_ranges, ARRAY_SIZE(tps68470_ldo_ranges)),
119+
/*
120+
* (1) This regulator must have the same voltage as VIO if S_IO LDO is used to
121+
* power a sensor/VCM which I2C is daisy chained behind the PMIC.
122+
* (2) If there is no I2C daisy chain it can be set freely.
123+
*/
124+
TPS68470_REGULATOR(VSIO, TPS68470_VSIO, tps68470_regulator_ops, 126,
125+
TPS68470_REG_VSIOVAL, TPS68470_VSIOVAL_IOVOLT_MASK,
126+
TPS68470_REG_S_I2C_CTL, TPS68470_S_I2C_CTL_EN_MASK,
127+
tps68470_ldo_ranges, ARRAY_SIZE(tps68470_ldo_ranges)),
128+
TPS68470_REGULATOR(AUX1, TPS68470_AUX1, tps68470_regulator_ops, 126,
129+
TPS68470_REG_VAUX1VAL, TPS68470_VAUX1VAL_AUX1VOLT_MASK,
130+
TPS68470_REG_VAUX1CTL, TPS68470_VAUX1CTL_EN_MASK,
131+
tps68470_ldo_ranges, ARRAY_SIZE(tps68470_ldo_ranges)),
132+
TPS68470_REGULATOR(AUX2, TPS68470_AUX2, tps68470_regulator_ops, 126,
133+
TPS68470_REG_VAUX2VAL, TPS68470_VAUX2VAL_AUX2VOLT_MASK,
134+
TPS68470_REG_VAUX2CTL, TPS68470_VAUX2CTL_EN_MASK,
135+
tps68470_ldo_ranges, ARRAY_SIZE(tps68470_ldo_ranges)),
136+
};
137+
138+
static int tps68470_regulator_probe(struct platform_device *pdev)
139+
{
140+
struct device *dev = &pdev->dev;
141+
struct tps68470_regulator_platform_data *pdata = dev_get_platdata(dev);
142+
struct tps68470_regulator_data *data;
143+
struct regulator_config config = { };
144+
struct regulator_dev *rdev;
145+
int i;
146+
147+
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
148+
if (!data)
149+
return -ENOMEM;
150+
151+
data->clk = devm_clk_get(dev, "tps68470-clk");
152+
if (IS_ERR(data->clk))
153+
return dev_err_probe(dev, PTR_ERR(data->clk), "getting tps68470-clk\n");
154+
155+
config.dev = dev->parent;
156+
config.regmap = dev_get_drvdata(dev->parent);
157+
config.driver_data = data;
158+
159+
for (i = 0; i < TPS68470_NUM_REGULATORS; i++) {
160+
if (pdata)
161+
config.init_data = pdata->reg_init_data[i];
162+
else
163+
config.init_data = NULL;
164+
165+
rdev = devm_regulator_register(dev, &regulators[i], &config);
166+
if (IS_ERR(rdev))
167+
return dev_err_probe(dev, PTR_ERR(rdev),
168+
"registering %s regulator\n",
169+
regulators[i].name);
170+
}
171+
172+
return 0;
173+
}
174+
175+
static struct platform_driver tps68470_regulator_driver = {
176+
.driver = {
177+
.name = "tps68470-regulator",
178+
},
179+
.probe = tps68470_regulator_probe,
180+
};
181+
182+
/*
183+
* The ACPI tps68470 probe-ordering depends on the clk/gpio/regulator drivers
184+
* registering before the drivers for the camera-sensors which use them bind.
185+
* subsys_initcall() ensures this when the drivers are builtin.
186+
*/
187+
static int __init tps68470_regulator_init(void)
188+
{
189+
return platform_driver_register(&tps68470_regulator_driver);
190+
}
191+
subsys_initcall(tps68470_regulator_init);
192+
193+
static void __exit tps68470_regulator_exit(void)
194+
{
195+
platform_driver_unregister(&tps68470_regulator_driver);
196+
}
197+
module_exit(tps68470_regulator_exit);
198+
199+
MODULE_ALIAS("platform:tps68470-regulator");
200+
MODULE_DESCRIPTION("TPS68470 voltage regulator driver");
201+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)