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/gpio.h>
22 #include <linux/slab.h>
23 #include <linux/err.h>
24 #include <linux/platform_device.h>
25 #include <linux/regulator/driver.h>
26 #include <linux/regulator/machine.h>
27 #include <linux/mfd/tps65090.h>
29 struct tps65090_regulator
{
31 struct regulator_desc
*desc
;
32 struct regulator_dev
*rdev
;
35 static struct regulator_ops tps65090_ext_control_ops
= {
38 static struct regulator_ops tps65090_reg_contol_ops
= {
39 .enable
= regulator_enable_regmap
,
40 .disable
= regulator_disable_regmap
,
41 .is_enabled
= regulator_is_enabled_regmap
,
44 static struct regulator_ops tps65090_ldo_ops
= {
47 #define tps65090_REG_DESC(_id, _sname, _en_reg, _ops) \
49 .name = "TPS65090_RAILS"#_id, \
50 .supply_name = _sname, \
51 .id = TPS65090_REGULATOR_##_id, \
53 .enable_reg = _en_reg, \
54 .enable_mask = BIT(0), \
55 .type = REGULATOR_VOLTAGE, \
56 .owner = THIS_MODULE, \
59 static struct regulator_desc tps65090_regulator_desc
[] = {
60 tps65090_REG_DESC(DCDC1
, "vsys1", 0x0C, tps65090_reg_contol_ops
),
61 tps65090_REG_DESC(DCDC2
, "vsys2", 0x0D, tps65090_reg_contol_ops
),
62 tps65090_REG_DESC(DCDC3
, "vsys3", 0x0E, tps65090_reg_contol_ops
),
63 tps65090_REG_DESC(FET1
, "infet1", 0x0F, tps65090_reg_contol_ops
),
64 tps65090_REG_DESC(FET2
, "infet2", 0x10, tps65090_reg_contol_ops
),
65 tps65090_REG_DESC(FET3
, "infet3", 0x11, tps65090_reg_contol_ops
),
66 tps65090_REG_DESC(FET4
, "infet4", 0x12, tps65090_reg_contol_ops
),
67 tps65090_REG_DESC(FET5
, "infet5", 0x13, tps65090_reg_contol_ops
),
68 tps65090_REG_DESC(FET6
, "infet6", 0x14, tps65090_reg_contol_ops
),
69 tps65090_REG_DESC(FET7
, "infet7", 0x15, tps65090_reg_contol_ops
),
70 tps65090_REG_DESC(LDO1
, "vsys_l1", 0, tps65090_ldo_ops
),
71 tps65090_REG_DESC(LDO2
, "vsys_l2", 0, tps65090_ldo_ops
),
74 static inline bool is_dcdc(int id
)
77 case TPS65090_REGULATOR_DCDC1
:
78 case TPS65090_REGULATOR_DCDC2
:
79 case TPS65090_REGULATOR_DCDC3
:
86 static int tps65090_config_ext_control(
87 struct tps65090_regulator
*ri
, bool enable
)
90 struct device
*parent
= ri
->dev
->parent
;
91 unsigned int reg_en_reg
= ri
->desc
->enable_reg
;
94 ret
= tps65090_set_bits(parent
, reg_en_reg
, 1);
96 ret
= tps65090_clr_bits(parent
, reg_en_reg
, 1);
98 dev_err(ri
->dev
, "Error in updating reg 0x%x\n", reg_en_reg
);
102 static int tps65090_regulator_disable_ext_control(
103 struct tps65090_regulator
*ri
,
104 struct tps65090_regulator_plat_data
*tps_pdata
)
107 struct device
*parent
= ri
->dev
->parent
;
108 unsigned int reg_en_reg
= ri
->desc
->enable_reg
;
111 * First enable output for internal control if require.
112 * And then disable external control.
114 if (tps_pdata
->reg_init_data
->constraints
.always_on
||
115 tps_pdata
->reg_init_data
->constraints
.boot_on
) {
116 ret
= tps65090_set_bits(parent
, reg_en_reg
, 0);
118 dev_err(ri
->dev
, "Error in set reg 0x%x\n", reg_en_reg
);
122 return tps65090_config_ext_control(ri
, false);
125 static void tps65090_configure_regulator_config(
126 struct tps65090_regulator_plat_data
*tps_pdata
,
127 struct regulator_config
*config
)
129 if (gpio_is_valid(tps_pdata
->gpio
)) {
130 int gpio_flag
= GPIOF_OUT_INIT_LOW
;
132 if (tps_pdata
->reg_init_data
->constraints
.always_on
||
133 tps_pdata
->reg_init_data
->constraints
.boot_on
)
134 gpio_flag
= GPIOF_OUT_INIT_HIGH
;
136 config
->ena_gpio
= tps_pdata
->gpio
;
137 config
->ena_gpio_flags
= gpio_flag
;
141 static int tps65090_regulator_probe(struct platform_device
*pdev
)
143 struct tps65090
*tps65090_mfd
= dev_get_drvdata(pdev
->dev
.parent
);
144 struct tps65090_regulator
*ri
= NULL
;
145 struct regulator_config config
= { };
146 struct regulator_dev
*rdev
;
147 struct tps65090_regulator_plat_data
*tps_pdata
;
148 struct tps65090_regulator
*pmic
;
149 struct tps65090_platform_data
*tps65090_pdata
;
153 dev_dbg(&pdev
->dev
, "Probing regulator\n");
155 tps65090_pdata
= dev_get_platdata(pdev
->dev
.parent
);
156 if (!tps65090_pdata
) {
157 dev_err(&pdev
->dev
, "Platform data missing\n");
161 pmic
= devm_kzalloc(&pdev
->dev
, TPS65090_REGULATOR_MAX
* sizeof(*pmic
),
164 dev_err(&pdev
->dev
, "mem alloc for pmic failed\n");
168 for (num
= 0; num
< TPS65090_REGULATOR_MAX
; num
++) {
169 tps_pdata
= tps65090_pdata
->reg_pdata
[num
];
172 ri
->dev
= &pdev
->dev
;
173 ri
->desc
= &tps65090_regulator_desc
[num
];
176 * TPS5090 DCDC support the control from external digital input.
177 * Configure it as per platform data.
179 if (tps_pdata
&& is_dcdc(num
) && tps_pdata
->reg_init_data
) {
180 if (tps_pdata
->enable_ext_control
) {
181 tps65090_configure_regulator_config(
183 ri
->desc
->ops
= &tps65090_ext_control_ops
;
185 ret
= tps65090_regulator_disable_ext_control(
189 "failed disable ext control\n");
195 config
.dev
= &pdev
->dev
;
196 config
.driver_data
= ri
;
197 config
.regmap
= tps65090_mfd
->rmap
;
199 config
.init_data
= tps_pdata
->reg_init_data
;
201 config
.init_data
= NULL
;
203 rdev
= regulator_register(ri
->desc
, &config
);
205 dev_err(&pdev
->dev
, "failed to register regulator %s\n",
212 /* Enable external control if it is require */
213 if (tps_pdata
&& is_dcdc(num
) && tps_pdata
->reg_init_data
&&
214 tps_pdata
->enable_ext_control
) {
215 ret
= tps65090_config_ext_control(ri
, true);
217 /* Increment num to get unregister rdev */
224 platform_set_drvdata(pdev
, pmic
);
230 regulator_unregister(ri
->rdev
);
235 static int tps65090_regulator_remove(struct platform_device
*pdev
)
237 struct tps65090_regulator
*pmic
= platform_get_drvdata(pdev
);
238 struct tps65090_regulator
*ri
;
241 for (num
= 0; num
< TPS65090_REGULATOR_MAX
; ++num
) {
243 regulator_unregister(ri
->rdev
);
248 static struct platform_driver tps65090_regulator_driver
= {
250 .name
= "tps65090-pmic",
251 .owner
= THIS_MODULE
,
253 .probe
= tps65090_regulator_probe
,
254 .remove
= tps65090_regulator_remove
,
257 static int __init
tps65090_regulator_init(void)
259 return platform_driver_register(&tps65090_regulator_driver
);
261 subsys_initcall(tps65090_regulator_init
);
263 static void __exit
tps65090_regulator_exit(void)
265 platform_driver_unregister(&tps65090_regulator_driver
);
267 module_exit(tps65090_regulator_exit
);
269 MODULE_DESCRIPTION("tps65090 regulator driver");
270 MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>");
271 MODULE_LICENSE("GPL v2");
272 MODULE_ALIAS("platform:tps65090-pmic");