2 * Regulator driver for tps65090 power management chip.
4 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/slab.h>
22 #include <linux/err.h>
23 #include <linux/platform_device.h>
24 #include <linux/regulator/driver.h>
25 #include <linux/regulator/machine.h>
26 #include <linux/mfd/tps65090.h>
28 struct tps65090_regulator {
30 struct regulator_desc *desc;
31 struct regulator_dev *rdev;
34 static struct regulator_ops tps65090_ops = {
35 .enable = regulator_enable_regmap,
36 .disable = regulator_disable_regmap,
37 .is_enabled = regulator_is_enabled_regmap,
40 #define tps65090_REG_DESC(_id, _sname, _en_reg, _ops) \
42 .name = "TPS65090_RAILS"#_id, \
43 .supply_name = _sname, \
44 .id = TPS65090_ID_##_id, \
46 .enable_reg = _en_reg, \
47 .enable_mask = BIT(0), \
48 .type = REGULATOR_VOLTAGE, \
49 .owner = THIS_MODULE, \
52 static struct regulator_desc tps65090_regulator_desc[] = {
53 tps65090_REG_DESC(DCDC1, "vsys1", 0x0C, tps65090_ops),
54 tps65090_REG_DESC(DCDC2, "vsys2", 0x0D, tps65090_ops),
55 tps65090_REG_DESC(DCDC3, "vsys3", 0x0E, tps65090_ops),
56 tps65090_REG_DESC(FET1, "infet1", 0x0F, tps65090_ops),
57 tps65090_REG_DESC(FET2, "infet2", 0x10, tps65090_ops),
58 tps65090_REG_DESC(FET3, "infet3", 0x11, tps65090_ops),
59 tps65090_REG_DESC(FET4, "infet4", 0x12, tps65090_ops),
60 tps65090_REG_DESC(FET5, "infet5", 0x13, tps65090_ops),
61 tps65090_REG_DESC(FET6, "infet6", 0x14, tps65090_ops),
62 tps65090_REG_DESC(FET7, "infet7", 0x15, tps65090_ops),
65 static inline bool is_dcdc(int id)
68 case TPS65090_ID_DCDC1:
69 case TPS65090_ID_DCDC2:
70 case TPS65090_ID_DCDC3:
77 static int __devinit tps65090_config_ext_control(
78 struct tps65090_regulator *ri, bool enable)
81 struct device *parent = ri->dev->parent;
82 unsigned int reg_en_reg = ri->desc->enable_reg;
85 ret = tps65090_set_bits(parent, reg_en_reg, 1);
87 ret = tps65090_clr_bits(parent, reg_en_reg, 1);
89 dev_err(ri->dev, "Error in updating reg 0x%x\n", reg_en_reg);
93 static int __devinit tps65090_regulator_disable_ext_control(
94 struct tps65090_regulator *ri,
95 struct tps65090_regulator_plat_data *tps_pdata)
98 struct device *parent = ri->dev->parent;
99 unsigned int reg_en_reg = ri->desc->enable_reg;
102 * First enable output for internal control if require.
103 * And then disable external control.
105 if (tps_pdata->reg_init_data->constraints.always_on ||
106 tps_pdata->reg_init_data->constraints.boot_on) {
107 ret = tps65090_set_bits(parent, reg_en_reg, 0);
109 dev_err(ri->dev, "Error in set reg 0x%x\n", reg_en_reg);
113 return tps65090_config_ext_control(ri, false);
116 static int __devinit tps65090_regulator_probe(struct platform_device *pdev)
118 struct tps65090 *tps65090_mfd = dev_get_drvdata(pdev->dev.parent);
119 struct tps65090_regulator *ri = NULL;
120 struct regulator_config config = { };
121 struct regulator_dev *rdev;
122 struct tps65090_regulator_plat_data *tps_pdata;
123 struct tps65090_regulator *pmic;
124 struct tps65090_platform_data *tps65090_pdata;
128 dev_dbg(&pdev->dev, "Probing regulator\n");
130 tps65090_pdata = dev_get_platdata(pdev->dev.parent);
131 if (!tps65090_pdata) {
132 dev_err(&pdev->dev, "Platform data missing\n");
136 pmic = devm_kzalloc(&pdev->dev, TPS65090_ID_MAX * sizeof(*pmic),
139 dev_err(&pdev->dev, "mem alloc for pmic failed\n");
143 for (num = 0; num < TPS65090_ID_MAX; num++) {
144 tps_pdata = tps65090_pdata->reg_pdata[num];
147 ri->dev = &pdev->dev;
148 ri->desc = &tps65090_regulator_desc[num];
151 * TPS5090 DCDC support the control from external digital input.
152 * It may be possible that during boot, the external control is
153 * enabled. Disabling external control for DCDC.
155 if (tps_pdata && is_dcdc(num) && tps_pdata->reg_init_data) {
156 ret = tps65090_regulator_disable_ext_control(
160 "failed disable ext control\n");
164 config.dev = &pdev->dev;
165 config.driver_data = ri;
166 config.regmap = tps65090_mfd->rmap;
168 config.init_data = tps_pdata->reg_init_data;
170 config.init_data = NULL;
172 rdev = regulator_register(ri->desc, &config);
174 dev_err(&pdev->dev, "failed to register regulator %s\n",
182 platform_set_drvdata(pdev, pmic);
188 regulator_unregister(ri->rdev);
193 static int __devexit tps65090_regulator_remove(struct platform_device *pdev)
195 struct tps65090_regulator *pmic = platform_get_drvdata(pdev);
196 struct tps65090_regulator *ri;
199 for (num = 0; num < TPS65090_ID_MAX; ++num) {
201 regulator_unregister(ri->rdev);
206 static struct platform_driver tps65090_regulator_driver = {
208 .name = "tps65090-regulator",
209 .owner = THIS_MODULE,
211 .probe = tps65090_regulator_probe,
212 .remove = __devexit_p(tps65090_regulator_remove),
215 static int __init tps65090_regulator_init(void)
217 return platform_driver_register(&tps65090_regulator_driver);
219 subsys_initcall(tps65090_regulator_init);
221 static void __exit tps65090_regulator_exit(void)
223 platform_driver_unregister(&tps65090_regulator_driver);
225 module_exit(tps65090_regulator_exit);
227 MODULE_DESCRIPTION("tps65090 regulator driver");
228 MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>");
229 MODULE_LICENSE("GPL v2");