blob: 2e92aa8718cc51e66bde7397471bad109a7ec914 [file] [log] [blame]
Venu Byravarasu452534e2012-03-22 18:34:09 +05301/*
2 * Regulator driver for tps65090 power management chip.
3 *
4 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
5
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.
9
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
13 * more details.
14
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/>
17 */
18
19#include <linux/module.h>
Doug Andersoned11f1e2014-04-23 08:56:05 -070020#include <linux/delay.h>
Venu Byravarasu452534e2012-03-22 18:34:09 +053021#include <linux/init.h>
Laxman Dewanganf329b172012-10-09 15:19:02 +053022#include <linux/gpio.h>
Laxman Dewangan6c7a7a02013-01-29 14:35:16 +053023#include <linux/of_gpio.h>
Venu Byravarasu452534e2012-03-22 18:34:09 +053024#include <linux/slab.h>
25#include <linux/err.h>
26#include <linux/platform_device.h>
27#include <linux/regulator/driver.h>
28#include <linux/regulator/machine.h>
Laxman Dewangan6c7a7a02013-01-29 14:35:16 +053029#include <linux/regulator/of_regulator.h>
Venu Byravarasu452534e2012-03-22 18:34:09 +053030#include <linux/mfd/tps65090.h>
Venu Byravarasu452534e2012-03-22 18:34:09 +053031
Doug Andersoned11f1e2014-04-23 08:56:05 -070032#define MAX_CTRL_READ_TRIES 5
33#define MAX_FET_ENABLE_TRIES 1000
34
35#define CTRL_EN_BIT 0 /* Regulator enable bit, active high */
Doug Anderson29041442014-04-16 16:12:28 -070036#define CTRL_WT_BIT 2 /* Regulator wait time 0 bit */
Doug Andersoned11f1e2014-04-23 08:56:05 -070037#define CTRL_PG_BIT 4 /* Regulator power good bit, 1=good */
38#define CTRL_TO_BIT 7 /* Regulator timeout bit, 1=wait */
Doug Anderson29041442014-04-16 16:12:28 -070039
40#define MAX_OVERCURRENT_WAIT 3 /* Overcurrent wait must be <= this */
41
42/**
43 * struct tps65090_regulator - Per-regulator data for a tps65090 regulator
44 *
45 * @dev: Pointer to our device.
46 * @desc: The struct regulator_desc for the regulator.
47 * @rdev: The struct regulator_dev for the regulator.
48 * @overcurrent_wait_valid: True if overcurrent_wait is valid.
49 * @overcurrent_wait: For FETs, the value to put in the WTFET bitfield.
50 */
51
Venu Byravarasu452534e2012-03-22 18:34:09 +053052struct tps65090_regulator {
Venu Byravarasu452534e2012-03-22 18:34:09 +053053 struct device *dev;
Laxman Dewangan24282a12012-10-09 15:18:59 +053054 struct regulator_desc *desc;
55 struct regulator_dev *rdev;
Doug Anderson29041442014-04-16 16:12:28 -070056 bool overcurrent_wait_valid;
57 int overcurrent_wait;
Venu Byravarasu452534e2012-03-22 18:34:09 +053058};
59
Laxman Dewanganf329b172012-10-09 15:19:02 +053060static struct regulator_ops tps65090_ext_control_ops = {
61};
62
Doug Anderson29041442014-04-16 16:12:28 -070063/**
64 * tps65090_reg_set_overcurrent_wait - Setup overcurrent wait
65 *
66 * This will set the overcurrent wait time based on what's in the regulator
67 * info.
68 *
69 * @ri: Overall regulator data
70 * @rdev: Regulator device
71 *
72 * Return: 0 if no error, non-zero if there was an error writing the register.
73 */
74static int tps65090_reg_set_overcurrent_wait(struct tps65090_regulator *ri,
75 struct regulator_dev *rdev)
76{
77 int ret;
78
79 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
80 MAX_OVERCURRENT_WAIT << CTRL_WT_BIT,
81 ri->overcurrent_wait << CTRL_WT_BIT);
82 if (ret) {
83 dev_err(&rdev->dev, "Error updating overcurrent wait %#x\n",
84 rdev->desc->enable_reg);
85 }
86
87 return ret;
88}
89
Doug Andersoned11f1e2014-04-23 08:56:05 -070090/**
91 * tps65090_try_enable_fet - Try to enable a FET
92 *
93 * @rdev: Regulator device
94 *
95 * Return: 0 if ok, -ENOTRECOVERABLE if the FET power good bit did not get
96 * set, or some other -ve value if another error occurred (e.g. i2c error)
97 */
98static int tps65090_try_enable_fet(struct regulator_dev *rdev)
99{
100 unsigned int control;
101 int ret, i;
102
103 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
104 rdev->desc->enable_mask,
105 rdev->desc->enable_mask);
106 if (ret < 0) {
107 dev_err(&rdev->dev, "Error in updating reg %#x\n",
108 rdev->desc->enable_reg);
109 return ret;
110 }
111
112 for (i = 0; i < MAX_CTRL_READ_TRIES; i++) {
113 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg,
114 &control);
115 if (ret < 0)
116 return ret;
117
118 if (!(control & BIT(CTRL_TO_BIT)))
119 break;
120
121 usleep_range(1000, 1500);
122 }
123 if (!(control & BIT(CTRL_PG_BIT)))
124 return -ENOTRECOVERABLE;
125
126 return 0;
127}
128
129/**
130 * tps65090_fet_enable - Enable a FET, trying a few times if it fails
131 *
132 * Some versions of the tps65090 have issues when turning on the FETs.
133 * This function goes through several steps to ensure the best chance of the
134 * FET going on. Specifically:
135 * - We'll make sure that we bump the "overcurrent wait" to the maximum, which
136 * increases the chances that we'll turn on properly.
137 * - We'll retry turning the FET on multiple times (turning off in between).
138 *
139 * @rdev: Regulator device
140 *
141 * Return: 0 if ok, non-zero if it fails.
142 */
143static int tps65090_fet_enable(struct regulator_dev *rdev)
144{
145 int ret, tries;
146
147 /*
148 * Try enabling multiple times until we succeed since sometimes the
149 * first try times out.
150 */
151 tries = 0;
152 while (true) {
153 ret = tps65090_try_enable_fet(rdev);
154 if (!ret)
155 break;
156 if (ret != -ENOTRECOVERABLE || tries == MAX_FET_ENABLE_TRIES)
157 goto err;
158
159 /* Try turning the FET off (and then on again) */
160 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
161 rdev->desc->enable_mask, 0);
162 if (ret)
163 goto err;
164
165 tries++;
166 }
167
168 if (tries)
169 dev_warn(&rdev->dev, "reg %#x enable ok after %d tries\n",
170 rdev->desc->enable_reg, tries);
171
172 return 0;
173err:
174 dev_warn(&rdev->dev, "reg %#x enable failed\n", rdev->desc->enable_reg);
175 WARN_ON(1);
176
177 return ret;
178}
179
180static struct regulator_ops tps65090_reg_control_ops = {
Laxman Dewanganf329b172012-10-09 15:19:02 +0530181 .enable = regulator_enable_regmap,
182 .disable = regulator_disable_regmap,
183 .is_enabled = regulator_is_enabled_regmap,
Venu Byravarasu452534e2012-03-22 18:34:09 +0530184};
185
Doug Andersoned11f1e2014-04-23 08:56:05 -0700186static struct regulator_ops tps65090_fet_control_ops = {
187 .enable = tps65090_fet_enable,
188 .disable = regulator_disable_regmap,
189 .is_enabled = regulator_is_enabled_regmap,
190};
191
Laxman Dewangan3a81ef82012-10-09 15:19:01 +0530192static struct regulator_ops tps65090_ldo_ops = {
193};
194
Javier Martinez Canillas4f2352c2014-07-31 14:31:05 +0200195#define tps65090_REG_DESC(_id, _sname, _en_reg, _en_bits, _nvolt, _volt, _ops) \
Venu Byravarasu452534e2012-03-22 18:34:09 +0530196{ \
Laxman Dewangan24282a12012-10-09 15:18:59 +0530197 .name = "TPS65090_RAILS"#_id, \
198 .supply_name = _sname, \
Laxman Dewangan8620ca92012-10-09 15:19:00 +0530199 .id = TPS65090_REGULATOR_##_id, \
Javier Martinez Canillas4f2352c2014-07-31 14:31:05 +0200200 .n_voltages = _nvolt, \
Laxman Dewangan24282a12012-10-09 15:18:59 +0530201 .ops = &_ops, \
Javier Martinez Canillas4f2352c2014-07-31 14:31:05 +0200202 .fixed_uV = _volt, \
Laxman Dewangan24282a12012-10-09 15:18:59 +0530203 .enable_reg = _en_reg, \
Doug Andersoned11f1e2014-04-23 08:56:05 -0700204 .enable_val = _en_bits, \
205 .enable_mask = _en_bits, \
Laxman Dewangan24282a12012-10-09 15:18:59 +0530206 .type = REGULATOR_VOLTAGE, \
207 .owner = THIS_MODULE, \
Venu Byravarasu452534e2012-03-22 18:34:09 +0530208}
209
Javier Martinez Canillas4f2352c2014-07-31 14:31:05 +0200210#define tps65090_REG_FIXEDV(_id, _sname, en_reg, _en_bits, _volt, _ops) \
211 tps65090_REG_DESC(_id, _sname, en_reg, _en_bits, 1, _volt, _ops)
212
213#define tps65090_REG_SWITCH(_id, _sname, en_reg, _en_bits, _ops) \
214 tps65090_REG_DESC(_id, _sname, en_reg, _en_bits, 0, 0, _ops)
215
Laxman Dewangan24282a12012-10-09 15:18:59 +0530216static struct regulator_desc tps65090_regulator_desc[] = {
Javier Martinez Canillas4f2352c2014-07-31 14:31:05 +0200217 tps65090_REG_FIXEDV(DCDC1, "vsys1", 0x0C, BIT(CTRL_EN_BIT), 5000000,
218 tps65090_reg_control_ops),
219 tps65090_REG_FIXEDV(DCDC2, "vsys2", 0x0D, BIT(CTRL_EN_BIT), 3300000,
220 tps65090_reg_control_ops),
221 tps65090_REG_SWITCH(DCDC3, "vsys3", 0x0E, BIT(CTRL_EN_BIT),
222 tps65090_reg_control_ops),
Doug Andersoned11f1e2014-04-23 08:56:05 -0700223
Javier Martinez Canillas4f2352c2014-07-31 14:31:05 +0200224 tps65090_REG_SWITCH(FET1, "infet1", 0x0F,
225 BIT(CTRL_EN_BIT) | BIT(CTRL_PG_BIT),
226 tps65090_fet_control_ops),
227 tps65090_REG_SWITCH(FET2, "infet2", 0x10,
228 BIT(CTRL_EN_BIT) | BIT(CTRL_PG_BIT),
229 tps65090_fet_control_ops),
230 tps65090_REG_SWITCH(FET3, "infet3", 0x11,
231 BIT(CTRL_EN_BIT) | BIT(CTRL_PG_BIT),
232 tps65090_fet_control_ops),
233 tps65090_REG_SWITCH(FET4, "infet4", 0x12,
234 BIT(CTRL_EN_BIT) | BIT(CTRL_PG_BIT),
235 tps65090_fet_control_ops),
236 tps65090_REG_SWITCH(FET5, "infet5", 0x13,
237 BIT(CTRL_EN_BIT) | BIT(CTRL_PG_BIT),
238 tps65090_fet_control_ops),
239 tps65090_REG_SWITCH(FET6, "infet6", 0x14,
240 BIT(CTRL_EN_BIT) | BIT(CTRL_PG_BIT),
241 tps65090_fet_control_ops),
242 tps65090_REG_SWITCH(FET7, "infet7", 0x15,
243 BIT(CTRL_EN_BIT) | BIT(CTRL_PG_BIT),
244 tps65090_fet_control_ops),
Doug Andersoned11f1e2014-04-23 08:56:05 -0700245
Javier Martinez Canillas4f2352c2014-07-31 14:31:05 +0200246 tps65090_REG_FIXEDV(LDO1, "vsys-l1", 0, 0, 5000000,
247 tps65090_ldo_ops),
248 tps65090_REG_FIXEDV(LDO2, "vsys-l2", 0, 0, 3300000,
249 tps65090_ldo_ops),
Venu Byravarasu452534e2012-03-22 18:34:09 +0530250};
251
Laxman Dewangan24282a12012-10-09 15:18:59 +0530252static inline bool is_dcdc(int id)
Venu Byravarasu452534e2012-03-22 18:34:09 +0530253{
Laxman Dewangan24282a12012-10-09 15:18:59 +0530254 switch (id) {
Laxman Dewangan8620ca92012-10-09 15:19:00 +0530255 case TPS65090_REGULATOR_DCDC1:
256 case TPS65090_REGULATOR_DCDC2:
257 case TPS65090_REGULATOR_DCDC3:
Laxman Dewangan24282a12012-10-09 15:18:59 +0530258 return true;
259 default:
260 return false;
Venu Byravarasu452534e2012-03-22 18:34:09 +0530261 }
Laxman Dewangan24282a12012-10-09 15:18:59 +0530262}
263
Bill Pembertona5023572012-11-19 13:22:22 -0500264static int tps65090_config_ext_control(
Laxman Dewangan24282a12012-10-09 15:18:59 +0530265 struct tps65090_regulator *ri, bool enable)
266{
267 int ret;
268 struct device *parent = ri->dev->parent;
269 unsigned int reg_en_reg = ri->desc->enable_reg;
270
271 if (enable)
272 ret = tps65090_set_bits(parent, reg_en_reg, 1);
273 else
274 ret = tps65090_clr_bits(parent, reg_en_reg, 1);
275 if (ret < 0)
276 dev_err(ri->dev, "Error in updating reg 0x%x\n", reg_en_reg);
277 return ret;
278}
279
Bill Pembertona5023572012-11-19 13:22:22 -0500280static int tps65090_regulator_disable_ext_control(
Laxman Dewangan24282a12012-10-09 15:18:59 +0530281 struct tps65090_regulator *ri,
282 struct tps65090_regulator_plat_data *tps_pdata)
283{
284 int ret = 0;
285 struct device *parent = ri->dev->parent;
286 unsigned int reg_en_reg = ri->desc->enable_reg;
287
288 /*
289 * First enable output for internal control if require.
290 * And then disable external control.
291 */
292 if (tps_pdata->reg_init_data->constraints.always_on ||
293 tps_pdata->reg_init_data->constraints.boot_on) {
294 ret = tps65090_set_bits(parent, reg_en_reg, 0);
295 if (ret < 0) {
296 dev_err(ri->dev, "Error in set reg 0x%x\n", reg_en_reg);
297 return ret;
298 }
299 }
300 return tps65090_config_ext_control(ri, false);
Venu Byravarasu452534e2012-03-22 18:34:09 +0530301}
302
Bill Pembertona5023572012-11-19 13:22:22 -0500303static void tps65090_configure_regulator_config(
Laxman Dewanganf329b172012-10-09 15:19:02 +0530304 struct tps65090_regulator_plat_data *tps_pdata,
305 struct regulator_config *config)
306{
307 if (gpio_is_valid(tps_pdata->gpio)) {
308 int gpio_flag = GPIOF_OUT_INIT_LOW;
309
310 if (tps_pdata->reg_init_data->constraints.always_on ||
311 tps_pdata->reg_init_data->constraints.boot_on)
312 gpio_flag = GPIOF_OUT_INIT_HIGH;
313
314 config->ena_gpio = tps_pdata->gpio;
Markus Pargmann1de38212014-11-03 19:12:04 +0100315 config->ena_gpio_initialized = true;
Laxman Dewanganf329b172012-10-09 15:19:02 +0530316 config->ena_gpio_flags = gpio_flag;
317 }
318}
319
Laxman Dewangan6c7a7a02013-01-29 14:35:16 +0530320#ifdef CONFIG_OF
321static struct of_regulator_match tps65090_matches[] = {
322 { .name = "dcdc1", },
323 { .name = "dcdc2", },
324 { .name = "dcdc3", },
325 { .name = "fet1", },
326 { .name = "fet2", },
327 { .name = "fet3", },
328 { .name = "fet4", },
329 { .name = "fet5", },
330 { .name = "fet6", },
331 { .name = "fet7", },
332 { .name = "ldo1", },
333 { .name = "ldo2", },
334};
335
336static struct tps65090_platform_data *tps65090_parse_dt_reg_data(
337 struct platform_device *pdev,
338 struct of_regulator_match **tps65090_reg_matches)
339{
340 struct tps65090_platform_data *tps65090_pdata;
341 struct device_node *np = pdev->dev.parent->of_node;
342 struct device_node *regulators;
343 int idx = 0, ret;
344 struct tps65090_regulator_plat_data *reg_pdata;
345
346 tps65090_pdata = devm_kzalloc(&pdev->dev, sizeof(*tps65090_pdata),
347 GFP_KERNEL);
Sachin Kamat0ad91c62014-02-20 14:23:15 +0530348 if (!tps65090_pdata)
Laxman Dewangan6c7a7a02013-01-29 14:35:16 +0530349 return ERR_PTR(-ENOMEM);
Laxman Dewangan6c7a7a02013-01-29 14:35:16 +0530350
351 reg_pdata = devm_kzalloc(&pdev->dev, TPS65090_REGULATOR_MAX *
352 sizeof(*reg_pdata), GFP_KERNEL);
Sachin Kamat0ad91c62014-02-20 14:23:15 +0530353 if (!reg_pdata)
Laxman Dewangan6c7a7a02013-01-29 14:35:16 +0530354 return ERR_PTR(-ENOMEM);
Laxman Dewangan6c7a7a02013-01-29 14:35:16 +0530355
Laxman Dewangan4c850ea2013-10-08 19:31:02 +0530356 regulators = of_get_child_by_name(np, "regulators");
Laxman Dewangan6c7a7a02013-01-29 14:35:16 +0530357 if (!regulators) {
358 dev_err(&pdev->dev, "regulator node not found\n");
359 return ERR_PTR(-ENODEV);
360 }
361
Axel Lin09a228e2013-01-30 20:28:20 +0800362 ret = of_regulator_match(&pdev->dev, regulators, tps65090_matches,
Laxman Dewangan6c7a7a02013-01-29 14:35:16 +0530363 ARRAY_SIZE(tps65090_matches));
Sachin Kamat026cdfe2014-02-17 14:33:37 +0530364 of_node_put(regulators);
Laxman Dewangan6c7a7a02013-01-29 14:35:16 +0530365 if (ret < 0) {
366 dev_err(&pdev->dev,
367 "Error parsing regulator init data: %d\n", ret);
368 return ERR_PTR(ret);
369 }
370
371 *tps65090_reg_matches = tps65090_matches;
372 for (idx = 0; idx < ARRAY_SIZE(tps65090_matches); idx++) {
373 struct regulator_init_data *ri_data;
374 struct tps65090_regulator_plat_data *rpdata;
375
376 rpdata = &reg_pdata[idx];
377 ri_data = tps65090_matches[idx].init_data;
378 if (!ri_data || !tps65090_matches[idx].of_node)
379 continue;
380
381 rpdata->reg_init_data = ri_data;
382 rpdata->enable_ext_control = of_property_read_bool(
383 tps65090_matches[idx].of_node,
384 "ti,enable-ext-control");
385 if (rpdata->enable_ext_control)
386 rpdata->gpio = of_get_named_gpio(np,
387 "dcdc-ext-control-gpios", 0);
388
Doug Anderson29041442014-04-16 16:12:28 -0700389 if (of_property_read_u32(tps65090_matches[idx].of_node,
390 "ti,overcurrent-wait",
391 &rpdata->overcurrent_wait) == 0)
392 rpdata->overcurrent_wait_valid = true;
393
Laxman Dewangan6c7a7a02013-01-29 14:35:16 +0530394 tps65090_pdata->reg_pdata[idx] = rpdata;
395 }
396 return tps65090_pdata;
397}
398#else
399static inline struct tps65090_platform_data *tps65090_parse_dt_reg_data(
400 struct platform_device *pdev,
401 struct of_regulator_match **tps65090_reg_matches)
402{
403 *tps65090_reg_matches = NULL;
404 return NULL;
405}
406#endif
407
Bill Pembertona5023572012-11-19 13:22:22 -0500408static int tps65090_regulator_probe(struct platform_device *pdev)
Venu Byravarasu452534e2012-03-22 18:34:09 +0530409{
Axel Lin06c49982012-04-17 17:08:56 +0800410 struct tps65090 *tps65090_mfd = dev_get_drvdata(pdev->dev.parent);
Venu Byravarasu452534e2012-03-22 18:34:09 +0530411 struct tps65090_regulator *ri = NULL;
Mark Brownc1727082012-04-04 00:50:22 +0100412 struct regulator_config config = { };
Venu Byravarasu452534e2012-03-22 18:34:09 +0530413 struct regulator_dev *rdev;
Laxman Dewangan24282a12012-10-09 15:18:59 +0530414 struct tps65090_regulator_plat_data *tps_pdata;
415 struct tps65090_regulator *pmic;
416 struct tps65090_platform_data *tps65090_pdata;
Laxman Dewangan6c7a7a02013-01-29 14:35:16 +0530417 struct of_regulator_match *tps65090_reg_matches = NULL;
Laxman Dewangan24282a12012-10-09 15:18:59 +0530418 int num;
419 int ret;
Venu Byravarasu452534e2012-03-22 18:34:09 +0530420
Laxman Dewangan24282a12012-10-09 15:18:59 +0530421 dev_dbg(&pdev->dev, "Probing regulator\n");
Venu Byravarasu452534e2012-03-22 18:34:09 +0530422
Laxman Dewangan24282a12012-10-09 15:18:59 +0530423 tps65090_pdata = dev_get_platdata(pdev->dev.parent);
Laxman Dewangan6c7a7a02013-01-29 14:35:16 +0530424 if (!tps65090_pdata && tps65090_mfd->dev->of_node)
425 tps65090_pdata = tps65090_parse_dt_reg_data(pdev,
426 &tps65090_reg_matches);
427 if (IS_ERR_OR_NULL(tps65090_pdata)) {
Laxman Dewangan24282a12012-10-09 15:18:59 +0530428 dev_err(&pdev->dev, "Platform data missing\n");
Laxman Dewangan6c7a7a02013-01-29 14:35:16 +0530429 return tps65090_pdata ? PTR_ERR(tps65090_pdata) : -EINVAL;
Venu Byravarasu452534e2012-03-22 18:34:09 +0530430 }
Venu Byravarasu452534e2012-03-22 18:34:09 +0530431
Laxman Dewangan8620ca92012-10-09 15:19:00 +0530432 pmic = devm_kzalloc(&pdev->dev, TPS65090_REGULATOR_MAX * sizeof(*pmic),
Laxman Dewangan24282a12012-10-09 15:18:59 +0530433 GFP_KERNEL);
Sachin Kamat0ad91c62014-02-20 14:23:15 +0530434 if (!pmic)
Laxman Dewangan24282a12012-10-09 15:18:59 +0530435 return -ENOMEM;
Venu Byravarasu452534e2012-03-22 18:34:09 +0530436
Laxman Dewangan8620ca92012-10-09 15:19:00 +0530437 for (num = 0; num < TPS65090_REGULATOR_MAX; num++) {
Laxman Dewangan24282a12012-10-09 15:18:59 +0530438 tps_pdata = tps65090_pdata->reg_pdata[num];
439
440 ri = &pmic[num];
441 ri->dev = &pdev->dev;
442 ri->desc = &tps65090_regulator_desc[num];
Doug Andersonc122c5b2014-05-01 11:50:16 -0700443 if (tps_pdata) {
444 ri->overcurrent_wait_valid =
445 tps_pdata->overcurrent_wait_valid;
446 ri->overcurrent_wait = tps_pdata->overcurrent_wait;
447 }
Laxman Dewangan24282a12012-10-09 15:18:59 +0530448
449 /*
450 * TPS5090 DCDC support the control from external digital input.
Laxman Dewanganf329b172012-10-09 15:19:02 +0530451 * Configure it as per platform data.
Laxman Dewangan24282a12012-10-09 15:18:59 +0530452 */
453 if (tps_pdata && is_dcdc(num) && tps_pdata->reg_init_data) {
Laxman Dewanganf329b172012-10-09 15:19:02 +0530454 if (tps_pdata->enable_ext_control) {
455 tps65090_configure_regulator_config(
456 tps_pdata, &config);
457 ri->desc->ops = &tps65090_ext_control_ops;
458 } else {
459 ret = tps65090_regulator_disable_ext_control(
Laxman Dewangan24282a12012-10-09 15:18:59 +0530460 ri, tps_pdata);
Laxman Dewanganf329b172012-10-09 15:19:02 +0530461 if (ret < 0) {
462 dev_err(&pdev->dev,
Laxman Dewangan24282a12012-10-09 15:18:59 +0530463 "failed disable ext control\n");
Sachin Kamat9738efa2013-09-04 17:17:48 +0530464 return ret;
Laxman Dewanganf329b172012-10-09 15:19:02 +0530465 }
Laxman Dewangan24282a12012-10-09 15:18:59 +0530466 }
467 }
Laxman Dewanganf329b172012-10-09 15:19:02 +0530468
Laxman Dewangan6c7a7a02013-01-29 14:35:16 +0530469 config.dev = pdev->dev.parent;
Laxman Dewangan24282a12012-10-09 15:18:59 +0530470 config.driver_data = ri;
471 config.regmap = tps65090_mfd->rmap;
472 if (tps_pdata)
473 config.init_data = tps_pdata->reg_init_data;
474 else
475 config.init_data = NULL;
Laxman Dewangan6c7a7a02013-01-29 14:35:16 +0530476 if (tps65090_reg_matches)
477 config.of_node = tps65090_reg_matches[num].of_node;
478 else
479 config.of_node = NULL;
Laxman Dewangan24282a12012-10-09 15:18:59 +0530480
Sachin Kamat9738efa2013-09-04 17:17:48 +0530481 rdev = devm_regulator_register(&pdev->dev, ri->desc, &config);
Laxman Dewangan24282a12012-10-09 15:18:59 +0530482 if (IS_ERR(rdev)) {
483 dev_err(&pdev->dev, "failed to register regulator %s\n",
484 ri->desc->name);
Sachin Kamat9738efa2013-09-04 17:17:48 +0530485 return PTR_ERR(rdev);
Laxman Dewangan24282a12012-10-09 15:18:59 +0530486 }
487 ri->rdev = rdev;
Laxman Dewanganf329b172012-10-09 15:19:02 +0530488
Doug Anderson29041442014-04-16 16:12:28 -0700489 if (ri->overcurrent_wait_valid) {
490 ret = tps65090_reg_set_overcurrent_wait(ri, rdev);
491 if (ret < 0)
492 return ret;
493 }
494
Laxman Dewanganf329b172012-10-09 15:19:02 +0530495 /* Enable external control if it is require */
496 if (tps_pdata && is_dcdc(num) && tps_pdata->reg_init_data &&
497 tps_pdata->enable_ext_control) {
498 ret = tps65090_config_ext_control(ri, true);
Sachin Kamat9738efa2013-09-04 17:17:48 +0530499 if (ret < 0)
500 return ret;
Laxman Dewanganf329b172012-10-09 15:19:02 +0530501 }
Laxman Dewangan24282a12012-10-09 15:18:59 +0530502 }
503
504 platform_set_drvdata(pdev, pmic);
Venu Byravarasu452534e2012-03-22 18:34:09 +0530505 return 0;
Venu Byravarasu452534e2012-03-22 18:34:09 +0530506}
507
508static struct platform_driver tps65090_regulator_driver = {
509 .driver = {
Laxman Dewangan8620ca92012-10-09 15:19:00 +0530510 .name = "tps65090-pmic",
Venu Byravarasu452534e2012-03-22 18:34:09 +0530511 .owner = THIS_MODULE,
512 },
513 .probe = tps65090_regulator_probe,
Venu Byravarasu452534e2012-03-22 18:34:09 +0530514};
515
516static int __init tps65090_regulator_init(void)
517{
518 return platform_driver_register(&tps65090_regulator_driver);
519}
520subsys_initcall(tps65090_regulator_init);
521
522static void __exit tps65090_regulator_exit(void)
523{
524 platform_driver_unregister(&tps65090_regulator_driver);
525}
526module_exit(tps65090_regulator_exit);
527
528MODULE_DESCRIPTION("tps65090 regulator driver");
529MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>");
530MODULE_LICENSE("GPL v2");
Axel Lind95420b2012-11-23 23:47:16 +0800531MODULE_ALIAS("platform:tps65090-pmic");