aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/Kconfig21
-rw-r--r--drivers/regulator/Makefile2
-rw-r--r--drivers/regulator/da9055-regulator.c683
-rw-r--r--drivers/regulator/tps51632-regulator.c332
4 files changed, 1038 insertions, 0 deletions
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 67d47b59a66d..10b1edc89621 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -109,6 +109,16 @@ config REGULATOR_DA9052
109 This driver supports the voltage regulators of DA9052-BC and 109 This driver supports the voltage regulators of DA9052-BC and
110 DA9053-AA/Bx PMIC. 110 DA9053-AA/Bx PMIC.
111 111
112config REGULATOR_DA9055
113 tristate "Dialog Semiconductor DA9055 regulators"
114 depends on MFD_DA9055
115 help
116 Say y here to support the BUCKs and LDOs regulators found on
117 Dialog Semiconductor DA9055 PMIC.
118
119 This driver can also be built as a module. If so, the module
120 will be called da9055-regulator.
121
112config REGULATOR_FAN53555 122config REGULATOR_FAN53555
113 tristate "Fairchild FAN53555 Regulator" 123 tristate "Fairchild FAN53555 Regulator"
114 depends on I2C 124 depends on I2C
@@ -335,6 +345,17 @@ config REGULATOR_PALMAS
335 on the muxing. This is handled automatically in the driver by 345 on the muxing. This is handled automatically in the driver by
336 reading the mux info from OTP. 346 reading the mux info from OTP.
337 347
348config REGULATOR_TPS51632
349 tristate "TI TPS51632 Power Regulator"
350 depends on I2C
351 select REGMAP_I2C
352 help
353 This driver supports TPS51632 voltage regulator chip.
354 The TPS51632 is 3-2-1 Phase D-Cap+ Step Down Driverless Controller
355 with Serial VID control and DVFS.
356 The voltage output can be configure through I2C interface or PWM
357 interface.
358
338config REGULATOR_TPS6105X 359config REGULATOR_TPS6105X
339 tristate "TI TPS6105X Power regulators" 360 tristate "TI TPS6105X Power regulators"
340 depends on TPS6105X 361 depends on TPS6105X
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index e431eed8a878..bdaca617e2f2 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o
18obj-$(CONFIG_REGULATOR_ARIZONA) += arizona-micsupp.o arizona-ldo1.o 18obj-$(CONFIG_REGULATOR_ARIZONA) += arizona-micsupp.o arizona-ldo1.o
19obj-$(CONFIG_REGULATOR_DA903X) += da903x.o 19obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
20obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o 20obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o
21obj-$(CONFIG_REGULATOR_DA9055) += da9055-regulator.o
21obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o 22obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o
22obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o 23obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o
23obj-$(CONFIG_REGULATOR_FAN53555) += fan53555.o 24obj-$(CONFIG_REGULATOR_FAN53555) += fan53555.o
@@ -41,6 +42,7 @@ obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o
41obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o 42obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
42obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o 43obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o
43obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o 44obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o
45obj-$(CONFIG_REGULATOR_TPS51632) += tps51632-regulator.o
44obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o 46obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o
45obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o 47obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o
46obj-$(CONFIG_REGULATOR_RC5T583) += rc5t583-regulator.o 48obj-$(CONFIG_REGULATOR_RC5T583) += rc5t583-regulator.o
diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c
new file mode 100644
index 000000000000..121564bb5415
--- /dev/null
+++ b/drivers/regulator/da9055-regulator.c
@@ -0,0 +1,683 @@
1/*
2* Regulator driver for DA9055 PMIC
3*
4* Copyright(c) 2012 Dialog Semiconductor Ltd.
5*
6* Author: David Dajun Chen <dchen@diasemi.com>
7*
8* This program is free software; you can redistribute it and/or modify
9* it under the terms of the GNU General Public License as published by
10* the Free Software Foundation; either version 2 of the License, or
11* (at your option) any later version.
12*
13*/
14
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/err.h>
18#include <linux/gpio.h>
19#include <linux/platform_device.h>
20#include <linux/regulator/driver.h>
21#include <linux/regulator/machine.h>
22
23#include <linux/mfd/da9055/core.h>
24#include <linux/mfd/da9055/reg.h>
25#include <linux/mfd/da9055/pdata.h>
26
27#define DA9055_MIN_UA 0
28#define DA9055_MAX_UA 3
29
30#define DA9055_LDO_MODE_SYNC 0
31#define DA9055_LDO_MODE_SLEEP 1
32
33#define DA9055_BUCK_MODE_SLEEP 1
34#define DA9055_BUCK_MODE_SYNC 2
35#define DA9055_BUCK_MODE_AUTO 3
36
37/* DA9055 REGULATOR IDs */
38#define DA9055_ID_BUCK1 0
39#define DA9055_ID_BUCK2 1
40#define DA9055_ID_LDO1 2
41#define DA9055_ID_LDO2 3
42#define DA9055_ID_LDO3 4
43#define DA9055_ID_LDO4 5
44#define DA9055_ID_LDO5 6
45#define DA9055_ID_LDO6 7
46
47/* DA9055 BUCK current limit */
48static const int da9055_current_limits[] = { 500000, 600000, 700000, 800000 };
49
50struct da9055_conf_reg {
51 int reg;
52 int sel_mask;
53 int en_mask;
54};
55
56struct da9055_volt_reg {
57 int reg_a;
58 int reg_b;
59 int sl_shift;
60 int v_offset;
61 int v_mask;
62 int v_shift;
63};
64
65struct da9055_mode_reg {
66 int reg;
67 int mask;
68 int shift;
69};
70
71struct da9055_regulator_info {
72 struct regulator_desc reg_desc;
73 struct da9055_conf_reg conf;
74 struct da9055_volt_reg volt;
75 struct da9055_mode_reg mode;
76};
77
78struct da9055_regulator {
79 struct da9055 *da9055;
80 struct da9055_regulator_info *info;
81 struct regulator_dev *rdev;
82 enum gpio_select reg_rselect;
83};
84
85static unsigned int da9055_buck_get_mode(struct regulator_dev *rdev)
86{
87 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
88 struct da9055_regulator_info *info = regulator->info;
89 int ret, mode = 0;
90
91 ret = da9055_reg_read(regulator->da9055, info->mode.reg);
92 if (ret < 0)
93 return ret;
94
95 switch ((ret & info->mode.mask) >> info->mode.shift) {
96 case DA9055_BUCK_MODE_SYNC:
97 mode = REGULATOR_MODE_FAST;
98 break;
99 case DA9055_BUCK_MODE_AUTO:
100 mode = REGULATOR_MODE_NORMAL;
101 break;
102 case DA9055_BUCK_MODE_SLEEP:
103 mode = REGULATOR_MODE_STANDBY;
104 break;
105 }
106
107 return mode;
108}
109
110static int da9055_buck_set_mode(struct regulator_dev *rdev,
111 unsigned int mode)
112{
113 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
114 struct da9055_regulator_info *info = regulator->info;
115 int val = 0;
116
117 switch (mode) {
118 case REGULATOR_MODE_FAST:
119 val = DA9055_BUCK_MODE_SYNC << info->mode.shift;
120 break;
121 case REGULATOR_MODE_NORMAL:
122 val = DA9055_BUCK_MODE_AUTO << info->mode.shift;
123 break;
124 case REGULATOR_MODE_STANDBY:
125 val = DA9055_BUCK_MODE_SLEEP << info->mode.shift;
126 break;
127 }
128
129 return da9055_reg_update(regulator->da9055, info->mode.reg,
130 info->mode.mask, val);
131}
132
133static unsigned int da9055_ldo_get_mode(struct regulator_dev *rdev)
134{
135 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
136 struct da9055_regulator_info *info = regulator->info;
137 int ret;
138
139 ret = da9055_reg_read(regulator->da9055, info->volt.reg_b);
140 if (ret < 0)
141 return ret;
142
143 if (ret >> info->volt.sl_shift)
144 return REGULATOR_MODE_STANDBY;
145 else
146 return REGULATOR_MODE_NORMAL;
147}
148
149static int da9055_ldo_set_mode(struct regulator_dev *rdev, unsigned int mode)
150{
151 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
152 struct da9055_regulator_info *info = regulator->info;
153 struct da9055_volt_reg volt = info->volt;
154 int val = 0;
155
156 switch (mode) {
157 case REGULATOR_MODE_NORMAL:
158 case REGULATOR_MODE_FAST:
159 val = DA9055_LDO_MODE_SYNC;
160 break;
161 case REGULATOR_MODE_STANDBY:
162 val = DA9055_LDO_MODE_SLEEP;
163 break;
164 }
165
166 return da9055_reg_update(regulator->da9055, volt.reg_b,
167 1 << volt.sl_shift,
168 val << volt.sl_shift);
169}
170
171static int da9055_buck_get_current_limit(struct regulator_dev *rdev)
172{
173 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
174 struct da9055_regulator_info *info = regulator->info;
175 int ret;
176
177 ret = da9055_reg_read(regulator->da9055, DA9055_REG_BUCK_LIM);
178 if (ret < 0)
179 return ret;
180
181 ret &= info->mode.mask;
182 return da9055_current_limits[ret >> info->mode.shift];
183}
184
185static int da9055_buck_set_current_limit(struct regulator_dev *rdev, int min_uA,
186 int max_uA)
187{
188 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
189 struct da9055_regulator_info *info = regulator->info;
190 int i, val = 0;
191
192 if (min_uA > da9055_current_limits[DA9055_MAX_UA] ||
193 max_uA < da9055_current_limits[DA9055_MIN_UA])
194 return -EINVAL;
195
196 for (i = 0; i < ARRAY_SIZE(da9055_current_limits); i++) {
197 if (min_uA <= da9055_current_limits[i]) {
198 val = i;
199 break;
200 }
201 }
202
203 return da9055_reg_update(regulator->da9055, DA9055_REG_BUCK_LIM,
204 info->mode.mask, val << info->mode.shift);
205}
206
207static int da9055_list_voltage(struct regulator_dev *rdev, unsigned selector)
208{
209 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
210 struct da9055_regulator_info *info = regulator->info;
211
212 if (selector >= rdev->desc->n_voltages)
213 return -EINVAL;
214
215 if (selector < info->volt.v_offset)
216 return 0;
217
218 selector -= info->volt.v_offset;
219 return rdev->desc->min_uV + (rdev->desc->uV_step * selector);
220}
221
222static int da9055_map_voltage(struct regulator_dev *rdev, int min_uV,
223 int max_uV)
224{
225 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
226 struct da9055_regulator_info *info = regulator->info;
227 int sel, voltage;
228
229 if (min_uV < rdev->desc->min_uV)
230 min_uV = rdev->desc->min_uV;
231
232 sel = DIV_ROUND_UP(min_uV - rdev->desc->min_uV, rdev->desc->uV_step);
233 sel += info->volt.v_offset;
234
235 voltage = da9055_list_voltage(rdev, sel);
236 if (voltage < min_uV || voltage > max_uV)
237 return -EINVAL;
238
239 return sel;
240}
241
242static int da9055_regulator_get_voltage_sel(struct regulator_dev *rdev)
243{
244 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
245 struct da9055_regulator_info *info = regulator->info;
246 struct da9055_volt_reg volt = info->volt;
247 int ret, sel;
248
249 /*
250 * There are two voltage register set A & B for voltage ramping but
251 * either one of then can be active therefore we first determine
252 * the active register set.
253 */
254 ret = da9055_reg_read(regulator->da9055, info->conf.reg);
255 if (ret < 0)
256 return ret;
257
258 ret &= info->conf.sel_mask;
259
260 /* Get the voltage for the active register set A/B */
261 if (ret == DA9055_REGUALTOR_SET_A)
262 ret = da9055_reg_read(regulator->da9055, volt.reg_a);
263 else
264 ret = da9055_reg_read(regulator->da9055, volt.reg_b);
265
266 if (ret < 0)
267 return ret;
268
269 sel = (ret & volt.v_mask);
270 if (sel <= volt.v_offset)
271 return 0;
272 else
273 return sel;
274}
275
276static int da9055_regulator_set_voltage_sel(struct regulator_dev *rdev,
277 unsigned int selector)
278{
279 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
280 struct da9055_regulator_info *info = regulator->info;
281 int ret;
282
283 /*
284 * Regulator register set A/B is not selected through GPIO therefore
285 * we use default register set A for voltage ramping.
286 */
287 if (regulator->reg_rselect == NO_GPIO) {
288 /* Select register set A */
289 ret = da9055_reg_update(regulator->da9055, info->conf.reg,
290 info->conf.sel_mask, DA9055_SEL_REG_A);
291 if (ret < 0)
292 return ret;
293
294 /* Set the voltage */
295 return da9055_reg_update(regulator->da9055, info->volt.reg_a,
296 info->volt.v_mask, selector);
297 }
298
299 /*
300 * Here regulator register set A/B is selected through GPIO.
301 * Therefore we first determine the selected register set A/B and
302 * then set the desired voltage for that register set A/B.
303 */
304 ret = da9055_reg_read(regulator->da9055, info->conf.reg);
305 if (ret < 0)
306 return ret;
307
308 ret &= info->conf.sel_mask;
309
310 /* Set the voltage */
311 if (ret == DA9055_REGUALTOR_SET_A)
312 return da9055_reg_update(regulator->da9055, info->volt.reg_a,
313 info->volt.v_mask, selector);
314 else
315 return da9055_reg_update(regulator->da9055, info->volt.reg_b,
316 info->volt.v_mask, selector);
317}
318
319static int da9055_regulator_set_suspend_voltage(struct regulator_dev *rdev,
320 int uV)
321{
322 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
323 struct da9055_regulator_info *info = regulator->info;
324 int ret;
325
326 /* Select register set B for suspend voltage ramping. */
327 if (regulator->reg_rselect == NO_GPIO) {
328 ret = da9055_reg_update(regulator->da9055, info->conf.reg,
329 info->conf.sel_mask, DA9055_SEL_REG_B);
330 if (ret < 0)
331 return ret;
332 }
333
334 ret = da9055_map_voltage(rdev, uV, uV);
335 if (ret < 0)
336 return ret;
337
338 return da9055_reg_update(regulator->da9055, info->volt.reg_b,
339 info->volt.v_mask, ret);
340}
341
342static int da9055_suspend_enable(struct regulator_dev *rdev)
343{
344 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
345 struct da9055_regulator_info *info = regulator->info;
346
347 /* Select register set B for voltage ramping. */
348 if (regulator->reg_rselect == NO_GPIO)
349 return da9055_reg_update(regulator->da9055, info->conf.reg,
350 info->conf.sel_mask, DA9055_SEL_REG_B);
351 else
352 return 0;
353}
354
355static int da9055_suspend_disable(struct regulator_dev *rdev)
356{
357 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
358 struct da9055_regulator_info *info = regulator->info;
359
360 /* Diselect register set B. */
361 if (regulator->reg_rselect == NO_GPIO)
362 return da9055_reg_update(regulator->da9055, info->conf.reg,
363 info->conf.sel_mask, DA9055_SEL_REG_A);
364 else
365 return 0;
366}
367
368static struct regulator_ops da9055_buck_ops = {
369 .get_mode = da9055_buck_get_mode,
370 .set_mode = da9055_buck_set_mode,
371
372 .get_current_limit = da9055_buck_get_current_limit,
373 .set_current_limit = da9055_buck_set_current_limit,
374
375 .get_voltage_sel = da9055_regulator_get_voltage_sel,
376 .set_voltage_sel = da9055_regulator_set_voltage_sel,
377 .list_voltage = da9055_list_voltage,
378 .map_voltage = da9055_map_voltage,
379 .is_enabled = regulator_is_enabled_regmap,
380 .enable = regulator_enable_regmap,
381 .disable = regulator_disable_regmap,
382
383 .set_suspend_voltage = da9055_regulator_set_suspend_voltage,
384 .set_suspend_enable = da9055_suspend_enable,
385 .set_suspend_disable = da9055_suspend_disable,
386 .set_suspend_mode = da9055_buck_set_mode,
387};
388
389static struct regulator_ops da9055_ldo_ops = {
390 .get_mode = da9055_ldo_get_mode,
391 .set_mode = da9055_ldo_set_mode,
392
393 .get_voltage_sel = da9055_regulator_get_voltage_sel,
394 .set_voltage_sel = da9055_regulator_set_voltage_sel,
395 .list_voltage = da9055_list_voltage,
396 .map_voltage = da9055_map_voltage,
397 .is_enabled = regulator_is_enabled_regmap,
398 .enable = regulator_enable_regmap,
399 .disable = regulator_disable_regmap,
400
401 .set_suspend_voltage = da9055_regulator_set_suspend_voltage,
402 .set_suspend_enable = da9055_suspend_enable,
403 .set_suspend_disable = da9055_suspend_disable,
404 .set_suspend_mode = da9055_ldo_set_mode,
405
406};
407
408#define DA9055_LDO(_id, step, min, max, vbits, voffset) \
409{\
410 .reg_desc = {\
411 .name = #_id,\
412 .ops = &da9055_ldo_ops,\
413 .type = REGULATOR_VOLTAGE,\
414 .id = DA9055_ID_##_id,\
415 .n_voltages = (max - min) / step + 1 + (voffset), \
416 .enable_reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
417 .enable_mask = 1, \
418 .min_uV = (min) * 1000,\
419 .uV_step = (step) * 1000,\
420 .owner = THIS_MODULE,\
421 },\
422 .conf = {\
423 .reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
424 .sel_mask = (1 << 4),\
425 .en_mask = 1,\
426 },\
427 .volt = {\
428 .reg_a = DA9055_REG_VBCORE_A + DA9055_ID_##_id, \
429 .reg_b = DA9055_REG_VBCORE_B + DA9055_ID_##_id, \
430 .sl_shift = 7,\
431 .v_offset = (voffset),\
432 .v_mask = (1 << (vbits)) - 1,\
433 .v_shift = (vbits),\
434 },\
435}
436
437#define DA9055_BUCK(_id, step, min, max, vbits, voffset, mbits, sbits) \
438{\
439 .reg_desc = {\
440 .name = #_id,\
441 .ops = &da9055_buck_ops,\
442 .type = REGULATOR_VOLTAGE,\
443 .id = DA9055_ID_##_id,\
444 .n_voltages = (max - min) / step + 1 + (voffset), \
445 .enable_reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
446 .enable_mask = 1,\
447 .min_uV = (min) * 1000,\
448 .uV_step = (step) * 1000,\
449 .owner = THIS_MODULE,\
450 },\
451 .conf = {\
452 .reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
453 .sel_mask = (1 << 4),\
454 .en_mask = 1,\
455 },\
456 .volt = {\
457 .reg_a = DA9055_REG_VBCORE_A + DA9055_ID_##_id, \
458 .reg_b = DA9055_REG_VBCORE_B + DA9055_ID_##_id, \
459 .sl_shift = 7,\
460 .v_offset = (voffset),\
461 .v_mask = (1 << (vbits)) - 1,\
462 .v_shift = (vbits),\
463 },\
464 .mode = {\
465 .reg = DA9055_REG_BCORE_MODE,\
466 .mask = (mbits),\
467 .shift = (sbits),\
468 },\
469}
470
471static struct da9055_regulator_info da9055_regulator_info[] = {
472 DA9055_BUCK(BUCK1, 25, 725, 2075, 6, 9, 0xc, 2),
473 DA9055_BUCK(BUCK2, 25, 925, 2500, 6, 0, 3, 0),
474 DA9055_LDO(LDO1, 50, 900, 3300, 6, 2),
475 DA9055_LDO(LDO2, 50, 900, 3300, 6, 3),
476 DA9055_LDO(LDO3, 50, 900, 3300, 6, 2),
477 DA9055_LDO(LDO4, 50, 900, 3300, 6, 2),
478 DA9055_LDO(LDO5, 50, 900, 2750, 6, 2),
479 DA9055_LDO(LDO6, 20, 900, 3300, 7, 0),
480};
481
482/*
483 * Configures regulator to be controlled either through GPIO 1 or 2.
484 * GPIO can control regulator state and/or select the regulator register
485 * set A/B for voltage ramping.
486 */
487static __devinit int da9055_gpio_init(struct da9055_regulator *regulator,
488 struct regulator_config *config,
489 struct da9055_pdata *pdata, int id)
490{
491 struct da9055_regulator_info *info = regulator->info;
492 int ret = 0;
493
494 if (pdata->gpio_ren && pdata->gpio_ren[id]) {
495 char name[18];
496 int gpio_mux = pdata->gpio_ren[id];
497
498 config->ena_gpio = pdata->ena_gpio[id];
499 config->ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
500 config->ena_gpio_invert = 1;
501
502 /*
503 * GPI pin is muxed with regulator to control the
504 * regulator state.
505 */
506 sprintf(name, "DA9055 GPI %d", gpio_mux);
507 ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN,
508 name);
509 if (ret < 0)
510 goto err;
511
512 /*
513 * Let the regulator know that its state is controlled
514 * through GPI.
515 */
516 ret = da9055_reg_update(regulator->da9055, info->conf.reg,
517 DA9055_E_GPI_MASK,
518 pdata->reg_ren[id]
519 << DA9055_E_GPI_SHIFT);
520 if (ret < 0)
521 goto err;
522 }
523
524 if (pdata->gpio_rsel && pdata->gpio_rsel[id]) {
525 char name[18];
526 int gpio_mux = pdata->gpio_rsel[id];
527
528 regulator->reg_rselect = pdata->reg_rsel[id];
529
530 /*
531 * GPI pin is muxed with regulator to select the
532 * regulator register set A/B for voltage ramping.
533 */
534 sprintf(name, "DA9055 GPI %d", gpio_mux);
535 ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN,
536 name);
537 if (ret < 0)
538 goto err;
539
540 /*
541 * Let the regulator know that its register set A/B
542 * will be selected through GPI for voltage ramping.
543 */
544 ret = da9055_reg_update(regulator->da9055, info->conf.reg,
545 DA9055_V_GPI_MASK,
546 pdata->reg_rsel[id]
547 << DA9055_V_GPI_SHIFT);
548 }
549
550err:
551 return ret;
552}
553
554static irqreturn_t da9055_ldo5_6_oc_irq(int irq, void *data)
555{
556 struct da9055_regulator *regulator = data;
557
558 regulator_notifier_call_chain(regulator->rdev,
559 REGULATOR_EVENT_OVER_CURRENT, NULL);
560
561 return IRQ_HANDLED;
562}
563
564static inline struct da9055_regulator_info *find_regulator_info(int id)
565{
566 struct da9055_regulator_info *info;
567 int i;
568
569 for (i = 0; i < ARRAY_SIZE(da9055_regulator_info); i++) {
570 info = &da9055_regulator_info[i];
571 if (info->reg_desc.id == id)
572 return info;
573 }
574
575 return NULL;
576}
577
578static int __devinit da9055_regulator_probe(struct platform_device *pdev)
579{
580 struct regulator_config config = { };
581 struct da9055_regulator *regulator;
582 struct da9055 *da9055 = dev_get_drvdata(pdev->dev.parent);
583 struct da9055_pdata *pdata = da9055->dev->platform_data;
584 int ret, irq;
585
586 if (pdata == NULL || pdata->regulators[pdev->id] == NULL)
587 return -ENODEV;
588
589 regulator = devm_kzalloc(&pdev->dev, sizeof(struct da9055_regulator),
590 GFP_KERNEL);
591 if (!regulator)
592 return -ENOMEM;
593
594 regulator->info = find_regulator_info(pdev->id);
595 if (regulator->info == NULL) {
596 dev_err(&pdev->dev, "invalid regulator ID specified\n");
597 return -EINVAL;
598 }
599
600 regulator->da9055 = da9055;
601 config.dev = &pdev->dev;
602 config.driver_data = regulator;
603 config.regmap = da9055->regmap;
604
605 if (pdata && pdata->regulators)
606 config.init_data = pdata->regulators[pdev->id];
607
608 ret = da9055_gpio_init(regulator, &config, pdata, pdev->id);
609 if (ret < 0)
610 return ret;
611
612 regulator->rdev = regulator_register(&regulator->info->reg_desc,
613 &config);
614 if (IS_ERR(regulator->rdev)) {
615 dev_err(&pdev->dev, "Failed to register regulator %s\n",
616 regulator->info->reg_desc.name);
617 ret = PTR_ERR(regulator->rdev);
618 return ret;
619 }
620
621 /* Only LDO 5 and 6 has got the over current interrupt */
622 if (pdev->id == DA9055_ID_LDO5 || pdev->id == DA9055_ID_LDO6) {
623 irq = platform_get_irq_byname(pdev, "REGULATOR");
624 irq = regmap_irq_get_virq(da9055->irq_data, irq);
625 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
626 da9055_ldo5_6_oc_irq,
627 IRQF_TRIGGER_HIGH |
628 IRQF_ONESHOT |
629 IRQF_PROBE_SHARED,
630 pdev->name, regulator);
631 if (ret != 0) {
632 if (ret != -EBUSY) {
633 dev_err(&pdev->dev,
634 "Failed to request Regulator IRQ %d: %d\n",
635 irq, ret);
636 goto err_regulator;
637 }
638 }
639 }
640
641 platform_set_drvdata(pdev, regulator);
642
643 return 0;
644
645err_regulator:
646 regulator_unregister(regulator->rdev);
647 return ret;
648}
649
650static int __devexit da9055_regulator_remove(struct platform_device *pdev)
651{
652 struct da9055_regulator *regulator = platform_get_drvdata(pdev);
653
654 regulator_unregister(regulator->rdev);
655
656 return 0;
657}
658
659static struct platform_driver da9055_regulator_driver = {
660 .probe = da9055_regulator_probe,
661 .remove = __devexit_p(da9055_regulator_remove),
662 .driver = {
663 .name = "da9055-regulator",
664 .owner = THIS_MODULE,
665 },
666};
667
668static int __init da9055_regulator_init(void)
669{
670 return platform_driver_register(&da9055_regulator_driver);
671}
672subsys_initcall(da9055_regulator_init);
673
674static void __exit da9055_regulator_exit(void)
675{
676 platform_driver_unregister(&da9055_regulator_driver);
677}
678module_exit(da9055_regulator_exit);
679
680MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
681MODULE_DESCRIPTION("Power Regulator driver for Dialog DA9055 PMIC");
682MODULE_LICENSE("GPL");
683MODULE_ALIAS("platform:da9055-regulator");
diff --git a/drivers/regulator/tps51632-regulator.c b/drivers/regulator/tps51632-regulator.c
new file mode 100644
index 000000000000..34603640d6d9
--- /dev/null
+++ b/drivers/regulator/tps51632-regulator.c
@@ -0,0 +1,332 @@
1/*
2 * tps51632-regulator.c -- TI TPS51632
3 *
4 * Regulator driver for TPS51632 3-2-1 Phase D-Cap Step Down Driverless
5 * Controller with serial VID control and DVFS.
6 *
7 * Copyright (c) 2012, NVIDIA Corporation.
8 *
9 * Author: Laxman Dewangan <ldewangan@nvidia.com>
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation version 2.
14 *
15 * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
16 * whether express or implied; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 * 02111-1307, USA
24 */
25
26#include <linux/err.h>
27#include <linux/i2c.h>
28#include <linux/init.h>
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/platform_device.h>
32#include <linux/regmap.h>
33#include <linux/regulator/driver.h>
34#include <linux/regulator/machine.h>
35#include <linux/regulator/tps51632-regulator.h>
36#include <linux/slab.h>
37
38/* Register definitions */
39#define TPS51632_VOLTAGE_SELECT_REG 0x0
40#define TPS51632_VOLTAGE_BASE_REG 0x1
41#define TPS51632_OFFSET_REG 0x2
42#define TPS51632_IMON_REG 0x3
43#define TPS51632_VMAX_REG 0x4
44#define TPS51632_DVFS_CONTROL_REG 0x5
45#define TPS51632_POWER_STATE_REG 0x6
46#define TPS51632_SLEW_REGS 0x7
47#define TPS51632_FAULT_REG 0x14
48
49#define TPS51632_MAX_REG 0x15
50
51#define TPS51632_VOUT_MASK 0x7F
52#define TPS51632_VOUT_OFFSET_MASK 0x1F
53#define TPS51632_VMAX_MASK 0x7F
54#define TPS51632_VMAX_LOCK 0x80
55
56/* TPS51632_DVFS_CONTROL_REG */
57#define TPS51632_DVFS_PWMEN 0x1
58#define TPS51632_DVFS_STEP_20 0x2
59#define TPS51632_DVFS_VMAX_PG 0x4
60#define TPS51632_DVFS_PWMRST 0x8
61#define TPS51632_DVFS_OCA_EN 0x10
62#define TPS51632_DVFS_FCCM 0x20
63
64/* TPS51632_POWER_STATE_REG */
65#define TPS51632_POWER_STATE_MASK 0x03
66#define TPS51632_POWER_STATE_MULTI_PHASE_CCM 0x0
67#define TPS51632_POWER_STATE_SINGLE_PHASE_CCM 0x1
68#define TPS51632_POWER_STATE_SINGLE_PHASE_DCM 0x2
69
70#define TPS51632_MIN_VOLATGE 500000
71#define TPS51632_MAX_VOLATGE 1520000
72#define TPS51632_VOLATGE_STEP_10mV 10000
73#define TPS51632_VOLATGE_STEP_20mV 20000
74#define TPS51632_MAX_VSEL 0x7F
75#define TPS51632_MIN_VSEL 0x19
76#define TPS51632_DEFAULT_RAMP_DELAY 6000
77#define TPS51632_VOLT_VSEL(uV) \
78 (DIV_ROUND_UP(uV - TPS51632_MIN_VOLATGE, \
79 TPS51632_VOLATGE_STEP_10mV) + \
80 TPS51632_MIN_VSEL)
81
82/* TPS51632 chip information */
83struct tps51632_chip {
84 struct device *dev;
85 struct regulator_desc desc;
86 struct regulator_dev *rdev;
87 struct regmap *regmap;
88 bool enable_pwm_dvfs;
89};
90
91static int tps51632_dcdc_get_voltage_sel(struct regulator_dev *rdev)
92{
93 struct tps51632_chip *tps = rdev_get_drvdata(rdev);
94 unsigned int data;
95 int ret;
96 unsigned int reg = TPS51632_VOLTAGE_SELECT_REG;
97 int vsel;
98
99 if (tps->enable_pwm_dvfs)
100 reg = TPS51632_VOLTAGE_BASE_REG;
101
102 ret = regmap_read(tps->regmap, reg, &data);
103 if (ret < 0) {
104 dev_err(tps->dev, "reg read failed, err %d\n", ret);
105 return ret;
106 }
107
108 vsel = data & TPS51632_VOUT_MASK;
109
110 if (vsel < TPS51632_MIN_VSEL)
111 return 0;
112 else
113 return vsel - TPS51632_MIN_VSEL;
114}
115
116static int tps51632_dcdc_set_voltage_sel(struct regulator_dev *rdev,
117 unsigned selector)
118{
119 struct tps51632_chip *tps = rdev_get_drvdata(rdev);
120 int vsel;
121 int ret;
122 unsigned int reg = TPS51632_VOLTAGE_SELECT_REG;
123
124 if (tps->enable_pwm_dvfs)
125 reg = TPS51632_VOLTAGE_BASE_REG;
126
127 vsel = selector + TPS51632_MIN_VSEL;
128 if (vsel > TPS51632_MAX_VSEL)
129 return -EINVAL;
130
131 ret = regmap_write(tps->regmap, TPS51632_VOLTAGE_SELECT_REG, vsel);
132 if (ret < 0)
133 dev_err(tps->dev, "reg write failed, err %d\n", ret);
134 return ret;
135}
136
137static int tps51632_dcdc_set_ramp_delay(struct regulator_dev *rdev,
138 int ramp_delay)
139{
140 struct tps51632_chip *tps = rdev_get_drvdata(rdev);
141 int bit = ramp_delay/6000;
142 int ret;
143
144 if (bit)
145 bit--;
146 ret = regmap_write(tps->regmap, TPS51632_SLEW_REGS, BIT(bit));
147 if (ret < 0)
148 dev_err(tps->dev, "SLEW reg write failed, err %d\n", ret);
149 return ret;
150}
151
152static struct regulator_ops tps51632_dcdc_ops = {
153 .get_voltage_sel = tps51632_dcdc_get_voltage_sel,
154 .set_voltage_sel = tps51632_dcdc_set_voltage_sel,
155 .list_voltage = regulator_list_voltage_linear,
156 .set_voltage_time_sel = regulator_set_voltage_time_sel,
157 .set_ramp_delay = tps51632_dcdc_set_ramp_delay,
158};
159
160static int __devinit tps51632_init_dcdc(struct tps51632_chip *tps,
161 struct tps51632_regulator_platform_data *pdata)
162{
163 int ret;
164 uint8_t control = 0;
165 int vsel;
166
167 if (!pdata->enable_pwm_dvfs)
168 goto skip_pwm_config;
169
170 control |= TPS51632_DVFS_PWMEN;
171 tps->enable_pwm_dvfs = pdata->enable_pwm_dvfs;
172 vsel = TPS51632_VOLT_VSEL(pdata->base_voltage_uV);
173 ret = regmap_write(tps->regmap, TPS51632_VOLTAGE_BASE_REG, vsel);
174 if (ret < 0) {
175 dev_err(tps->dev, "BASE reg write failed, err %d\n", ret);
176 return ret;
177 }
178
179 if (pdata->dvfs_step_20mV)
180 control |= TPS51632_DVFS_STEP_20;
181
182 if (pdata->max_voltage_uV) {
183 unsigned int vmax;
184 /**
185 * TPS51632 hw behavior: VMAX register can be write only
186 * once as it get locked after first write. The lock get
187 * reset only when device is power-reset.
188 * Write register only when lock bit is not enabled.
189 */
190 ret = regmap_read(tps->regmap, TPS51632_VMAX_REG, &vmax);
191 if (ret < 0) {
192 dev_err(tps->dev, "VMAX read failed, err %d\n", ret);
193 return ret;
194 }
195 if (!(vmax & TPS51632_VMAX_LOCK)) {
196 vsel = TPS51632_VOLT_VSEL(pdata->max_voltage_uV);
197 ret = regmap_write(tps->regmap, TPS51632_VMAX_REG,
198 vsel);
199 if (ret < 0) {
200 dev_err(tps->dev,
201 "VMAX write failed, err %d\n", ret);
202 return ret;
203 }
204 }
205 }
206
207skip_pwm_config:
208 ret = regmap_write(tps->regmap, TPS51632_DVFS_CONTROL_REG, control);
209 if (ret < 0)
210 dev_err(tps->dev, "DVFS reg write failed, err %d\n", ret);
211 return ret;
212}
213
214static bool rd_wr_reg(struct device *dev, unsigned int reg)
215{
216 if ((reg >= 0x8) && (reg <= 0x10))
217 return false;
218 return true;
219}
220
221static const struct regmap_config tps51632_regmap_config = {
222 .reg_bits = 8,
223 .val_bits = 8,
224 .writeable_reg = rd_wr_reg,
225 .readable_reg = rd_wr_reg,
226 .max_register = TPS51632_MAX_REG - 1,
227 .cache_type = REGCACHE_RBTREE,
228};
229
230static int __devinit tps51632_probe(struct i2c_client *client,
231 const struct i2c_device_id *id)
232{
233 struct tps51632_regulator_platform_data *pdata;
234 struct regulator_dev *rdev;
235 struct tps51632_chip *tps;
236 int ret;
237 struct regulator_config config = { };
238
239 pdata = client->dev.platform_data;
240 if (!pdata) {
241 dev_err(&client->dev, "No Platform data\n");
242 return -EINVAL;
243 }
244
245 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
246 if (!tps) {
247 dev_err(&client->dev, "Memory allocation failed\n");
248 return -ENOMEM;
249 }
250
251 tps->dev = &client->dev;
252 tps->desc.name = id->name;
253 tps->desc.id = 0;
254 tps->desc.ramp_delay = TPS51632_DEFAULT_RAMP_DELAY;
255 tps->desc.min_uV = TPS51632_MIN_VOLATGE;
256 tps->desc.uV_step = TPS51632_VOLATGE_STEP_10mV;
257 tps->desc.n_voltages = (TPS51632_MAX_VSEL - TPS51632_MIN_VSEL) + 1;
258 tps->desc.ops = &tps51632_dcdc_ops;
259 tps->desc.type = REGULATOR_VOLTAGE;
260 tps->desc.owner = THIS_MODULE;
261
262 tps->regmap = devm_regmap_init_i2c(client, &tps51632_regmap_config);
263 if (IS_ERR(tps->regmap)) {
264 ret = PTR_ERR(tps->regmap);
265 dev_err(&client->dev, "regmap init failed, err %d\n", ret);
266 return ret;
267 }
268 i2c_set_clientdata(client, tps);
269
270 ret = tps51632_init_dcdc(tps, pdata);
271 if (ret < 0) {
272 dev_err(tps->dev, "Init failed, err = %d\n", ret);
273 return ret;
274 }
275
276 /* Register the regulators */
277 config.dev = &client->dev;
278 config.init_data = pdata->reg_init_data;
279 config.driver_data = tps;
280 config.regmap = tps->regmap;
281 config.of_node = client->dev.of_node;
282
283 rdev = regulator_register(&tps->desc, &config);
284 if (IS_ERR(rdev)) {
285 dev_err(tps->dev, "regulator register failed\n");
286 return PTR_ERR(rdev);
287 }
288
289 tps->rdev = rdev;
290 return 0;
291}
292
293static int __devexit tps51632_remove(struct i2c_client *client)
294{
295 struct tps51632_chip *tps = i2c_get_clientdata(client);
296
297 regulator_unregister(tps->rdev);
298 return 0;
299}
300
301static const struct i2c_device_id tps51632_id[] = {
302 {.name = "tps51632",},
303 {},
304};
305
306MODULE_DEVICE_TABLE(i2c, tps51632_id);
307
308static struct i2c_driver tps51632_i2c_driver = {
309 .driver = {
310 .name = "tps51632",
311 .owner = THIS_MODULE,
312 },
313 .probe = tps51632_probe,
314 .remove = __devexit_p(tps51632_remove),
315 .id_table = tps51632_id,
316};
317
318static int __init tps51632_init(void)
319{
320 return i2c_add_driver(&tps51632_i2c_driver);
321}
322subsys_initcall(tps51632_init);
323
324static void __exit tps51632_cleanup(void)
325{
326 i2c_del_driver(&tps51632_i2c_driver);
327}
328module_exit(tps51632_cleanup);
329
330MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
331MODULE_DESCRIPTION("TPS51632 voltage regulator driver");
332MODULE_LICENSE("GPL v2");