1 // SPDX-License-Identifier: GPL-2.0
3 // Regulator driver for TPS68470 PMIC
5 // Copyright (c) 2021 Red Hat Inc.
6 // Copyright (C) 2018 Intel Corporation
9 // Hans de Goede <hdegoede@redhat.com>
10 // Zaikuo Wang <zaikuo.wang@intel.com>
11 // Tianshu Qiu <tian.shu.qiu@intel.com>
12 // Jian Xu Zheng <jian.xu.zheng@intel.com>
13 // Yuning Pu <yuning.pu@intel.com>
14 // Rajmohan Mani <rajmohan.mani@intel.com>
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>
28 struct tps68470_regulator_data {
32 #define TPS68470_REGULATOR(_name, _id, _ops, _n, \
33 _vr, _vm, _er, _em, _lr, _nlr) \
34 [TPS68470_ ## _name] = { \
39 .type = REGULATOR_VOLTAGE, \
40 .owner = THIS_MODULE, \
45 .linear_ranges = _lr, \
46 .n_linear_ranges = _nlr, \
49 static const struct linear_range tps68470_ldo_ranges[] = {
50 REGULATOR_LINEAR_RANGE(875000, 0, 125, 17800),
53 static const struct linear_range tps68470_core_ranges[] = {
54 REGULATOR_LINEAR_RANGE(900000, 0, 42, 25000),
57 static int tps68470_regulator_enable(struct regulator_dev *rdev)
59 struct tps68470_regulator_data *data = rdev->reg_data;
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);
66 dev_err(&rdev->dev, "Error enabling TPS68470 clock\n");
71 return regulator_enable_regmap(rdev);
74 static int tps68470_regulator_disable(struct regulator_dev *rdev)
76 struct tps68470_regulator_data *data = rdev->reg_data;
78 if (rdev->desc->id == TPS68470_CORE)
79 clk_disable_unprepare(data->clk);
81 return regulator_disable_regmap(rdev);
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,
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,
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,
118 tps68470_ldo_ranges, ARRAY_SIZE(tps68470_ldo_ranges)),
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.
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)),
138 static int tps68470_regulator_probe(struct platform_device *pdev)
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;
147 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
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");
155 config.dev = dev->parent;
156 config.regmap = dev_get_drvdata(dev->parent);
157 config.driver_data = data;
159 for (i = 0; i < TPS68470_NUM_REGULATORS; i++) {
161 config.init_data = pdata->reg_init_data[i];
163 config.init_data = NULL;
165 rdev = devm_regulator_register(dev, ®ulators[i], &config);
167 return dev_err_probe(dev, PTR_ERR(rdev),
168 "registering %s regulator\n",
175 static struct platform_driver tps68470_regulator_driver = {
177 .name = "tps68470-regulator",
178 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
180 .probe = tps68470_regulator_probe,
184 * The ACPI tps68470 probe-ordering depends on the clk/gpio/regulator drivers
185 * registering before the drivers for the camera-sensors which use them bind.
186 * subsys_initcall() ensures this when the drivers are builtin.
188 static int __init tps68470_regulator_init(void)
190 return platform_driver_register(&tps68470_regulator_driver);
192 subsys_initcall(tps68470_regulator_init);
194 static void __exit tps68470_regulator_exit(void)
196 platform_driver_unregister(&tps68470_regulator_driver);
198 module_exit(tps68470_regulator_exit);
200 MODULE_ALIAS("platform:tps68470-regulator");
201 MODULE_DESCRIPTION("TPS68470 voltage regulator driver");
202 MODULE_LICENSE("GPL v2");