aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator
diff options
context:
space:
mode:
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>2008-10-14 20:31:54 -0400
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2008-10-14 20:31:54 -0400
commit6dc6472581f693b5fc95aebedf67b4960fb85cf0 (patch)
tree06a5a9a08519950575505273eabced331ed51405 /drivers/regulator
parentee673eaa72d8d185012b1027a05e25aba18c267f (diff)
parent8acd3a60bcca17c6d89c73cee3ad6057eb83ba1e (diff)
Merge commit 'origin'
Manual fixup of conflicts on: arch/powerpc/include/asm/dcr-regs.h drivers/net/ibm_newemac/core.h
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/Kconfig24
-rw-r--r--drivers/regulator/Makefile3
-rw-r--r--drivers/regulator/bq24022.c21
-rw-r--r--drivers/regulator/core.c508
-rw-r--r--drivers/regulator/da903x.c513
-rw-r--r--drivers/regulator/wm8350-regulator.c1431
-rw-r--r--drivers/regulator/wm8400-regulator.c368
7 files changed, 2625 insertions, 243 deletions
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index a656128f1fdd..4dada6ee1119 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -56,4 +56,28 @@ config REGULATOR_BQ24022
56 charging select between 100 mA and 500 mA charging current 56 charging select between 100 mA and 500 mA charging current
57 limit. 57 limit.
58 58
59config REGULATOR_WM8350
60 tristate "Wolfson Microelectroncis WM8350 AudioPlus PMIC"
61 depends on MFD_WM8350
62 select REGULATOR
63 help
64 This driver provides support for the voltage and current regulators
65 of the WM8350 AudioPlus PMIC.
66
67config REGULATOR_WM8400
68 tristate "Wolfson Microelectroncis WM8400 AudioPlus PMIC"
69 depends on MFD_WM8400
70 select REGULATOR
71 help
72 This driver provides support for the voltage regulators of the
73 WM8400 AudioPlus PMIC.
74
75config REGULATOR_DA903X
76 tristate "Support regulators on Dialog Semiconductor DA9030/DA9034 PMIC"
77 depends on PMIC_DA903X
78 select REGULATOR
79 help
80 Say y here to support the BUCKs and LDOs regulators found on
81 Dialog Semiconductor DA9030/DA9034 PMIC.
82
59endmenu 83endmenu
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index ac2c64efe65c..254d40c02ee8 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -8,5 +8,8 @@ obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o
8obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o 8obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
9 9
10obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o 10obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o
11obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o
12obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o
13obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
11 14
12ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG 15ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG
diff --git a/drivers/regulator/bq24022.c b/drivers/regulator/bq24022.c
index 263699d6152d..366565aba865 100644
--- a/drivers/regulator/bq24022.c
+++ b/drivers/regulator/bq24022.c
@@ -18,13 +18,13 @@
18#include <linux/regulator/bq24022.h> 18#include <linux/regulator/bq24022.h>
19#include <linux/regulator/driver.h> 19#include <linux/regulator/driver.h>
20 20
21
21static int bq24022_set_current_limit(struct regulator_dev *rdev, 22static int bq24022_set_current_limit(struct regulator_dev *rdev,
22 int min_uA, int max_uA) 23 int min_uA, int max_uA)
23{ 24{
24 struct platform_device *pdev = rdev_get_drvdata(rdev); 25 struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev);
25 struct bq24022_mach_info *pdata = pdev->dev.platform_data;
26 26
27 dev_dbg(&pdev->dev, "setting current limit to %s mA\n", 27 dev_dbg(rdev_get_dev(rdev), "setting current limit to %s mA\n",
28 max_uA >= 500000 ? "500" : "100"); 28 max_uA >= 500000 ? "500" : "100");
29 29
30 /* REVISIT: maybe return error if min_uA != 0 ? */ 30 /* REVISIT: maybe return error if min_uA != 0 ? */
@@ -34,18 +34,16 @@ static int bq24022_set_current_limit(struct regulator_dev *rdev,
34 34
35static int bq24022_get_current_limit(struct regulator_dev *rdev) 35static int bq24022_get_current_limit(struct regulator_dev *rdev)
36{ 36{
37 struct platform_device *pdev = rdev_get_drvdata(rdev); 37 struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev);
38 struct bq24022_mach_info *pdata = pdev->dev.platform_data;
39 38
40 return gpio_get_value(pdata->gpio_iset2) ? 500000 : 100000; 39 return gpio_get_value(pdata->gpio_iset2) ? 500000 : 100000;
41} 40}
42 41
43static int bq24022_enable(struct regulator_dev *rdev) 42static int bq24022_enable(struct regulator_dev *rdev)
44{ 43{
45 struct platform_device *pdev = rdev_get_drvdata(rdev); 44 struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev);
46 struct bq24022_mach_info *pdata = pdev->dev.platform_data;
47 45
48 dev_dbg(&pdev->dev, "enabling charger\n"); 46 dev_dbg(rdev_get_dev(rdev), "enabling charger\n");
49 47
50 gpio_set_value(pdata->gpio_nce, 0); 48 gpio_set_value(pdata->gpio_nce, 0);
51 return 0; 49 return 0;
@@ -53,10 +51,9 @@ static int bq24022_enable(struct regulator_dev *rdev)
53 51
54static int bq24022_disable(struct regulator_dev *rdev) 52static int bq24022_disable(struct regulator_dev *rdev)
55{ 53{
56 struct platform_device *pdev = rdev_get_drvdata(rdev); 54 struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev);
57 struct bq24022_mach_info *pdata = pdev->dev.platform_data;
58 55
59 dev_dbg(&pdev->dev, "disabling charger\n"); 56 dev_dbg(rdev_get_dev(rdev), "disabling charger\n");
60 57
61 gpio_set_value(pdata->gpio_nce, 1); 58 gpio_set_value(pdata->gpio_nce, 1);
62 return 0; 59 return 0;
@@ -108,7 +105,7 @@ static int __init bq24022_probe(struct platform_device *pdev)
108 ret = gpio_direction_output(pdata->gpio_iset2, 0); 105 ret = gpio_direction_output(pdata->gpio_iset2, 0);
109 ret = gpio_direction_output(pdata->gpio_nce, 1); 106 ret = gpio_direction_output(pdata->gpio_nce, 1);
110 107
111 bq24022 = regulator_register(&bq24022_desc, pdev); 108 bq24022 = regulator_register(&bq24022_desc, &pdev->dev, pdata);
112 if (IS_ERR(bq24022)) { 109 if (IS_ERR(bq24022)) {
113 dev_dbg(&pdev->dev, "couldn't register regulator\n"); 110 dev_dbg(&pdev->dev, "couldn't register regulator\n");
114 ret = PTR_ERR(bq24022); 111 ret = PTR_ERR(bq24022);
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 9c7986261568..02a774424e8d 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2,8 +2,9 @@
2 * core.c -- Voltage/Current Regulator framework. 2 * core.c -- Voltage/Current Regulator framework.
3 * 3 *
4 * Copyright 2007, 2008 Wolfson Microelectronics PLC. 4 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
5 * Copyright 2008 SlimLogic Ltd.
5 * 6 *
6 * Author: Liam Girdwood <liam.girdwood@wolfsonmicro.com> 7 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify it 9 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the 10 * under the terms of the GNU General Public License as published by the
@@ -64,14 +65,9 @@ struct regulator_map {
64 struct list_head list; 65 struct list_head list;
65 struct device *dev; 66 struct device *dev;
66 const char *supply; 67 const char *supply;
67 const char *regulator; 68 struct regulator_dev *regulator;
68}; 69};
69 70
70static inline struct regulator_dev *to_rdev(struct device *d)
71{
72 return container_of(d, struct regulator_dev, dev);
73}
74
75/* 71/*
76 * struct regulator 72 * struct regulator
77 * 73 *
@@ -227,7 +223,7 @@ static ssize_t device_requested_uA_show(struct device *dev,
227static ssize_t regulator_uV_show(struct device *dev, 223static ssize_t regulator_uV_show(struct device *dev,
228 struct device_attribute *attr, char *buf) 224 struct device_attribute *attr, char *buf)
229{ 225{
230 struct regulator_dev *rdev = to_rdev(dev); 226 struct regulator_dev *rdev = dev_get_drvdata(dev);
231 ssize_t ret; 227 ssize_t ret;
232 228
233 mutex_lock(&rdev->mutex); 229 mutex_lock(&rdev->mutex);
@@ -240,15 +236,31 @@ static ssize_t regulator_uV_show(struct device *dev,
240static ssize_t regulator_uA_show(struct device *dev, 236static ssize_t regulator_uA_show(struct device *dev,
241 struct device_attribute *attr, char *buf) 237 struct device_attribute *attr, char *buf)
242{ 238{
243 struct regulator_dev *rdev = to_rdev(dev); 239 struct regulator_dev *rdev = dev_get_drvdata(dev);
244 240
245 return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev)); 241 return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev));
246} 242}
247 243
244static ssize_t regulator_name_show(struct device *dev,
245 struct device_attribute *attr, char *buf)
246{
247 struct regulator_dev *rdev = dev_get_drvdata(dev);
248 const char *name;
249
250 if (rdev->constraints->name)
251 name = rdev->constraints->name;
252 else if (rdev->desc->name)
253 name = rdev->desc->name;
254 else
255 name = "";
256
257 return sprintf(buf, "%s\n", name);
258}
259
248static ssize_t regulator_opmode_show(struct device *dev, 260static ssize_t regulator_opmode_show(struct device *dev,
249 struct device_attribute *attr, char *buf) 261 struct device_attribute *attr, char *buf)
250{ 262{
251 struct regulator_dev *rdev = to_rdev(dev); 263 struct regulator_dev *rdev = dev_get_drvdata(dev);
252 int mode = _regulator_get_mode(rdev); 264 int mode = _regulator_get_mode(rdev);
253 265
254 switch (mode) { 266 switch (mode) {
@@ -267,7 +279,7 @@ static ssize_t regulator_opmode_show(struct device *dev,
267static ssize_t regulator_state_show(struct device *dev, 279static ssize_t regulator_state_show(struct device *dev,
268 struct device_attribute *attr, char *buf) 280 struct device_attribute *attr, char *buf)
269{ 281{
270 struct regulator_dev *rdev = to_rdev(dev); 282 struct regulator_dev *rdev = dev_get_drvdata(dev);
271 int state = _regulator_is_enabled(rdev); 283 int state = _regulator_is_enabled(rdev);
272 284
273 if (state > 0) 285 if (state > 0)
@@ -281,7 +293,7 @@ static ssize_t regulator_state_show(struct device *dev,
281static ssize_t regulator_min_uA_show(struct device *dev, 293static ssize_t regulator_min_uA_show(struct device *dev,
282 struct device_attribute *attr, char *buf) 294 struct device_attribute *attr, char *buf)
283{ 295{
284 struct regulator_dev *rdev = to_rdev(dev); 296 struct regulator_dev *rdev = dev_get_drvdata(dev);
285 297
286 if (!rdev->constraints) 298 if (!rdev->constraints)
287 return sprintf(buf, "constraint not defined\n"); 299 return sprintf(buf, "constraint not defined\n");
@@ -292,7 +304,7 @@ static ssize_t regulator_min_uA_show(struct device *dev,
292static ssize_t regulator_max_uA_show(struct device *dev, 304static ssize_t regulator_max_uA_show(struct device *dev,
293 struct device_attribute *attr, char *buf) 305 struct device_attribute *attr, char *buf)
294{ 306{
295 struct regulator_dev *rdev = to_rdev(dev); 307 struct regulator_dev *rdev = dev_get_drvdata(dev);
296 308
297 if (!rdev->constraints) 309 if (!rdev->constraints)
298 return sprintf(buf, "constraint not defined\n"); 310 return sprintf(buf, "constraint not defined\n");
@@ -303,7 +315,7 @@ static ssize_t regulator_max_uA_show(struct device *dev,
303static ssize_t regulator_min_uV_show(struct device *dev, 315static ssize_t regulator_min_uV_show(struct device *dev,
304 struct device_attribute *attr, char *buf) 316 struct device_attribute *attr, char *buf)
305{ 317{
306 struct regulator_dev *rdev = to_rdev(dev); 318 struct regulator_dev *rdev = dev_get_drvdata(dev);
307 319
308 if (!rdev->constraints) 320 if (!rdev->constraints)
309 return sprintf(buf, "constraint not defined\n"); 321 return sprintf(buf, "constraint not defined\n");
@@ -314,7 +326,7 @@ static ssize_t regulator_min_uV_show(struct device *dev,
314static ssize_t regulator_max_uV_show(struct device *dev, 326static ssize_t regulator_max_uV_show(struct device *dev,
315 struct device_attribute *attr, char *buf) 327 struct device_attribute *attr, char *buf)
316{ 328{
317 struct regulator_dev *rdev = to_rdev(dev); 329 struct regulator_dev *rdev = dev_get_drvdata(dev);
318 330
319 if (!rdev->constraints) 331 if (!rdev->constraints)
320 return sprintf(buf, "constraint not defined\n"); 332 return sprintf(buf, "constraint not defined\n");
@@ -325,7 +337,7 @@ static ssize_t regulator_max_uV_show(struct device *dev,
325static ssize_t regulator_total_uA_show(struct device *dev, 337static ssize_t regulator_total_uA_show(struct device *dev,
326 struct device_attribute *attr, char *buf) 338 struct device_attribute *attr, char *buf)
327{ 339{
328 struct regulator_dev *rdev = to_rdev(dev); 340 struct regulator_dev *rdev = dev_get_drvdata(dev);
329 struct regulator *regulator; 341 struct regulator *regulator;
330 int uA = 0; 342 int uA = 0;
331 343
@@ -339,14 +351,14 @@ static ssize_t regulator_total_uA_show(struct device *dev,
339static ssize_t regulator_num_users_show(struct device *dev, 351static ssize_t regulator_num_users_show(struct device *dev,
340 struct device_attribute *attr, char *buf) 352 struct device_attribute *attr, char *buf)
341{ 353{
342 struct regulator_dev *rdev = to_rdev(dev); 354 struct regulator_dev *rdev = dev_get_drvdata(dev);
343 return sprintf(buf, "%d\n", rdev->use_count); 355 return sprintf(buf, "%d\n", rdev->use_count);
344} 356}
345 357
346static ssize_t regulator_type_show(struct device *dev, 358static ssize_t regulator_type_show(struct device *dev,
347 struct device_attribute *attr, char *buf) 359 struct device_attribute *attr, char *buf)
348{ 360{
349 struct regulator_dev *rdev = to_rdev(dev); 361 struct regulator_dev *rdev = dev_get_drvdata(dev);
350 362
351 switch (rdev->desc->type) { 363 switch (rdev->desc->type) {
352 case REGULATOR_VOLTAGE: 364 case REGULATOR_VOLTAGE:
@@ -360,7 +372,7 @@ static ssize_t regulator_type_show(struct device *dev,
360static ssize_t regulator_suspend_mem_uV_show(struct device *dev, 372static ssize_t regulator_suspend_mem_uV_show(struct device *dev,
361 struct device_attribute *attr, char *buf) 373 struct device_attribute *attr, char *buf)
362{ 374{
363 struct regulator_dev *rdev = to_rdev(dev); 375 struct regulator_dev *rdev = dev_get_drvdata(dev);
364 376
365 if (!rdev->constraints) 377 if (!rdev->constraints)
366 return sprintf(buf, "not defined\n"); 378 return sprintf(buf, "not defined\n");
@@ -370,7 +382,7 @@ static ssize_t regulator_suspend_mem_uV_show(struct device *dev,
370static ssize_t regulator_suspend_disk_uV_show(struct device *dev, 382static ssize_t regulator_suspend_disk_uV_show(struct device *dev,
371 struct device_attribute *attr, char *buf) 383 struct device_attribute *attr, char *buf)
372{ 384{
373 struct regulator_dev *rdev = to_rdev(dev); 385 struct regulator_dev *rdev = dev_get_drvdata(dev);
374 386
375 if (!rdev->constraints) 387 if (!rdev->constraints)
376 return sprintf(buf, "not defined\n"); 388 return sprintf(buf, "not defined\n");
@@ -380,7 +392,7 @@ static ssize_t regulator_suspend_disk_uV_show(struct device *dev,
380static ssize_t regulator_suspend_standby_uV_show(struct device *dev, 392static ssize_t regulator_suspend_standby_uV_show(struct device *dev,
381 struct device_attribute *attr, char *buf) 393 struct device_attribute *attr, char *buf)
382{ 394{
383 struct regulator_dev *rdev = to_rdev(dev); 395 struct regulator_dev *rdev = dev_get_drvdata(dev);
384 396
385 if (!rdev->constraints) 397 if (!rdev->constraints)
386 return sprintf(buf, "not defined\n"); 398 return sprintf(buf, "not defined\n");
@@ -406,7 +418,7 @@ static ssize_t suspend_opmode_show(struct regulator_dev *rdev,
406static ssize_t regulator_suspend_mem_mode_show(struct device *dev, 418static ssize_t regulator_suspend_mem_mode_show(struct device *dev,
407 struct device_attribute *attr, char *buf) 419 struct device_attribute *attr, char *buf)
408{ 420{
409 struct regulator_dev *rdev = to_rdev(dev); 421 struct regulator_dev *rdev = dev_get_drvdata(dev);
410 422
411 if (!rdev->constraints) 423 if (!rdev->constraints)
412 return sprintf(buf, "not defined\n"); 424 return sprintf(buf, "not defined\n");
@@ -417,7 +429,7 @@ static ssize_t regulator_suspend_mem_mode_show(struct device *dev,
417static ssize_t regulator_suspend_disk_mode_show(struct device *dev, 429static ssize_t regulator_suspend_disk_mode_show(struct device *dev,
418 struct device_attribute *attr, char *buf) 430 struct device_attribute *attr, char *buf)
419{ 431{
420 struct regulator_dev *rdev = to_rdev(dev); 432 struct regulator_dev *rdev = dev_get_drvdata(dev);
421 433
422 if (!rdev->constraints) 434 if (!rdev->constraints)
423 return sprintf(buf, "not defined\n"); 435 return sprintf(buf, "not defined\n");
@@ -428,7 +440,7 @@ static ssize_t regulator_suspend_disk_mode_show(struct device *dev,
428static ssize_t regulator_suspend_standby_mode_show(struct device *dev, 440static ssize_t regulator_suspend_standby_mode_show(struct device *dev,
429 struct device_attribute *attr, char *buf) 441 struct device_attribute *attr, char *buf)
430{ 442{
431 struct regulator_dev *rdev = to_rdev(dev); 443 struct regulator_dev *rdev = dev_get_drvdata(dev);
432 444
433 if (!rdev->constraints) 445 if (!rdev->constraints)
434 return sprintf(buf, "not defined\n"); 446 return sprintf(buf, "not defined\n");
@@ -439,7 +451,7 @@ static ssize_t regulator_suspend_standby_mode_show(struct device *dev,
439static ssize_t regulator_suspend_mem_state_show(struct device *dev, 451static ssize_t regulator_suspend_mem_state_show(struct device *dev,
440 struct device_attribute *attr, char *buf) 452 struct device_attribute *attr, char *buf)
441{ 453{
442 struct regulator_dev *rdev = to_rdev(dev); 454 struct regulator_dev *rdev = dev_get_drvdata(dev);
443 455
444 if (!rdev->constraints) 456 if (!rdev->constraints)
445 return sprintf(buf, "not defined\n"); 457 return sprintf(buf, "not defined\n");
@@ -453,7 +465,7 @@ static ssize_t regulator_suspend_mem_state_show(struct device *dev,
453static ssize_t regulator_suspend_disk_state_show(struct device *dev, 465static ssize_t regulator_suspend_disk_state_show(struct device *dev,
454 struct device_attribute *attr, char *buf) 466 struct device_attribute *attr, char *buf)
455{ 467{
456 struct regulator_dev *rdev = to_rdev(dev); 468 struct regulator_dev *rdev = dev_get_drvdata(dev);
457 469
458 if (!rdev->constraints) 470 if (!rdev->constraints)
459 return sprintf(buf, "not defined\n"); 471 return sprintf(buf, "not defined\n");
@@ -467,7 +479,7 @@ static ssize_t regulator_suspend_disk_state_show(struct device *dev,
467static ssize_t regulator_suspend_standby_state_show(struct device *dev, 479static ssize_t regulator_suspend_standby_state_show(struct device *dev,
468 struct device_attribute *attr, char *buf) 480 struct device_attribute *attr, char *buf)
469{ 481{
470 struct regulator_dev *rdev = to_rdev(dev); 482 struct regulator_dev *rdev = dev_get_drvdata(dev);
471 483
472 if (!rdev->constraints) 484 if (!rdev->constraints)
473 return sprintf(buf, "not defined\n"); 485 return sprintf(buf, "not defined\n");
@@ -477,7 +489,9 @@ static ssize_t regulator_suspend_standby_state_show(struct device *dev,
477 else 489 else
478 return sprintf(buf, "disabled\n"); 490 return sprintf(buf, "disabled\n");
479} 491}
492
480static struct device_attribute regulator_dev_attrs[] = { 493static struct device_attribute regulator_dev_attrs[] = {
494 __ATTR(name, 0444, regulator_name_show, NULL),
481 __ATTR(microvolts, 0444, regulator_uV_show, NULL), 495 __ATTR(microvolts, 0444, regulator_uV_show, NULL),
482 __ATTR(microamps, 0444, regulator_uA_show, NULL), 496 __ATTR(microamps, 0444, regulator_uA_show, NULL),
483 __ATTR(opmode, 0444, regulator_opmode_show, NULL), 497 __ATTR(opmode, 0444, regulator_opmode_show, NULL),
@@ -512,7 +526,7 @@ static struct device_attribute regulator_dev_attrs[] = {
512 526
513static void regulator_dev_release(struct device *dev) 527static void regulator_dev_release(struct device *dev)
514{ 528{
515 struct regulator_dev *rdev = to_rdev(dev); 529 struct regulator_dev *rdev = dev_get_drvdata(dev);
516 kfree(rdev); 530 kfree(rdev);
517} 531}
518 532
@@ -569,8 +583,11 @@ static int suspend_set_state(struct regulator_dev *rdev,
569 583
570 /* enable & disable are mandatory for suspend control */ 584 /* enable & disable are mandatory for suspend control */
571 if (!rdev->desc->ops->set_suspend_enable || 585 if (!rdev->desc->ops->set_suspend_enable ||
572 !rdev->desc->ops->set_suspend_disable) 586 !rdev->desc->ops->set_suspend_disable) {
587 printk(KERN_ERR "%s: no way to set suspend state\n",
588 __func__);
573 return -EINVAL; 589 return -EINVAL;
590 }
574 591
575 if (rstate->enabled) 592 if (rstate->enabled)
576 ret = rdev->desc->ops->set_suspend_enable(rdev); 593 ret = rdev->desc->ops->set_suspend_enable(rdev);
@@ -656,6 +673,155 @@ static void print_constraints(struct regulator_dev *rdev)
656 printk(KERN_INFO "regulator: %s: %s\n", rdev->desc->name, buf); 673 printk(KERN_INFO "regulator: %s: %s\n", rdev->desc->name, buf);
657} 674}
658 675
676/**
677 * set_machine_constraints - sets regulator constraints
678 * @regulator: regulator source
679 *
680 * Allows platform initialisation code to define and constrain
681 * regulator circuits e.g. valid voltage/current ranges, etc. NOTE:
682 * Constraints *must* be set by platform code in order for some
683 * regulator operations to proceed i.e. set_voltage, set_current_limit,
684 * set_mode.
685 */
686static int set_machine_constraints(struct regulator_dev *rdev,
687 struct regulation_constraints *constraints)
688{
689 int ret = 0;
690 const char *name;
691 struct regulator_ops *ops = rdev->desc->ops;
692
693 if (constraints->name)
694 name = constraints->name;
695 else if (rdev->desc->name)
696 name = rdev->desc->name;
697 else
698 name = "regulator";
699
700 rdev->constraints = constraints;
701
702 /* do we need to apply the constraint voltage */
703 if (rdev->constraints->apply_uV &&
704 rdev->constraints->min_uV == rdev->constraints->max_uV &&
705 ops->set_voltage) {
706 ret = ops->set_voltage(rdev,
707 rdev->constraints->min_uV, rdev->constraints->max_uV);
708 if (ret < 0) {
709 printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n",
710 __func__,
711 rdev->constraints->min_uV, name);
712 rdev->constraints = NULL;
713 goto out;
714 }
715 }
716
717 /* are we enabled at boot time by firmware / bootloader */
718 if (rdev->constraints->boot_on)
719 rdev->use_count = 1;
720
721 /* do we need to setup our suspend state */
722 if (constraints->initial_state) {
723 ret = suspend_prepare(rdev, constraints->initial_state);
724 if (ret < 0) {
725 printk(KERN_ERR "%s: failed to set suspend state for %s\n",
726 __func__, name);
727 rdev->constraints = NULL;
728 goto out;
729 }
730 }
731
732 /* if always_on is set then turn the regulator on if it's not
733 * already on. */
734 if (constraints->always_on && ops->enable &&
735 ((ops->is_enabled && !ops->is_enabled(rdev)) ||
736 (!ops->is_enabled && !constraints->boot_on))) {
737 ret = ops->enable(rdev);
738 if (ret < 0) {
739 printk(KERN_ERR "%s: failed to enable %s\n",
740 __func__, name);
741 rdev->constraints = NULL;
742 goto out;
743 }
744 }
745
746 print_constraints(rdev);
747out:
748 return ret;
749}
750
751/**
752 * set_supply - set regulator supply regulator
753 * @regulator: regulator name
754 * @supply: supply regulator name
755 *
756 * Called by platform initialisation code to set the supply regulator for this
757 * regulator. This ensures that a regulators supply will also be enabled by the
758 * core if it's child is enabled.
759 */
760static int set_supply(struct regulator_dev *rdev,
761 struct regulator_dev *supply_rdev)
762{
763 int err;
764
765 err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj,
766 "supply");
767 if (err) {
768 printk(KERN_ERR
769 "%s: could not add device link %s err %d\n",
770 __func__, supply_rdev->dev.kobj.name, err);
771 goto out;
772 }
773 rdev->supply = supply_rdev;
774 list_add(&rdev->slist, &supply_rdev->supply_list);
775out:
776 return err;
777}
778
779/**
780 * set_consumer_device_supply: Bind a regulator to a symbolic supply
781 * @regulator: regulator source
782 * @dev: device the supply applies to
783 * @supply: symbolic name for supply
784 *
785 * Allows platform initialisation code to map physical regulator
786 * sources to symbolic names for supplies for use by devices. Devices
787 * should use these symbolic names to request regulators, avoiding the
788 * need to provide board-specific regulator names as platform data.
789 */
790static int set_consumer_device_supply(struct regulator_dev *rdev,
791 struct device *consumer_dev, const char *supply)
792{
793 struct regulator_map *node;
794
795 if (supply == NULL)
796 return -EINVAL;
797
798 node = kmalloc(sizeof(struct regulator_map), GFP_KERNEL);
799 if (node == NULL)
800 return -ENOMEM;
801
802 node->regulator = rdev;
803 node->dev = consumer_dev;
804 node->supply = supply;
805
806 list_add(&node->list, &regulator_map_list);
807 return 0;
808}
809
810static void unset_consumer_device_supply(struct regulator_dev *rdev,
811 struct device *consumer_dev)
812{
813 struct regulator_map *node, *n;
814
815 list_for_each_entry_safe(node, n, &regulator_map_list, list) {
816 if (rdev == node->regulator &&
817 consumer_dev == node->dev) {
818 list_del(&node->list);
819 kfree(node);
820 return;
821 }
822 }
823}
824
659#define REG_STR_SIZE 32 825#define REG_STR_SIZE 32
660 826
661static struct regulator *create_regulator(struct regulator_dev *rdev, 827static struct regulator *create_regulator(struct regulator_dev *rdev,
@@ -746,7 +912,6 @@ struct regulator *regulator_get(struct device *dev, const char *id)
746 struct regulator_dev *rdev; 912 struct regulator_dev *rdev;
747 struct regulator_map *map; 913 struct regulator_map *map;
748 struct regulator *regulator = ERR_PTR(-ENODEV); 914 struct regulator *regulator = ERR_PTR(-ENODEV);
749 const char *supply = id;
750 915
751 if (id == NULL) { 916 if (id == NULL) {
752 printk(KERN_ERR "regulator: get() with no identifier\n"); 917 printk(KERN_ERR "regulator: get() with no identifier\n");
@@ -758,15 +923,9 @@ struct regulator *regulator_get(struct device *dev, const char *id)
758 list_for_each_entry(map, &regulator_map_list, list) { 923 list_for_each_entry(map, &regulator_map_list, list) {
759 if (dev == map->dev && 924 if (dev == map->dev &&
760 strcmp(map->supply, id) == 0) { 925 strcmp(map->supply, id) == 0) {
761 supply = map->regulator; 926 rdev = map->regulator;
762 break;
763 }
764 }
765
766 list_for_each_entry(rdev, &regulator_list, list) {
767 if (strcmp(supply, rdev->desc->name) == 0 &&
768 try_module_get(rdev->owner))
769 goto found; 927 goto found;
928 }
770 } 929 }
771 printk(KERN_ERR "regulator: Unable to get requested regulator: %s\n", 930 printk(KERN_ERR "regulator: Unable to get requested regulator: %s\n",
772 id); 931 id);
@@ -774,12 +933,16 @@ struct regulator *regulator_get(struct device *dev, const char *id)
774 return regulator; 933 return regulator;
775 934
776found: 935found:
936 if (!try_module_get(rdev->owner))
937 goto out;
938
777 regulator = create_regulator(rdev, dev, id); 939 regulator = create_regulator(rdev, dev, id);
778 if (regulator == NULL) { 940 if (regulator == NULL) {
779 regulator = ERR_PTR(-ENOMEM); 941 regulator = ERR_PTR(-ENOMEM);
780 module_put(rdev->owner); 942 module_put(rdev->owner);
781 } 943 }
782 944
945out:
783 mutex_unlock(&regulator_list_mutex); 946 mutex_unlock(&regulator_list_mutex);
784 return regulator; 947 return regulator;
785} 948}
@@ -1559,11 +1722,12 @@ EXPORT_SYMBOL_GPL(regulator_notifier_call_chain);
1559 * Returns 0 on success. 1722 * Returns 0 on success.
1560 */ 1723 */
1561struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, 1724struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
1562 void *reg_data) 1725 struct device *dev, void *driver_data)
1563{ 1726{
1564 static atomic_t regulator_no = ATOMIC_INIT(0); 1727 static atomic_t regulator_no = ATOMIC_INIT(0);
1565 struct regulator_dev *rdev; 1728 struct regulator_dev *rdev;
1566 int ret; 1729 struct regulator_init_data *init_data = dev->platform_data;
1730 int ret, i;
1567 1731
1568 if (regulator_desc == NULL) 1732 if (regulator_desc == NULL)
1569 return ERR_PTR(-EINVAL); 1733 return ERR_PTR(-EINVAL);
@@ -1575,6 +1739,9 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
1575 !regulator_desc->type == REGULATOR_CURRENT) 1739 !regulator_desc->type == REGULATOR_CURRENT)
1576 return ERR_PTR(-EINVAL); 1740 return ERR_PTR(-EINVAL);
1577 1741
1742 if (!init_data)
1743 return ERR_PTR(-EINVAL);
1744
1578 rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); 1745 rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL);
1579 if (rdev == NULL) 1746 if (rdev == NULL)
1580 return ERR_PTR(-ENOMEM); 1747 return ERR_PTR(-ENOMEM);
@@ -1582,7 +1749,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
1582 mutex_lock(&regulator_list_mutex); 1749 mutex_lock(&regulator_list_mutex);
1583 1750
1584 mutex_init(&rdev->mutex); 1751 mutex_init(&rdev->mutex);
1585 rdev->reg_data = reg_data; 1752 rdev->reg_data = driver_data;
1586 rdev->owner = regulator_desc->owner; 1753 rdev->owner = regulator_desc->owner;
1587 rdev->desc = regulator_desc; 1754 rdev->desc = regulator_desc;
1588 INIT_LIST_HEAD(&rdev->consumer_list); 1755 INIT_LIST_HEAD(&rdev->consumer_list);
@@ -1591,20 +1758,68 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
1591 INIT_LIST_HEAD(&rdev->slist); 1758 INIT_LIST_HEAD(&rdev->slist);
1592 BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier); 1759 BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier);
1593 1760
1761 /* preform any regulator specific init */
1762 if (init_data->regulator_init) {
1763 ret = init_data->regulator_init(rdev->reg_data);
1764 if (ret < 0) {
1765 kfree(rdev);
1766 rdev = ERR_PTR(ret);
1767 goto out;
1768 }
1769 }
1770
1771 /* set regulator constraints */
1772 ret = set_machine_constraints(rdev, &init_data->constraints);
1773 if (ret < 0) {
1774 kfree(rdev);
1775 rdev = ERR_PTR(ret);
1776 goto out;
1777 }
1778
1779 /* register with sysfs */
1594 rdev->dev.class = &regulator_class; 1780 rdev->dev.class = &regulator_class;
1595 device_initialize(&rdev->dev); 1781 rdev->dev.parent = dev;
1596 snprintf(rdev->dev.bus_id, sizeof(rdev->dev.bus_id), 1782 snprintf(rdev->dev.bus_id, sizeof(rdev->dev.bus_id),
1597 "regulator_%ld_%s", 1783 "regulator.%d", atomic_inc_return(&regulator_no) - 1);
1598 (unsigned long)atomic_inc_return(&regulator_no) - 1, 1784 ret = device_register(&rdev->dev);
1599 regulator_desc->name); 1785 if (ret != 0) {
1600
1601 ret = device_add(&rdev->dev);
1602 if (ret == 0)
1603 list_add(&rdev->list, &regulator_list);
1604 else {
1605 kfree(rdev); 1786 kfree(rdev);
1606 rdev = ERR_PTR(ret); 1787 rdev = ERR_PTR(ret);
1788 goto out;
1789 }
1790
1791 dev_set_drvdata(&rdev->dev, rdev);
1792
1793 /* set supply regulator if it exists */
1794 if (init_data->supply_regulator_dev) {
1795 ret = set_supply(rdev,
1796 dev_get_drvdata(init_data->supply_regulator_dev));
1797 if (ret < 0) {
1798 device_unregister(&rdev->dev);
1799 kfree(rdev);
1800 rdev = ERR_PTR(ret);
1801 goto out;
1802 }
1607 } 1803 }
1804
1805 /* add consumers devices */
1806 for (i = 0; i < init_data->num_consumer_supplies; i++) {
1807 ret = set_consumer_device_supply(rdev,
1808 init_data->consumer_supplies[i].dev,
1809 init_data->consumer_supplies[i].supply);
1810 if (ret < 0) {
1811 for (--i; i >= 0; i--)
1812 unset_consumer_device_supply(rdev,
1813 init_data->consumer_supplies[i].dev);
1814 device_unregister(&rdev->dev);
1815 kfree(rdev);
1816 rdev = ERR_PTR(ret);
1817 goto out;
1818 }
1819 }
1820
1821 list_add(&rdev->list, &regulator_list);
1822out:
1608 mutex_unlock(&regulator_list_mutex); 1823 mutex_unlock(&regulator_list_mutex);
1609 return rdev; 1824 return rdev;
1610} 1825}
@@ -1631,187 +1846,6 @@ void regulator_unregister(struct regulator_dev *rdev)
1631EXPORT_SYMBOL_GPL(regulator_unregister); 1846EXPORT_SYMBOL_GPL(regulator_unregister);
1632 1847
1633/** 1848/**
1634 * regulator_set_supply - set regulator supply regulator
1635 * @regulator: regulator name
1636 * @supply: supply regulator name
1637 *
1638 * Called by platform initialisation code to set the supply regulator for this
1639 * regulator. This ensures that a regulators supply will also be enabled by the
1640 * core if it's child is enabled.
1641 */
1642int regulator_set_supply(const char *regulator, const char *supply)
1643{
1644 struct regulator_dev *rdev, *supply_rdev;
1645 int err;
1646
1647 if (regulator == NULL || supply == NULL)
1648 return -EINVAL;
1649
1650 mutex_lock(&regulator_list_mutex);
1651
1652 list_for_each_entry(rdev, &regulator_list, list) {
1653 if (!strcmp(rdev->desc->name, regulator))
1654 goto found_regulator;
1655 }
1656 mutex_unlock(&regulator_list_mutex);
1657 return -ENODEV;
1658
1659found_regulator:
1660 list_for_each_entry(supply_rdev, &regulator_list, list) {
1661 if (!strcmp(supply_rdev->desc->name, supply))
1662 goto found_supply;
1663 }
1664 mutex_unlock(&regulator_list_mutex);
1665 return -ENODEV;
1666
1667found_supply:
1668 err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj,
1669 "supply");
1670 if (err) {
1671 printk(KERN_ERR
1672 "%s: could not add device link %s err %d\n",
1673 __func__, supply_rdev->dev.kobj.name, err);
1674 goto out;
1675 }
1676 rdev->supply = supply_rdev;
1677 list_add(&rdev->slist, &supply_rdev->supply_list);
1678out:
1679 mutex_unlock(&regulator_list_mutex);
1680 return err;
1681}
1682EXPORT_SYMBOL_GPL(regulator_set_supply);
1683
1684/**
1685 * regulator_get_supply - get regulator supply regulator
1686 * @regulator: regulator name
1687 *
1688 * Returns the supply supply regulator name or NULL if no supply regulator
1689 * exists (i.e the regulator is supplied directly from USB, Line, Battery, etc)
1690 */
1691const char *regulator_get_supply(const char *regulator)
1692{
1693 struct regulator_dev *rdev;
1694
1695 if (regulator == NULL)
1696 return NULL;
1697
1698 mutex_lock(&regulator_list_mutex);
1699 list_for_each_entry(rdev, &regulator_list, list) {
1700 if (!strcmp(rdev->desc->name, regulator))
1701 goto found;
1702 }
1703 mutex_unlock(&regulator_list_mutex);
1704 return NULL;
1705
1706found:
1707 mutex_unlock(&regulator_list_mutex);
1708 if (rdev->supply)
1709 return rdev->supply->desc->name;
1710 else
1711 return NULL;
1712}
1713EXPORT_SYMBOL_GPL(regulator_get_supply);
1714
1715/**
1716 * regulator_set_machine_constraints - sets regulator constraints
1717 * @regulator: regulator source
1718 *
1719 * Allows platform initialisation code to define and constrain
1720 * regulator circuits e.g. valid voltage/current ranges, etc. NOTE:
1721 * Constraints *must* be set by platform code in order for some
1722 * regulator operations to proceed i.e. set_voltage, set_current_limit,
1723 * set_mode.
1724 */
1725int regulator_set_machine_constraints(const char *regulator_name,
1726 struct regulation_constraints *constraints)
1727{
1728 struct regulator_dev *rdev;
1729 int ret = 0;
1730
1731 if (regulator_name == NULL)
1732 return -EINVAL;
1733
1734 mutex_lock(&regulator_list_mutex);
1735
1736 list_for_each_entry(rdev, &regulator_list, list) {
1737 if (!strcmp(regulator_name, rdev->desc->name))
1738 goto found;
1739 }
1740 ret = -ENODEV;
1741 goto out;
1742
1743found:
1744 mutex_lock(&rdev->mutex);
1745 rdev->constraints = constraints;
1746
1747 /* do we need to apply the constraint voltage */
1748 if (rdev->constraints->apply_uV &&
1749 rdev->constraints->min_uV == rdev->constraints->max_uV &&
1750 rdev->desc->ops->set_voltage) {
1751 ret = rdev->desc->ops->set_voltage(rdev,
1752 rdev->constraints->min_uV, rdev->constraints->max_uV);
1753 if (ret < 0) {
1754 printk(KERN_ERR "%s: failed to apply %duV"
1755 " constraint\n", __func__,
1756 rdev->constraints->min_uV);
1757 rdev->constraints = NULL;
1758 goto out;
1759 }
1760 }
1761
1762 /* are we enabled at boot time by firmware / bootloader */
1763 if (rdev->constraints->boot_on)
1764 rdev->use_count = 1;
1765
1766 /* do we need to setup our suspend state */
1767 if (constraints->initial_state)
1768 ret = suspend_prepare(rdev, constraints->initial_state);
1769
1770 print_constraints(rdev);
1771 mutex_unlock(&rdev->mutex);
1772
1773out:
1774 mutex_unlock(&regulator_list_mutex);
1775 return ret;
1776}
1777EXPORT_SYMBOL_GPL(regulator_set_machine_constraints);
1778
1779
1780/**
1781 * regulator_set_device_supply: Bind a regulator to a symbolic supply
1782 * @regulator: regulator source
1783 * @dev: device the supply applies to
1784 * @supply: symbolic name for supply
1785 *
1786 * Allows platform initialisation code to map physical regulator
1787 * sources to symbolic names for supplies for use by devices. Devices
1788 * should use these symbolic names to request regulators, avoiding the
1789 * need to provide board-specific regulator names as platform data.
1790 */
1791int regulator_set_device_supply(const char *regulator, struct device *dev,
1792 const char *supply)
1793{
1794 struct regulator_map *node;
1795
1796 if (regulator == NULL || supply == NULL)
1797 return -EINVAL;
1798
1799 node = kmalloc(sizeof(struct regulator_map), GFP_KERNEL);
1800 if (node == NULL)
1801 return -ENOMEM;
1802
1803 node->regulator = regulator;
1804 node->dev = dev;
1805 node->supply = supply;
1806
1807 mutex_lock(&regulator_list_mutex);
1808 list_add(&node->list, &regulator_map_list);
1809 mutex_unlock(&regulator_list_mutex);
1810 return 0;
1811}
1812EXPORT_SYMBOL_GPL(regulator_set_device_supply);
1813
1814/**
1815 * regulator_suspend_prepare: prepare regulators for system wide suspend 1849 * regulator_suspend_prepare: prepare regulators for system wide suspend
1816 * @state: system suspend state 1850 * @state: system suspend state
1817 * 1851 *
@@ -1893,6 +1927,18 @@ int rdev_get_id(struct regulator_dev *rdev)
1893} 1927}
1894EXPORT_SYMBOL_GPL(rdev_get_id); 1928EXPORT_SYMBOL_GPL(rdev_get_id);
1895 1929
1930struct device *rdev_get_dev(struct regulator_dev *rdev)
1931{
1932 return &rdev->dev;
1933}
1934EXPORT_SYMBOL_GPL(rdev_get_dev);
1935
1936void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data)
1937{
1938 return reg_init_data->driver_data;
1939}
1940EXPORT_SYMBOL_GPL(regulator_get_init_drvdata);
1941
1896static int __init regulator_init(void) 1942static int __init regulator_init(void)
1897{ 1943{
1898 printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION); 1944 printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION);
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c
new file mode 100644
index 000000000000..3688e339db87
--- /dev/null
+++ b/drivers/regulator/da903x.c
@@ -0,0 +1,513 @@
1/*
2 * Regulators driver for Dialog Semiconductor DA903x
3 *
4 * Copyright (C) 2006-2008 Marvell International Ltd.
5 * Copyright (C) 2008 Compulab Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/err.h>
15#include <linux/platform_device.h>
16#include <linux/regulator/driver.h>
17#include <linux/regulator/machine.h>
18#include <linux/mfd/da903x.h>
19
20/* DA9030 Registers */
21#define DA9030_INVAL (-1)
22#define DA9030_LDO1011 (0x10)
23#define DA9030_LDO15 (0x11)
24#define DA9030_LDO1416 (0x12)
25#define DA9030_LDO1819 (0x13)
26#define DA9030_LDO17 (0x14)
27#define DA9030_BUCK2DVM1 (0x15)
28#define DA9030_BUCK2DVM2 (0x16)
29#define DA9030_RCTL11 (0x17)
30#define DA9030_RCTL21 (0x18)
31#define DA9030_LDO1 (0x90)
32#define DA9030_LDO23 (0x91)
33#define DA9030_LDO45 (0x92)
34#define DA9030_LDO6 (0x93)
35#define DA9030_LDO78 (0x94)
36#define DA9030_LDO912 (0x95)
37#define DA9030_BUCK (0x96)
38#define DA9030_RCTL12 (0x97)
39#define DA9030_RCTL22 (0x98)
40#define DA9030_LDO_UNLOCK (0xa0)
41#define DA9030_LDO_UNLOCK_MASK (0xe0)
42#define DA9034_OVER1 (0x10)
43
44/* DA9034 Registers */
45#define DA9034_INVAL (-1)
46#define DA9034_OVER2 (0x11)
47#define DA9034_OVER3 (0x12)
48#define DA9034_LDO643 (0x13)
49#define DA9034_LDO987 (0x14)
50#define DA9034_LDO1110 (0x15)
51#define DA9034_LDO1312 (0x16)
52#define DA9034_LDO1514 (0x17)
53#define DA9034_VCC1 (0x20)
54#define DA9034_ADTV1 (0x23)
55#define DA9034_ADTV2 (0x24)
56#define DA9034_AVRC (0x25)
57#define DA9034_CDTV1 (0x26)
58#define DA9034_CDTV2 (0x27)
59#define DA9034_CVRC (0x28)
60#define DA9034_SDTV1 (0x29)
61#define DA9034_SDTV2 (0x2a)
62#define DA9034_SVRC (0x2b)
63#define DA9034_MDTV1 (0x32)
64#define DA9034_MDTV2 (0x33)
65#define DA9034_MVRC (0x34)
66
67struct da903x_regulator_info {
68 struct regulator_desc desc;
69
70 int min_uV;
71 int max_uV;
72 int step_uV;
73 int vol_reg;
74 int vol_shift;
75 int vol_nbits;
76 int update_reg;
77 int update_bit;
78 int enable_reg;
79 int enable_bit;
80};
81
82static inline int check_range(struct da903x_regulator_info *info,
83 int min_uV, int max_uV)
84{
85 if (min_uV < info->min_uV || min_uV > info->max_uV)
86 return -EINVAL;
87
88 return 0;
89}
90
91/* DA9030/DA9034 common operations */
92static int da903x_set_ldo_voltage(struct regulator_dev *rdev,
93 int min_uV, int max_uV)
94{
95 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
96 struct device *da9034_dev = rdev_get_dev(rdev)->parent;
97 uint8_t val, mask;
98
99 if (check_range(info, min_uV, max_uV)) {
100 pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV);
101 return -EINVAL;
102 }
103
104 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
105 val <<= info->vol_shift;
106 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
107
108 return da903x_update(da9034_dev, info->vol_reg, val, mask);
109}
110
111static int da903x_get_voltage(struct regulator_dev *rdev)
112{
113 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
114 struct device *da9034_dev = rdev_get_dev(rdev)->parent;
115 uint8_t val, mask;
116 int ret;
117
118 ret = da903x_read(da9034_dev, info->vol_reg, &val);
119 if (ret)
120 return ret;
121
122 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
123 val = (val & mask) >> info->vol_shift;
124
125 return info->min_uV + info->step_uV * val;
126}
127
128static int da903x_enable(struct regulator_dev *rdev)
129{
130 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
131 struct device *da9034_dev = rdev_get_dev(rdev)->parent;
132
133 return da903x_set_bits(da9034_dev, info->enable_reg,
134 1 << info->enable_bit);
135}
136
137static int da903x_disable(struct regulator_dev *rdev)
138{
139 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
140 struct device *da9034_dev = rdev_get_dev(rdev)->parent;
141
142 return da903x_clr_bits(da9034_dev, info->enable_reg,
143 1 << info->enable_bit);
144}
145
146static int da903x_is_enabled(struct regulator_dev *rdev)
147{
148 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
149 struct device *da9034_dev = rdev_get_dev(rdev)->parent;
150 uint8_t reg_val;
151 int ret;
152
153 ret = da903x_read(da9034_dev, info->enable_reg, &reg_val);
154 if (ret)
155 return ret;
156
157 return reg_val & (1 << info->enable_bit);
158}
159
160/* DA9030 specific operations */
161static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
162 int min_uV, int max_uV)
163{
164 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
165 struct device *da903x_dev = rdev_get_dev(rdev)->parent;
166 uint8_t val, mask;
167 int ret;
168
169 if (check_range(info, min_uV, max_uV)) {
170 pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV);
171 return -EINVAL;
172 }
173
174 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
175 val <<= info->vol_shift;
176 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
177 val |= DA9030_LDO_UNLOCK; /* have to set UNLOCK bits */
178 mask |= DA9030_LDO_UNLOCK_MASK;
179
180 /* write twice */
181 ret = da903x_update(da903x_dev, info->vol_reg, val, mask);
182 if (ret)
183 return ret;
184
185 return da903x_update(da903x_dev, info->vol_reg, val, mask);
186}
187
188static int da9030_set_ldo14_voltage(struct regulator_dev *rdev,
189 int min_uV, int max_uV)
190{
191 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
192 struct device *da903x_dev = rdev_get_dev(rdev)->parent;
193 uint8_t val, mask;
194 int thresh;
195
196 if (check_range(info, min_uV, max_uV)) {
197 pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV);
198 return -EINVAL;
199 }
200
201 thresh = (info->max_uV + info->min_uV) / 2;
202 if (min_uV < thresh) {
203 val = (thresh - min_uV + info->step_uV - 1) / info->step_uV;
204 val |= 0x4;
205 } else {
206 val = (min_uV - thresh + info->step_uV - 1) / info->step_uV;
207 }
208
209 val <<= info->vol_shift;
210 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
211
212 return da903x_update(da903x_dev, info->vol_reg, val, mask);
213}
214
215static int da9030_get_ldo14_voltage(struct regulator_dev *rdev)
216{
217 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
218 struct device *da903x_dev = rdev_get_dev(rdev)->parent;
219 uint8_t val, mask;
220 int ret;
221
222 ret = da903x_read(da903x_dev, info->vol_reg, &val);
223 if (ret)
224 return ret;
225
226 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
227 val = (val & mask) >> info->vol_shift;
228
229 if (val & 0x4)
230 return info->min_uV + info->step_uV * (3 - (val & ~0x4));
231 else
232 return (info->max_uV + info->min_uV) / 2 +
233 info->step_uV * (val & ~0x4);
234}
235
236/* DA9034 specific operations */
237static int da9034_set_dvc_voltage(struct regulator_dev *rdev,
238 int min_uV, int max_uV)
239{
240 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
241 struct device *da9034_dev = rdev_get_dev(rdev)->parent;
242 uint8_t val, mask;
243 int ret;
244
245 if (check_range(info, min_uV, max_uV)) {
246 pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV);
247 return -EINVAL;
248 }
249
250 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
251 val <<= info->vol_shift;
252 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
253
254 ret = da903x_update(da9034_dev, info->vol_reg, val, mask);
255 if (ret)
256 return ret;
257
258 ret = da903x_set_bits(da9034_dev, info->update_reg,
259 1 << info->update_bit);
260 return ret;
261}
262
263static int da9034_set_ldo12_voltage(struct regulator_dev *rdev,
264 int min_uV, int max_uV)
265{
266 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
267 struct device *da9034_dev = rdev_get_dev(rdev)->parent;
268 uint8_t val, mask;
269
270 if (check_range(info, min_uV, max_uV)) {
271 pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV);
272 return -EINVAL;
273 }
274
275 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
276 val = (val > 7 || val < 20) ? 8 : val - 12;
277 val <<= info->vol_shift;
278 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
279
280 return da903x_update(da9034_dev, info->vol_reg, val, mask);
281}
282
283static int da9034_get_ldo12_voltage(struct regulator_dev *rdev)
284{
285 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
286 struct device *da9034_dev = rdev_get_dev(rdev)->parent;
287 uint8_t val, mask;
288 int ret;
289
290 ret = da903x_read(da9034_dev, info->vol_reg, &val);
291 if (ret)
292 return ret;
293
294 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
295 val = (val & mask) >> info->vol_shift;
296
297 if (val >= 8)
298 return 2700000 + info->step_uV * (val - 8);
299
300 return info->min_uV + info->step_uV * val;
301}
302
303static struct regulator_ops da903x_regulator_ldo_ops = {
304 .set_voltage = da903x_set_ldo_voltage,
305 .get_voltage = da903x_get_voltage,
306 .enable = da903x_enable,
307 .disable = da903x_disable,
308 .is_enabled = da903x_is_enabled,
309};
310
311/* NOTE: this is dedicated for the insane DA9030 LDO14 */
312static struct regulator_ops da9030_regulator_ldo14_ops = {
313 .set_voltage = da9030_set_ldo14_voltage,
314 .get_voltage = da9030_get_ldo14_voltage,
315 .enable = da903x_enable,
316 .disable = da903x_disable,
317 .is_enabled = da903x_is_enabled,
318};
319
320/* NOTE: this is dedicated for the DA9030 LDO1 and LDO15 that have locks */
321static struct regulator_ops da9030_regulator_ldo1_15_ops = {
322 .set_voltage = da9030_set_ldo1_15_voltage,
323 .get_voltage = da903x_get_voltage,
324 .enable = da903x_enable,
325 .disable = da903x_disable,
326 .is_enabled = da903x_is_enabled,
327};
328
329static struct regulator_ops da9034_regulator_dvc_ops = {
330 .set_voltage = da9034_set_dvc_voltage,
331 .get_voltage = da903x_get_voltage,
332 .enable = da903x_enable,
333 .disable = da903x_disable,
334 .is_enabled = da903x_is_enabled,
335};
336
337/* NOTE: this is dedicated for the insane LDO12 */
338static struct regulator_ops da9034_regulator_ldo12_ops = {
339 .set_voltage = da9034_set_ldo12_voltage,
340 .get_voltage = da9034_get_ldo12_voltage,
341 .enable = da903x_enable,
342 .disable = da903x_disable,
343 .is_enabled = da903x_is_enabled,
344};
345
346#define DA903x_LDO(_pmic, _id, min, max, step, vreg, shift, nbits, ereg, ebit) \
347{ \
348 .desc = { \
349 .name = "LDO" #_id, \
350 .ops = &da903x_regulator_ldo_ops, \
351 .type = REGULATOR_VOLTAGE, \
352 .id = _pmic##_ID_LDO##_id, \
353 .owner = THIS_MODULE, \
354 }, \
355 .min_uV = (min) * 1000, \
356 .max_uV = (max) * 1000, \
357 .step_uV = (step) * 1000, \
358 .vol_reg = _pmic##_##vreg, \
359 .vol_shift = (shift), \
360 .vol_nbits = (nbits), \
361 .enable_reg = _pmic##_##ereg, \
362 .enable_bit = (ebit), \
363}
364
365#define DA9034_DVC(_id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \
366{ \
367 .desc = { \
368 .name = #_id, \
369 .ops = &da9034_regulator_dvc_ops, \
370 .type = REGULATOR_VOLTAGE, \
371 .id = DA9034_ID_##_id, \
372 .owner = THIS_MODULE, \
373 }, \
374 .min_uV = (min) * 1000, \
375 .max_uV = (max) * 1000, \
376 .step_uV = (step) * 1000, \
377 .vol_reg = DA9034_##vreg, \
378 .vol_shift = (0), \
379 .vol_nbits = (nbits), \
380 .update_reg = DA9034_##ureg, \
381 .update_bit = (ubit), \
382 .enable_reg = DA9034_##ereg, \
383 .enable_bit = (ebit), \
384}
385
386#define DA9034_LDO(_id, min, max, step, vreg, shift, nbits, ereg, ebit) \
387 DA903x_LDO(DA9034, _id, min, max, step, vreg, shift, nbits, ereg, ebit)
388
389#define DA9030_LDO(_id, min, max, step, vreg, shift, nbits, ereg, ebit) \
390 DA903x_LDO(DA9030, _id, min, max, step, vreg, shift, nbits, ereg, ebit)
391
392static struct da903x_regulator_info da903x_regulator_info[] = {
393 /* DA9030 */
394 DA9030_LDO( 1, 1200, 3200, 100, LDO1, 0, 5, RCTL12, 1),
395 DA9030_LDO( 2, 1800, 3200, 100, LDO23, 0, 4, RCTL12, 2),
396 DA9030_LDO( 3, 1800, 3200, 100, LDO23, 4, 4, RCTL12, 3),
397 DA9030_LDO( 4, 1800, 3200, 100, LDO45, 0, 4, RCTL12, 4),
398 DA9030_LDO( 5, 1800, 3200, 100, LDO45, 4, 4, RCTL12, 5),
399 DA9030_LDO( 6, 1800, 3200, 100, LDO6, 0, 4, RCTL12, 6),
400 DA9030_LDO( 7, 1800, 3200, 100, LDO78, 0, 4, RCTL12, 7),
401 DA9030_LDO( 8, 1800, 3200, 100, LDO78, 4, 4, RCTL22, 0),
402 DA9030_LDO( 9, 1800, 3200, 100, LDO912, 0, 4, RCTL22, 1),
403 DA9030_LDO(10, 1800, 3200, 100, LDO1011, 0, 4, RCTL22, 2),
404 DA9030_LDO(11, 1800, 3200, 100, LDO1011, 4, 4, RCTL22, 3),
405 DA9030_LDO(12, 1800, 3200, 100, LDO912, 4, 4, RCTL22, 4),
406 DA9030_LDO(14, 2760, 2940, 30, LDO1416, 0, 3, RCTL11, 4),
407 DA9030_LDO(15, 1100, 2650, 50, LDO15, 0, 5, RCTL11, 5),
408 DA9030_LDO(16, 1100, 2650, 50, LDO1416, 3, 5, RCTL11, 6),
409 DA9030_LDO(17, 1800, 3200, 100, LDO17, 0, 4, RCTL11, 7),
410 DA9030_LDO(18, 1800, 3200, 100, LDO1819, 0, 4, RCTL21, 2),
411 DA9030_LDO(19, 1800, 3200, 100, LDO1819, 4, 4, RCTL21, 1),
412 DA9030_LDO(13, 2100, 2100, 0, INVAL, 0, 0, RCTL11, 3), /* fixed @2.1V */
413
414 /* DA9034 */
415 DA9034_DVC(BUCK1, 725, 1500, 25, ADTV1, 5, VCC1, 0, OVER1, 0),
416 DA9034_DVC(BUCK2, 725, 1500, 25, CDTV1, 5, VCC1, 2, OVER1, 1),
417 DA9034_DVC(LDO2, 725, 1500, 25, SDTV1, 5, VCC1, 4, OVER1, 2),
418 DA9034_DVC(LDO1, 1700, 2075, 25, MDTV1, 4, VCC1, 6, OVER3, 4),
419
420 DA9034_LDO( 3, 1800, 3300, 100, LDO643, 0, 4, OVER3, 5),
421 DA9034_LDO( 4, 1800, 2900,1100, LDO643, 4, 1, OVER3, 6),
422 DA9034_LDO( 6, 2500, 2850, 50, LDO643, 5, 3, OVER2, 0),
423 DA9034_LDO( 7, 2700, 3050, 50, LDO987, 0, 3, OVER2, 1),
424 DA9034_LDO( 8, 2700, 2850, 50, LDO987, 3, 2, OVER2, 2),
425 DA9034_LDO( 9, 2700, 3050, 50, LDO987, 5, 3, OVER2, 3),
426 DA9034_LDO(10, 2700, 3050, 50, LDO1110, 0, 3, OVER2, 4),
427 DA9034_LDO(11, 1800, 3300, 100, LDO1110, 4, 4, OVER2, 5),
428 DA9034_LDO(12, 1700, 3050, 50, LDO1312, 0, 4, OVER3, 6),
429 DA9034_LDO(13, 1800, 3300, 100, LDO1312, 4, 4, OVER2, 7),
430 DA9034_LDO(14, 1800, 3300, 100, LDO1514, 0, 4, OVER3, 0),
431 DA9034_LDO(15, 1800, 3300, 100, LDO1514, 4, 4, OVER3, 1),
432 DA9034_LDO(5, 3100, 3100, 0, INVAL, 0, 0, OVER3, 7), /* fixed @3.1V */
433};
434
435static inline struct da903x_regulator_info *find_regulator_info(int id)
436{
437 struct da903x_regulator_info *ri;
438 int i;
439
440 for (i = 0; i < ARRAY_SIZE(da903x_regulator_info); i++) {
441 ri = &da903x_regulator_info[i];
442 if (ri->desc.id == id)
443 return ri;
444 }
445 return NULL;
446}
447
448static int __devinit da903x_regulator_probe(struct platform_device *pdev)
449{
450 struct da903x_regulator_info *ri = NULL;
451 struct regulator_dev *rdev;
452
453 ri = find_regulator_info(pdev->id);
454 if (ri == NULL) {
455 dev_err(&pdev->dev, "invalid regulator ID specified\n");
456 return -EINVAL;
457 }
458
459 /* Workaround for the weird LDO12 voltage setting */
460 if (ri->desc.id == DA9034_ID_LDO12)
461 ri->desc.ops = &da9034_regulator_ldo12_ops;
462
463 if (ri->desc.id == DA9030_ID_LDO14)
464 ri->desc.ops = &da9030_regulator_ldo14_ops;
465
466 if (ri->desc.id == DA9030_ID_LDO1 || ri->desc.id == DA9030_ID_LDO15)
467 ri->desc.ops = &da9030_regulator_ldo1_15_ops;
468
469 rdev = regulator_register(&ri->desc, pdev->dev.parent, ri);
470 if (IS_ERR(rdev)) {
471 dev_err(&pdev->dev, "failed to register regulator %s\n",
472 ri->desc.name);
473 return PTR_ERR(rdev);
474 }
475
476 platform_set_drvdata(pdev, rdev);
477 return 0;
478}
479
480static int __devexit da903x_regulator_remove(struct platform_device *pdev)
481{
482 struct regulator_dev *rdev = platform_get_drvdata(pdev);
483
484 regulator_unregister(rdev);
485 return 0;
486}
487
488static struct platform_driver da903x_regulator_driver = {
489 .driver = {
490 .name = "da903x-regulator",
491 .owner = THIS_MODULE,
492 },
493 .probe = da903x_regulator_probe,
494 .remove = da903x_regulator_remove,
495};
496
497static int __init da903x_regulator_init(void)
498{
499 return platform_driver_register(&da903x_regulator_driver);
500}
501module_init(da903x_regulator_init);
502
503static void __exit da903x_regulator_exit(void)
504{
505 platform_driver_unregister(&da903x_regulator_driver);
506}
507module_exit(da903x_regulator_exit);
508
509MODULE_LICENSE("GPL");
510MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>"
511 "Mike Rapoport <mike@compulab.co.il>");
512MODULE_DESCRIPTION("Regulator Driver for Dialog Semiconductor DA903X PMIC");
513MODULE_ALIAS("platform:da903x-regulator");
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c
new file mode 100644
index 000000000000..1f44b17e23b1
--- /dev/null
+++ b/drivers/regulator/wm8350-regulator.c
@@ -0,0 +1,1431 @@
1/*
2 * wm8350.c -- Voltage and current regulation for the Wolfson WM8350 PMIC
3 *
4 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
5 *
6 * Author: Liam Girdwood
7 * linux@wolfsonmicro.com
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 */
14
15#include <linux/module.h>
16#include <linux/moduleparam.h>
17#include <linux/init.h>
18#include <linux/bitops.h>
19#include <linux/err.h>
20#include <linux/i2c.h>
21#include <linux/mfd/wm8350/core.h>
22#include <linux/mfd/wm8350/pmic.h>
23#include <linux/platform_device.h>
24#include <linux/regulator/driver.h>
25#include <linux/regulator/machine.h>
26
27/* Microamps */
28static const int isink_cur[] = {
29 4,
30 5,
31 6,
32 7,
33 8,
34 10,
35 11,
36 14,
37 16,
38 19,
39 23,
40 27,
41 32,
42 39,
43 46,
44 54,
45 65,
46 77,
47 92,
48 109,
49 130,
50 154,
51 183,
52 218,
53 259,
54 308,
55 367,
56 436,
57 518,
58 616,
59 733,
60 872,
61 1037,
62 1233,
63 1466,
64 1744,
65 2073,
66 2466,
67 2933,
68 3487,
69 4147,
70 4932,
71 5865,
72 6975,
73 8294,
74 9864,
75 11730,
76 13949,
77 16589,
78 19728,
79 23460,
80 27899,
81 33178,
82 39455,
83 46920,
84 55798,
85 66355,
86 78910,
87 93840,
88 111596,
89 132710,
90 157820,
91 187681,
92 223191
93};
94
95static int get_isink_val(int min_uA, int max_uA, u16 *setting)
96{
97 int i;
98
99 for (i = ARRAY_SIZE(isink_cur) - 1; i >= 0; i--) {
100 if (min_uA <= isink_cur[i] && max_uA >= isink_cur[i]) {
101 *setting = i;
102 return 0;
103 }
104 }
105 return -EINVAL;
106}
107
108static inline int wm8350_ldo_val_to_mvolts(unsigned int val)
109{
110 if (val < 16)
111 return (val * 50) + 900;
112 else
113 return ((val - 16) * 100) + 1800;
114
115}
116
117static inline unsigned int wm8350_ldo_mvolts_to_val(int mV)
118{
119 if (mV < 1800)
120 return (mV - 900) / 50;
121 else
122 return ((mV - 1800) / 100) + 16;
123}
124
125static inline int wm8350_dcdc_val_to_mvolts(unsigned int val)
126{
127 return (val * 25) + 850;
128}
129
130static inline unsigned int wm8350_dcdc_mvolts_to_val(int mV)
131{
132 return (mV - 850) / 25;
133}
134
135static int wm8350_isink_set_current(struct regulator_dev *rdev, int min_uA,
136 int max_uA)
137{
138 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
139 int isink = rdev_get_id(rdev);
140 u16 val, setting;
141 int ret;
142
143 ret = get_isink_val(min_uA, max_uA, &setting);
144 if (ret != 0)
145 return ret;
146
147 switch (isink) {
148 case WM8350_ISINK_A:
149 val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) &
150 ~WM8350_CS1_ISEL_MASK;
151 wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_A,
152 val | setting);
153 break;
154 case WM8350_ISINK_B:
155 val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) &
156 ~WM8350_CS1_ISEL_MASK;
157 wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_B,
158 val | setting);
159 break;
160 default:
161 return -EINVAL;
162 }
163
164 return 0;
165}
166
167static int wm8350_isink_get_current(struct regulator_dev *rdev)
168{
169 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
170 int isink = rdev_get_id(rdev);
171 u16 val;
172
173 switch (isink) {
174 case WM8350_ISINK_A:
175 val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) &
176 WM8350_CS1_ISEL_MASK;
177 break;
178 case WM8350_ISINK_B:
179 val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) &
180 WM8350_CS1_ISEL_MASK;
181 break;
182 default:
183 return 0;
184 }
185
186 return (isink_cur[val] + 50) / 100;
187}
188
189/* turn on ISINK followed by DCDC */
190static int wm8350_isink_enable(struct regulator_dev *rdev)
191{
192 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
193 int isink = rdev_get_id(rdev);
194
195 switch (isink) {
196 case WM8350_ISINK_A:
197 switch (wm8350->pmic.isink_A_dcdc) {
198 case WM8350_DCDC_2:
199 case WM8350_DCDC_5:
200 wm8350_set_bits(wm8350, WM8350_POWER_MGMT_7,
201 WM8350_CS1_ENA);
202 wm8350_set_bits(wm8350, WM8350_CSA_FLASH_CONTROL,
203 WM8350_CS1_DRIVE);
204 wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED,
205 1 << (wm8350->pmic.isink_A_dcdc -
206 WM8350_DCDC_1));
207 break;
208 default:
209 return -EINVAL;
210 }
211 break;
212 case WM8350_ISINK_B:
213 switch (wm8350->pmic.isink_B_dcdc) {
214 case WM8350_DCDC_2:
215 case WM8350_DCDC_5:
216 wm8350_set_bits(wm8350, WM8350_POWER_MGMT_7,
217 WM8350_CS2_ENA);
218 wm8350_set_bits(wm8350, WM8350_CSB_FLASH_CONTROL,
219 WM8350_CS2_DRIVE);
220 wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED,
221 1 << (wm8350->pmic.isink_B_dcdc -
222 WM8350_DCDC_1));
223 break;
224 default:
225 return -EINVAL;
226 }
227 break;
228 default:
229 return -EINVAL;
230 }
231 return 0;
232}
233
234static int wm8350_isink_disable(struct regulator_dev *rdev)
235{
236 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
237 int isink = rdev_get_id(rdev);
238
239 switch (isink) {
240 case WM8350_ISINK_A:
241 switch (wm8350->pmic.isink_A_dcdc) {
242 case WM8350_DCDC_2:
243 case WM8350_DCDC_5:
244 wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED,
245 1 << (wm8350->pmic.isink_A_dcdc -
246 WM8350_DCDC_1));
247 wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_7,
248 WM8350_CS1_ENA);
249 break;
250 default:
251 return -EINVAL;
252 }
253 break;
254 case WM8350_ISINK_B:
255 switch (wm8350->pmic.isink_B_dcdc) {
256 case WM8350_DCDC_2:
257 case WM8350_DCDC_5:
258 wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED,
259 1 << (wm8350->pmic.isink_B_dcdc -
260 WM8350_DCDC_1));
261 wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_7,
262 WM8350_CS2_ENA);
263 break;
264 default:
265 return -EINVAL;
266 }
267 break;
268 default:
269 return -EINVAL;
270 }
271 return 0;
272}
273
274static int wm8350_isink_is_enabled(struct regulator_dev *rdev)
275{
276 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
277 int isink = rdev_get_id(rdev);
278
279 switch (isink) {
280 case WM8350_ISINK_A:
281 return wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) &
282 0x8000;
283 case WM8350_ISINK_B:
284 return wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) &
285 0x8000;
286 }
287 return -EINVAL;
288}
289
290int wm8350_isink_set_flash(struct wm8350 *wm8350, int isink, u16 mode,
291 u16 trigger, u16 duration, u16 on_ramp, u16 off_ramp,
292 u16 drive)
293{
294 switch (isink) {
295 case WM8350_ISINK_A:
296 wm8350_reg_write(wm8350, WM8350_CSA_FLASH_CONTROL,
297 (mode ? WM8350_CS1_FLASH_MODE : 0) |
298 (trigger ? WM8350_CS1_TRIGSRC : 0) |
299 duration | on_ramp | off_ramp | drive);
300 break;
301 case WM8350_ISINK_B:
302 wm8350_reg_write(wm8350, WM8350_CSB_FLASH_CONTROL,
303 (mode ? WM8350_CS2_FLASH_MODE : 0) |
304 (trigger ? WM8350_CS2_TRIGSRC : 0) |
305 duration | on_ramp | off_ramp | drive);
306 break;
307 default:
308 return -EINVAL;
309 }
310 return 0;
311}
312EXPORT_SYMBOL_GPL(wm8350_isink_set_flash);
313
314static int wm8350_dcdc_set_voltage(struct regulator_dev *rdev, int min_uV,
315 int max_uV)
316{
317 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
318 int volt_reg, dcdc = rdev_get_id(rdev), mV,
319 min_mV = min_uV / 1000, max_mV = max_uV / 1000;
320 u16 val;
321
322 if (min_mV < 850 || min_mV > 4025)
323 return -EINVAL;
324 if (max_mV < 850 || max_mV > 4025)
325 return -EINVAL;
326
327 /* step size is 25mV */
328 mV = (min_mV - 826) / 25;
329 if (wm8350_dcdc_val_to_mvolts(mV) > max_mV)
330 return -EINVAL;
331 BUG_ON(wm8350_dcdc_val_to_mvolts(mV) < min_mV);
332
333 switch (dcdc) {
334 case WM8350_DCDC_1:
335 volt_reg = WM8350_DCDC1_CONTROL;
336 break;
337 case WM8350_DCDC_3:
338 volt_reg = WM8350_DCDC3_CONTROL;
339 break;
340 case WM8350_DCDC_4:
341 volt_reg = WM8350_DCDC4_CONTROL;
342 break;
343 case WM8350_DCDC_6:
344 volt_reg = WM8350_DCDC6_CONTROL;
345 break;
346 case WM8350_DCDC_2:
347 case WM8350_DCDC_5:
348 default:
349 return -EINVAL;
350 }
351
352 /* all DCDCs have same mV bits */
353 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK;
354 wm8350_reg_write(wm8350, volt_reg, val | mV);
355 return 0;
356}
357
358static int wm8350_dcdc_get_voltage(struct regulator_dev *rdev)
359{
360 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
361 int volt_reg, dcdc = rdev_get_id(rdev);
362 u16 val;
363
364 switch (dcdc) {
365 case WM8350_DCDC_1:
366 volt_reg = WM8350_DCDC1_CONTROL;
367 break;
368 case WM8350_DCDC_3:
369 volt_reg = WM8350_DCDC3_CONTROL;
370 break;
371 case WM8350_DCDC_4:
372 volt_reg = WM8350_DCDC4_CONTROL;
373 break;
374 case WM8350_DCDC_6:
375 volt_reg = WM8350_DCDC6_CONTROL;
376 break;
377 case WM8350_DCDC_2:
378 case WM8350_DCDC_5:
379 default:
380 return -EINVAL;
381 }
382
383 /* all DCDCs have same mV bits */
384 val = wm8350_reg_read(wm8350, volt_reg) & WM8350_DC1_VSEL_MASK;
385 return wm8350_dcdc_val_to_mvolts(val) * 1000;
386}
387
388static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV)
389{
390 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
391 int volt_reg, mV = uV / 1000, dcdc = rdev_get_id(rdev);
392 u16 val;
393
394 dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, dcdc, mV);
395
396 if (mV && (mV < 850 || mV > 4025)) {
397 dev_err(wm8350->dev,
398 "DCDC%d suspend voltage %d mV out of range\n",
399 dcdc, mV);
400 return -EINVAL;
401 }
402 if (mV == 0)
403 mV = 850;
404
405 switch (dcdc) {
406 case WM8350_DCDC_1:
407 volt_reg = WM8350_DCDC1_LOW_POWER;
408 break;
409 case WM8350_DCDC_3:
410 volt_reg = WM8350_DCDC3_LOW_POWER;
411 break;
412 case WM8350_DCDC_4:
413 volt_reg = WM8350_DCDC4_LOW_POWER;
414 break;
415 case WM8350_DCDC_6:
416 volt_reg = WM8350_DCDC6_LOW_POWER;
417 break;
418 case WM8350_DCDC_2:
419 case WM8350_DCDC_5:
420 default:
421 return -EINVAL;
422 }
423
424 /* all DCDCs have same mV bits */
425 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK;
426 wm8350_reg_write(wm8350, volt_reg,
427 val | wm8350_dcdc_mvolts_to_val(mV));
428 return 0;
429}
430
431static int wm8350_dcdc_set_suspend_enable(struct regulator_dev *rdev)
432{
433 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
434 int dcdc = rdev_get_id(rdev);
435 u16 val;
436
437 switch (dcdc) {
438 case WM8350_DCDC_1:
439 val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER)
440 & ~WM8350_DCDC_HIB_MODE_MASK;
441 wm8350_reg_write(wm8350, WM8350_DCDC1_LOW_POWER,
442 wm8350->pmic.dcdc1_hib_mode);
443 break;
444 case WM8350_DCDC_3:
445 val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER)
446 & ~WM8350_DCDC_HIB_MODE_MASK;
447 wm8350_reg_write(wm8350, WM8350_DCDC3_LOW_POWER,
448 wm8350->pmic.dcdc3_hib_mode);
449 break;
450 case WM8350_DCDC_4:
451 val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER)
452 & ~WM8350_DCDC_HIB_MODE_MASK;
453 wm8350_reg_write(wm8350, WM8350_DCDC4_LOW_POWER,
454 wm8350->pmic.dcdc4_hib_mode);
455 break;
456 case WM8350_DCDC_6:
457 val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER)
458 & ~WM8350_DCDC_HIB_MODE_MASK;
459 wm8350_reg_write(wm8350, WM8350_DCDC6_LOW_POWER,
460 wm8350->pmic.dcdc6_hib_mode);
461 break;
462 case WM8350_DCDC_2:
463 case WM8350_DCDC_5:
464 default:
465 return -EINVAL;
466 }
467
468 return 0;
469}
470
471static int wm8350_dcdc_set_suspend_disable(struct regulator_dev *rdev)
472{
473 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
474 int dcdc = rdev_get_id(rdev);
475 u16 val;
476
477 switch (dcdc) {
478 case WM8350_DCDC_1:
479 val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER);
480 wm8350->pmic.dcdc1_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
481 wm8350_reg_write(wm8350, WM8350_DCDC1_LOW_POWER,
482 WM8350_DCDC_HIB_MODE_DIS);
483 break;
484 case WM8350_DCDC_3:
485 val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER);
486 wm8350->pmic.dcdc3_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
487 wm8350_reg_write(wm8350, WM8350_DCDC3_LOW_POWER,
488 WM8350_DCDC_HIB_MODE_DIS);
489 break;
490 case WM8350_DCDC_4:
491 val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER);
492 wm8350->pmic.dcdc4_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
493 wm8350_reg_write(wm8350, WM8350_DCDC4_LOW_POWER,
494 WM8350_DCDC_HIB_MODE_DIS);
495 break;
496 case WM8350_DCDC_6:
497 val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER);
498 wm8350->pmic.dcdc6_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
499 wm8350_reg_write(wm8350, WM8350_DCDC6_LOW_POWER,
500 WM8350_DCDC_HIB_MODE_DIS);
501 break;
502 case WM8350_DCDC_2:
503 case WM8350_DCDC_5:
504 default:
505 return -EINVAL;
506 }
507
508 return 0;
509}
510
511static int wm8350_dcdc25_set_suspend_enable(struct regulator_dev *rdev)
512{
513 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
514 int dcdc = rdev_get_id(rdev);
515 u16 val;
516
517 switch (dcdc) {
518 case WM8350_DCDC_2:
519 val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL)
520 & ~WM8350_DC2_HIB_MODE_MASK;
521 wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val |
522 WM8350_DC2_HIB_MODE_ACTIVE);
523 break;
524 case WM8350_DCDC_5:
525 val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL)
526 & ~WM8350_DC2_HIB_MODE_MASK;
527 wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val |
528 WM8350_DC5_HIB_MODE_ACTIVE);
529 break;
530 default:
531 return -EINVAL;
532 }
533 return 0;
534}
535
536static int wm8350_dcdc25_set_suspend_disable(struct regulator_dev *rdev)
537{
538 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
539 int dcdc = rdev_get_id(rdev);
540 u16 val;
541
542 switch (dcdc) {
543 case WM8350_DCDC_2:
544 val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL)
545 & ~WM8350_DC2_HIB_MODE_MASK;
546 wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val |
547 WM8350_DC2_HIB_MODE_DISABLE);
548 break;
549 case WM8350_DCDC_5:
550 val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL)
551 & ~WM8350_DC2_HIB_MODE_MASK;
552 wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val |
553 WM8350_DC2_HIB_MODE_DISABLE);
554 break;
555 default:
556 return -EINVAL;
557 }
558 return 0;
559}
560
561static int wm8350_dcdc_set_suspend_mode(struct regulator_dev *rdev,
562 unsigned int mode)
563{
564 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
565 int dcdc = rdev_get_id(rdev);
566 u16 *hib_mode;
567
568 switch (dcdc) {
569 case WM8350_DCDC_1:
570 hib_mode = &wm8350->pmic.dcdc1_hib_mode;
571 break;
572 case WM8350_DCDC_3:
573 hib_mode = &wm8350->pmic.dcdc3_hib_mode;
574 break;
575 case WM8350_DCDC_4:
576 hib_mode = &wm8350->pmic.dcdc4_hib_mode;
577 break;
578 case WM8350_DCDC_6:
579 hib_mode = &wm8350->pmic.dcdc6_hib_mode;
580 break;
581 case WM8350_DCDC_2:
582 case WM8350_DCDC_5:
583 default:
584 return -EINVAL;
585 }
586
587 switch (mode) {
588 case REGULATOR_MODE_NORMAL:
589 *hib_mode = WM8350_DCDC_HIB_MODE_IMAGE;
590 break;
591 case REGULATOR_MODE_IDLE:
592 *hib_mode = WM8350_DCDC_HIB_MODE_STANDBY;
593 break;
594 case REGULATOR_MODE_STANDBY:
595 *hib_mode = WM8350_DCDC_HIB_MODE_LDO_IM;
596 break;
597 default:
598 return -EINVAL;
599 }
600
601 return 0;
602}
603
604static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV)
605{
606 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
607 int volt_reg, mV = uV / 1000, ldo = rdev_get_id(rdev);
608 u16 val;
609
610 dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, ldo, mV);
611
612 if (mV < 900 || mV > 3300) {
613 dev_err(wm8350->dev, "LDO%d voltage %d mV out of range\n",
614 ldo, mV);
615 return -EINVAL;
616 }
617
618 switch (ldo) {
619 case WM8350_LDO_1:
620 volt_reg = WM8350_LDO1_LOW_POWER;
621 break;
622 case WM8350_LDO_2:
623 volt_reg = WM8350_LDO2_LOW_POWER;
624 break;
625 case WM8350_LDO_3:
626 volt_reg = WM8350_LDO3_LOW_POWER;
627 break;
628 case WM8350_LDO_4:
629 volt_reg = WM8350_LDO4_LOW_POWER;
630 break;
631 default:
632 return -EINVAL;
633 }
634
635 /* all LDOs have same mV bits */
636 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK;
637 wm8350_reg_write(wm8350, volt_reg,
638 val | wm8350_ldo_mvolts_to_val(mV));
639 return 0;
640}
641
642static int wm8350_ldo_set_suspend_enable(struct regulator_dev *rdev)
643{
644 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
645 int volt_reg, ldo = rdev_get_id(rdev);
646 u16 val;
647
648 switch (ldo) {
649 case WM8350_LDO_1:
650 volt_reg = WM8350_LDO1_LOW_POWER;
651 break;
652 case WM8350_LDO_2:
653 volt_reg = WM8350_LDO2_LOW_POWER;
654 break;
655 case WM8350_LDO_3:
656 volt_reg = WM8350_LDO3_LOW_POWER;
657 break;
658 case WM8350_LDO_4:
659 volt_reg = WM8350_LDO4_LOW_POWER;
660 break;
661 default:
662 return -EINVAL;
663 }
664
665 /* all LDOs have same mV bits */
666 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_HIB_MODE_MASK;
667 wm8350_reg_write(wm8350, volt_reg, val);
668 return 0;
669}
670
671static int wm8350_ldo_set_suspend_disable(struct regulator_dev *rdev)
672{
673 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
674 int volt_reg, ldo = rdev_get_id(rdev);
675 u16 val;
676
677 switch (ldo) {
678 case WM8350_LDO_1:
679 volt_reg = WM8350_LDO1_LOW_POWER;
680 break;
681 case WM8350_LDO_2:
682 volt_reg = WM8350_LDO2_LOW_POWER;
683 break;
684 case WM8350_LDO_3:
685 volt_reg = WM8350_LDO3_LOW_POWER;
686 break;
687 case WM8350_LDO_4:
688 volt_reg = WM8350_LDO4_LOW_POWER;
689 break;
690 default:
691 return -EINVAL;
692 }
693
694 /* all LDOs have same mV bits */
695 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_HIB_MODE_MASK;
696 wm8350_reg_write(wm8350, volt_reg, WM8350_LDO1_HIB_MODE_DIS);
697 return 0;
698}
699
700static int wm8350_ldo_set_voltage(struct regulator_dev *rdev, int min_uV,
701 int max_uV)
702{
703 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
704 int volt_reg, ldo = rdev_get_id(rdev), mV, min_mV = min_uV / 1000,
705 max_mV = max_uV / 1000;
706 u16 val;
707
708 if (min_mV < 900 || min_mV > 3300)
709 return -EINVAL;
710 if (max_mV < 900 || max_mV > 3300)
711 return -EINVAL;
712
713 if (min_mV < 1800) {
714 /* step size is 50mV < 1800mV */
715 mV = (min_mV - 851) / 50;
716 if (wm8350_ldo_val_to_mvolts(mV) > max_mV)
717 return -EINVAL;
718 BUG_ON(wm8350_ldo_val_to_mvolts(mV) < min_mV);
719 } else {
720 /* step size is 100mV > 1800mV */
721 mV = ((min_mV - 1701) / 100) + 16;
722 if (wm8350_ldo_val_to_mvolts(mV) > max_mV)
723 return -EINVAL;
724 BUG_ON(wm8350_ldo_val_to_mvolts(mV) < min_mV);
725 }
726
727 switch (ldo) {
728 case WM8350_LDO_1:
729 volt_reg = WM8350_LDO1_CONTROL;
730 break;
731 case WM8350_LDO_2:
732 volt_reg = WM8350_LDO2_CONTROL;
733 break;
734 case WM8350_LDO_3:
735 volt_reg = WM8350_LDO3_CONTROL;
736 break;
737 case WM8350_LDO_4:
738 volt_reg = WM8350_LDO4_CONTROL;
739 break;
740 default:
741 return -EINVAL;
742 }
743
744 /* all LDOs have same mV bits */
745 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK;
746 wm8350_reg_write(wm8350, volt_reg, val | mV);
747 return 0;
748}
749
750static int wm8350_ldo_get_voltage(struct regulator_dev *rdev)
751{
752 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
753 int volt_reg, ldo = rdev_get_id(rdev);
754 u16 val;
755
756 switch (ldo) {
757 case WM8350_LDO_1:
758 volt_reg = WM8350_LDO1_CONTROL;
759 break;
760 case WM8350_LDO_2:
761 volt_reg = WM8350_LDO2_CONTROL;
762 break;
763 case WM8350_LDO_3:
764 volt_reg = WM8350_LDO3_CONTROL;
765 break;
766 case WM8350_LDO_4:
767 volt_reg = WM8350_LDO4_CONTROL;
768 break;
769 default:
770 return -EINVAL;
771 }
772
773 /* all LDOs have same mV bits */
774 val = wm8350_reg_read(wm8350, volt_reg) & WM8350_LDO1_VSEL_MASK;
775 return wm8350_ldo_val_to_mvolts(val) * 1000;
776}
777
778int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start,
779 u16 stop, u16 fault)
780{
781 int slot_reg;
782 u16 val;
783
784 dev_dbg(wm8350->dev, "%s %d start %d stop %d\n",
785 __func__, dcdc, start, stop);
786
787 /* slot valid ? */
788 if (start > 15 || stop > 15)
789 return -EINVAL;
790
791 switch (dcdc) {
792 case WM8350_DCDC_1:
793 slot_reg = WM8350_DCDC1_TIMEOUTS;
794 break;
795 case WM8350_DCDC_2:
796 slot_reg = WM8350_DCDC2_TIMEOUTS;
797 break;
798 case WM8350_DCDC_3:
799 slot_reg = WM8350_DCDC3_TIMEOUTS;
800 break;
801 case WM8350_DCDC_4:
802 slot_reg = WM8350_DCDC4_TIMEOUTS;
803 break;
804 case WM8350_DCDC_5:
805 slot_reg = WM8350_DCDC5_TIMEOUTS;
806 break;
807 case WM8350_DCDC_6:
808 slot_reg = WM8350_DCDC6_TIMEOUTS;
809 break;
810 default:
811 return -EINVAL;
812 }
813
814 val = wm8350_reg_read(wm8350, slot_reg) &
815 ~(WM8350_DC1_ENSLOT_MASK | WM8350_DC1_SDSLOT_MASK |
816 WM8350_DC1_ERRACT_MASK);
817 wm8350_reg_write(wm8350, slot_reg,
818 val | (start << WM8350_DC1_ENSLOT_SHIFT) |
819 (stop << WM8350_DC1_SDSLOT_SHIFT) |
820 (fault << WM8350_DC1_ERRACT_SHIFT));
821
822 return 0;
823}
824EXPORT_SYMBOL_GPL(wm8350_dcdc_set_slot);
825
826int wm8350_ldo_set_slot(struct wm8350 *wm8350, int ldo, u16 start, u16 stop)
827{
828 int slot_reg;
829 u16 val;
830
831 dev_dbg(wm8350->dev, "%s %d start %d stop %d\n",
832 __func__, ldo, start, stop);
833
834 /* slot valid ? */
835 if (start > 15 || stop > 15)
836 return -EINVAL;
837
838 switch (ldo) {
839 case WM8350_LDO_1:
840 slot_reg = WM8350_LDO1_TIMEOUTS;
841 break;
842 case WM8350_LDO_2:
843 slot_reg = WM8350_LDO2_TIMEOUTS;
844 break;
845 case WM8350_LDO_3:
846 slot_reg = WM8350_LDO3_TIMEOUTS;
847 break;
848 case WM8350_LDO_4:
849 slot_reg = WM8350_LDO4_TIMEOUTS;
850 break;
851 default:
852 return -EINVAL;
853 }
854
855 val = wm8350_reg_read(wm8350, slot_reg) & ~WM8350_LDO1_SDSLOT_MASK;
856 wm8350_reg_write(wm8350, slot_reg, val | ((start << 10) | (stop << 6)));
857 return 0;
858}
859EXPORT_SYMBOL_GPL(wm8350_ldo_set_slot);
860
861int wm8350_dcdc25_set_mode(struct wm8350 *wm8350, int dcdc, u16 mode,
862 u16 ilim, u16 ramp, u16 feedback)
863{
864 u16 val;
865
866 dev_dbg(wm8350->dev, "%s %d mode: %s %s\n", __func__, dcdc,
867 mode ? "normal" : "boost", ilim ? "low" : "normal");
868
869 switch (dcdc) {
870 case WM8350_DCDC_2:
871 val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL)
872 & ~(WM8350_DC2_MODE_MASK | WM8350_DC2_ILIM_MASK |
873 WM8350_DC2_RMP_MASK | WM8350_DC2_FBSRC_MASK);
874 wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val |
875 (mode << WM8350_DC2_MODE_SHIFT) |
876 (ilim << WM8350_DC2_ILIM_SHIFT) |
877 (ramp << WM8350_DC2_RMP_SHIFT) |
878 (feedback << WM8350_DC2_FBSRC_SHIFT));
879 break;
880 case WM8350_DCDC_5:
881 val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL)
882 & ~(WM8350_DC5_MODE_MASK | WM8350_DC5_ILIM_MASK |
883 WM8350_DC5_RMP_MASK | WM8350_DC5_FBSRC_MASK);
884 wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val |
885 (mode << WM8350_DC5_MODE_SHIFT) |
886 (ilim << WM8350_DC5_ILIM_SHIFT) |
887 (ramp << WM8350_DC5_RMP_SHIFT) |
888 (feedback << WM8350_DC5_FBSRC_SHIFT));
889 break;
890 default:
891 return -EINVAL;
892 }
893
894 return 0;
895}
896EXPORT_SYMBOL_GPL(wm8350_dcdc25_set_mode);
897
898static int wm8350_dcdc_enable(struct regulator_dev *rdev)
899{
900 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
901 int dcdc = rdev_get_id(rdev);
902 u16 shift;
903
904 if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6)
905 return -EINVAL;
906
907 shift = dcdc - WM8350_DCDC_1;
908 wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift);
909 return 0;
910}
911
912static int wm8350_dcdc_disable(struct regulator_dev *rdev)
913{
914 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
915 int dcdc = rdev_get_id(rdev);
916 u16 shift;
917
918 if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6)
919 return -EINVAL;
920
921 shift = dcdc - WM8350_DCDC_1;
922 wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift);
923
924 return 0;
925}
926
927static int wm8350_ldo_enable(struct regulator_dev *rdev)
928{
929 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
930 int ldo = rdev_get_id(rdev);
931 u16 shift;
932
933 if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4)
934 return -EINVAL;
935
936 shift = (ldo - WM8350_LDO_1) + 8;
937 wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift);
938 return 0;
939}
940
941static int wm8350_ldo_disable(struct regulator_dev *rdev)
942{
943 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
944 int ldo = rdev_get_id(rdev);
945 u16 shift;
946
947 if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4)
948 return -EINVAL;
949
950 shift = (ldo - WM8350_LDO_1) + 8;
951 wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift);
952 return 0;
953}
954
955static int force_continuous_enable(struct wm8350 *wm8350, int dcdc, int enable)
956{
957 int reg = 0, ret;
958
959 switch (dcdc) {
960 case WM8350_DCDC_1:
961 reg = WM8350_DCDC1_FORCE_PWM;
962 break;
963 case WM8350_DCDC_3:
964 reg = WM8350_DCDC3_FORCE_PWM;
965 break;
966 case WM8350_DCDC_4:
967 reg = WM8350_DCDC4_FORCE_PWM;
968 break;
969 case WM8350_DCDC_6:
970 reg = WM8350_DCDC6_FORCE_PWM;
971 break;
972 default:
973 return -EINVAL;
974 }
975
976 if (enable)
977 ret = wm8350_set_bits(wm8350, reg,
978 WM8350_DCDC1_FORCE_PWM_ENA);
979 else
980 ret = wm8350_clear_bits(wm8350, reg,
981 WM8350_DCDC1_FORCE_PWM_ENA);
982 return ret;
983}
984
985static int wm8350_dcdc_set_mode(struct regulator_dev *rdev, unsigned int mode)
986{
987 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
988 int dcdc = rdev_get_id(rdev);
989 u16 val;
990
991 if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6)
992 return -EINVAL;
993
994 if (dcdc == WM8350_DCDC_2 || dcdc == WM8350_DCDC_5)
995 return -EINVAL;
996
997 val = 1 << (dcdc - WM8350_DCDC_1);
998
999 switch (mode) {
1000 case REGULATOR_MODE_FAST:
1001 /* force continuous mode */
1002 wm8350_set_bits(wm8350, WM8350_DCDC_ACTIVE_OPTIONS, val);
1003 wm8350_clear_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val);
1004 force_continuous_enable(wm8350, dcdc, 1);
1005 break;
1006 case REGULATOR_MODE_NORMAL:
1007 /* active / pulse skipping */
1008 wm8350_set_bits(wm8350, WM8350_DCDC_ACTIVE_OPTIONS, val);
1009 wm8350_clear_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val);
1010 force_continuous_enable(wm8350, dcdc, 0);
1011 break;
1012 case REGULATOR_MODE_IDLE:
1013 /* standby mode */
1014 force_continuous_enable(wm8350, dcdc, 0);
1015 wm8350_clear_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val);
1016 wm8350_clear_bits(wm8350, WM8350_DCDC_ACTIVE_OPTIONS, val);
1017 break;
1018 case REGULATOR_MODE_STANDBY:
1019 /* LDO mode */
1020 force_continuous_enable(wm8350, dcdc, 0);
1021 wm8350_set_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val);
1022 break;
1023 }
1024
1025 return 0;
1026}
1027
1028static unsigned int wm8350_dcdc_get_mode(struct regulator_dev *rdev)
1029{
1030 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
1031 int dcdc = rdev_get_id(rdev);
1032 u16 mask, sleep, active, force;
1033 int mode = REGULATOR_MODE_NORMAL;
1034
1035 if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6)
1036 return -EINVAL;
1037
1038 if (dcdc == WM8350_DCDC_2 || dcdc == WM8350_DCDC_5)
1039 return -EINVAL;
1040
1041 mask = 1 << (dcdc - WM8350_DCDC_1);
1042 active = wm8350_reg_read(wm8350, WM8350_DCDC_ACTIVE_OPTIONS) & mask;
1043 sleep = wm8350_reg_read(wm8350, WM8350_DCDC_SLEEP_OPTIONS) & mask;
1044 force = wm8350_reg_read(wm8350, WM8350_DCDC1_FORCE_PWM)
1045 & WM8350_DCDC1_FORCE_PWM_ENA;
1046 dev_dbg(wm8350->dev, "mask %x active %x sleep %x force %x",
1047 mask, active, sleep, force);
1048
1049 if (active && !sleep) {
1050 if (force)
1051 mode = REGULATOR_MODE_FAST;
1052 else
1053 mode = REGULATOR_MODE_NORMAL;
1054 } else if (!active && !sleep)
1055 mode = REGULATOR_MODE_IDLE;
1056 else if (!sleep)
1057 mode = REGULATOR_MODE_STANDBY;
1058
1059 return mode;
1060}
1061
1062static unsigned int wm8350_ldo_get_mode(struct regulator_dev *rdev)
1063{
1064 return REGULATOR_MODE_NORMAL;
1065}
1066
1067struct wm8350_dcdc_efficiency {
1068 int uA_load_min;
1069 int uA_load_max;
1070 unsigned int mode;
1071};
1072
1073static const struct wm8350_dcdc_efficiency dcdc1_6_efficiency[] = {
1074 {0, 10000, REGULATOR_MODE_STANDBY}, /* 0 - 10mA - LDO */
1075 {10000, 100000, REGULATOR_MODE_IDLE}, /* 10mA - 100mA - Standby */
1076 {100000, 1000000, REGULATOR_MODE_NORMAL}, /* > 100mA - Active */
1077 {-1, -1, REGULATOR_MODE_NORMAL},
1078};
1079
1080static const struct wm8350_dcdc_efficiency dcdc3_4_efficiency[] = {
1081 {0, 10000, REGULATOR_MODE_STANDBY}, /* 0 - 10mA - LDO */
1082 {10000, 100000, REGULATOR_MODE_IDLE}, /* 10mA - 100mA - Standby */
1083 {100000, 800000, REGULATOR_MODE_NORMAL}, /* > 100mA - Active */
1084 {-1, -1, REGULATOR_MODE_NORMAL},
1085};
1086
1087static unsigned int get_mode(int uA, const struct wm8350_dcdc_efficiency *eff)
1088{
1089 int i = 0;
1090
1091 while (eff[i].uA_load_min != -1) {
1092 if (uA >= eff[i].uA_load_min && uA <= eff[i].uA_load_max)
1093 return eff[i].mode;
1094 }
1095 return REGULATOR_MODE_NORMAL;
1096}
1097
1098/* Query the regulator for it's most efficient mode @ uV,uA
1099 * WM8350 regulator efficiency is pretty similar over
1100 * different input and output uV.
1101 */
1102static unsigned int wm8350_dcdc_get_optimum_mode(struct regulator_dev *rdev,
1103 int input_uV, int output_uV,
1104 int output_uA)
1105{
1106 int dcdc = rdev_get_id(rdev), mode;
1107
1108 switch (dcdc) {
1109 case WM8350_DCDC_1:
1110 case WM8350_DCDC_6:
1111 mode = get_mode(output_uA, dcdc1_6_efficiency);
1112 break;
1113 case WM8350_DCDC_3:
1114 case WM8350_DCDC_4:
1115 mode = get_mode(output_uA, dcdc3_4_efficiency);
1116 break;
1117 default:
1118 mode = REGULATOR_MODE_NORMAL;
1119 break;
1120 }
1121 return mode;
1122}
1123
1124static int wm8350_dcdc_is_enabled(struct regulator_dev *rdev)
1125{
1126 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
1127 int dcdc = rdev_get_id(rdev), shift;
1128
1129 if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6)
1130 return -EINVAL;
1131
1132 shift = dcdc - WM8350_DCDC_1;
1133 return wm8350_reg_read(wm8350, WM8350_DCDC_LDO_REQUESTED)
1134 & (1 << shift);
1135}
1136
1137static int wm8350_ldo_is_enabled(struct regulator_dev *rdev)
1138{
1139 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
1140 int ldo = rdev_get_id(rdev), shift;
1141
1142 if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4)
1143 return -EINVAL;
1144
1145 shift = (ldo - WM8350_LDO_1) + 8;
1146 return wm8350_reg_read(wm8350, WM8350_DCDC_LDO_REQUESTED)
1147 & (1 << shift);
1148}
1149
1150static struct regulator_ops wm8350_dcdc_ops = {
1151 .set_voltage = wm8350_dcdc_set_voltage,
1152 .get_voltage = wm8350_dcdc_get_voltage,
1153 .enable = wm8350_dcdc_enable,
1154 .disable = wm8350_dcdc_disable,
1155 .get_mode = wm8350_dcdc_get_mode,
1156 .set_mode = wm8350_dcdc_set_mode,
1157 .get_optimum_mode = wm8350_dcdc_get_optimum_mode,
1158 .is_enabled = wm8350_dcdc_is_enabled,
1159 .set_suspend_voltage = wm8350_dcdc_set_suspend_voltage,
1160 .set_suspend_enable = wm8350_dcdc_set_suspend_enable,
1161 .set_suspend_disable = wm8350_dcdc_set_suspend_disable,
1162 .set_suspend_mode = wm8350_dcdc_set_suspend_mode,
1163};
1164
1165static struct regulator_ops wm8350_dcdc2_5_ops = {
1166 .enable = wm8350_dcdc_enable,
1167 .disable = wm8350_dcdc_disable,
1168 .is_enabled = wm8350_dcdc_is_enabled,
1169 .set_suspend_enable = wm8350_dcdc25_set_suspend_enable,
1170 .set_suspend_disable = wm8350_dcdc25_set_suspend_disable,
1171};
1172
1173static struct regulator_ops wm8350_ldo_ops = {
1174 .set_voltage = wm8350_ldo_set_voltage,
1175 .get_voltage = wm8350_ldo_get_voltage,
1176 .enable = wm8350_ldo_enable,
1177 .disable = wm8350_ldo_disable,
1178 .is_enabled = wm8350_ldo_is_enabled,
1179 .get_mode = wm8350_ldo_get_mode,
1180 .set_suspend_voltage = wm8350_ldo_set_suspend_voltage,
1181 .set_suspend_enable = wm8350_ldo_set_suspend_enable,
1182 .set_suspend_disable = wm8350_ldo_set_suspend_disable,
1183};
1184
1185static struct regulator_ops wm8350_isink_ops = {
1186 .set_current_limit = wm8350_isink_set_current,
1187 .get_current_limit = wm8350_isink_get_current,
1188 .enable = wm8350_isink_enable,
1189 .disable = wm8350_isink_disable,
1190 .is_enabled = wm8350_isink_is_enabled,
1191};
1192
1193static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
1194 {
1195 .name = "DCDC1",
1196 .id = WM8350_DCDC_1,
1197 .ops = &wm8350_dcdc_ops,
1198 .irq = WM8350_IRQ_UV_DC1,
1199 .type = REGULATOR_VOLTAGE,
1200 .owner = THIS_MODULE,
1201 },
1202 {
1203 .name = "DCDC2",
1204 .id = WM8350_DCDC_2,
1205 .ops = &wm8350_dcdc2_5_ops,
1206 .irq = WM8350_IRQ_UV_DC2,
1207 .type = REGULATOR_VOLTAGE,
1208 .owner = THIS_MODULE,
1209 },
1210 {
1211 .name = "DCDC3",
1212 .id = WM8350_DCDC_3,
1213 .ops = &wm8350_dcdc_ops,
1214 .irq = WM8350_IRQ_UV_DC3,
1215 .type = REGULATOR_VOLTAGE,
1216 .owner = THIS_MODULE,
1217 },
1218 {
1219 .name = "DCDC4",
1220 .id = WM8350_DCDC_4,
1221 .ops = &wm8350_dcdc_ops,
1222 .irq = WM8350_IRQ_UV_DC4,
1223 .type = REGULATOR_VOLTAGE,
1224 .owner = THIS_MODULE,
1225 },
1226 {
1227 .name = "DCDC5",
1228 .id = WM8350_DCDC_5,
1229 .ops = &wm8350_dcdc2_5_ops,
1230 .irq = WM8350_IRQ_UV_DC5,
1231 .type = REGULATOR_VOLTAGE,
1232 .owner = THIS_MODULE,
1233 },
1234 {
1235 .name = "DCDC6",
1236 .id = WM8350_DCDC_6,
1237 .ops = &wm8350_dcdc_ops,
1238 .irq = WM8350_IRQ_UV_DC6,
1239 .type = REGULATOR_VOLTAGE,
1240 .owner = THIS_MODULE,
1241 },
1242 {
1243 .name = "LDO1",
1244 .id = WM8350_LDO_1,
1245 .ops = &wm8350_ldo_ops,
1246 .irq = WM8350_IRQ_UV_LDO1,
1247 .type = REGULATOR_VOLTAGE,
1248 .owner = THIS_MODULE,
1249 },
1250 {
1251 .name = "LDO2",
1252 .id = WM8350_LDO_2,
1253 .ops = &wm8350_ldo_ops,
1254 .irq = WM8350_IRQ_UV_LDO2,
1255 .type = REGULATOR_VOLTAGE,
1256 .owner = THIS_MODULE,
1257 },
1258 {
1259 .name = "LDO3",
1260 .id = WM8350_LDO_3,
1261 .ops = &wm8350_ldo_ops,
1262 .irq = WM8350_IRQ_UV_LDO3,
1263 .type = REGULATOR_VOLTAGE,
1264 .owner = THIS_MODULE,
1265 },
1266 {
1267 .name = "LDO4",
1268 .id = WM8350_LDO_4,
1269 .ops = &wm8350_ldo_ops,
1270 .irq = WM8350_IRQ_UV_LDO4,
1271 .type = REGULATOR_VOLTAGE,
1272 .owner = THIS_MODULE,
1273 },
1274 {
1275 .name = "ISINKA",
1276 .id = WM8350_ISINK_A,
1277 .ops = &wm8350_isink_ops,
1278 .irq = WM8350_IRQ_CS1,
1279 .type = REGULATOR_CURRENT,
1280 .owner = THIS_MODULE,
1281 },
1282 {
1283 .name = "ISINKB",
1284 .id = WM8350_ISINK_B,
1285 .ops = &wm8350_isink_ops,
1286 .irq = WM8350_IRQ_CS2,
1287 .type = REGULATOR_CURRENT,
1288 .owner = THIS_MODULE,
1289 },
1290};
1291
1292static void pmic_uv_handler(struct wm8350 *wm8350, int irq, void *data)
1293{
1294 struct regulator_dev *rdev = (struct regulator_dev *)data;
1295
1296 if (irq == WM8350_IRQ_CS1 || irq == WM8350_IRQ_CS2)
1297 regulator_notifier_call_chain(rdev,
1298 REGULATOR_EVENT_REGULATION_OUT,
1299 wm8350);
1300 else
1301 regulator_notifier_call_chain(rdev,
1302 REGULATOR_EVENT_UNDER_VOLTAGE,
1303 wm8350);
1304}
1305
1306static int wm8350_regulator_probe(struct platform_device *pdev)
1307{
1308 struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev);
1309 struct regulator_dev *rdev;
1310 int ret;
1311 u16 val;
1312
1313 if (pdev->id < WM8350_DCDC_1 || pdev->id > WM8350_ISINK_B)
1314 return -ENODEV;
1315
1316 /* do any regulatior specific init */
1317 switch (pdev->id) {
1318 case WM8350_DCDC_1:
1319 val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER);
1320 wm8350->pmic.dcdc1_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
1321 break;
1322 case WM8350_DCDC_3:
1323 val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER);
1324 wm8350->pmic.dcdc3_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
1325 break;
1326 case WM8350_DCDC_4:
1327 val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER);
1328 wm8350->pmic.dcdc4_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
1329 break;
1330 case WM8350_DCDC_6:
1331 val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER);
1332 wm8350->pmic.dcdc6_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
1333 break;
1334 }
1335
1336
1337 /* register regulator */
1338 rdev = regulator_register(&wm8350_reg[pdev->id], &pdev->dev,
1339 dev_get_drvdata(&pdev->dev));
1340 if (IS_ERR(rdev)) {
1341 dev_err(&pdev->dev, "failed to register %s\n",
1342 wm8350_reg[pdev->id].name);
1343 return PTR_ERR(rdev);
1344 }
1345
1346 /* register regulator IRQ */
1347 ret = wm8350_register_irq(wm8350, wm8350_reg[pdev->id].irq,
1348 pmic_uv_handler, rdev);
1349 if (ret < 0) {
1350 regulator_unregister(rdev);
1351 dev_err(&pdev->dev, "failed to register regulator %s IRQ\n",
1352 wm8350_reg[pdev->id].name);
1353 return ret;
1354 }
1355
1356 wm8350_unmask_irq(wm8350, wm8350_reg[pdev->id].irq);
1357
1358 return 0;
1359}
1360
1361static int wm8350_regulator_remove(struct platform_device *pdev)
1362{
1363 struct regulator_dev *rdev = platform_get_drvdata(pdev);
1364 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
1365
1366 wm8350_mask_irq(wm8350, wm8350_reg[pdev->id].irq);
1367 wm8350_free_irq(wm8350, wm8350_reg[pdev->id].irq);
1368
1369 regulator_unregister(rdev);
1370
1371 return 0;
1372}
1373
1374int wm8350_register_regulator(struct wm8350 *wm8350, int reg,
1375 struct regulator_init_data *initdata)
1376{
1377 struct platform_device *pdev;
1378 int ret;
1379
1380 if (wm8350->pmic.pdev[reg])
1381 return -EBUSY;
1382
1383 pdev = platform_device_alloc("wm8350-regulator", reg);
1384 if (!pdev)
1385 return -ENOMEM;
1386
1387 wm8350->pmic.pdev[reg] = pdev;
1388
1389 initdata->driver_data = wm8350;
1390
1391 pdev->dev.platform_data = initdata;
1392 pdev->dev.parent = wm8350->dev;
1393 platform_set_drvdata(pdev, wm8350);
1394
1395 ret = platform_device_add(pdev);
1396
1397 if (ret != 0) {
1398 dev_err(wm8350->dev, "Failed to register regulator %d: %d\n",
1399 reg, ret);
1400 platform_device_del(pdev);
1401 wm8350->pmic.pdev[reg] = NULL;
1402 }
1403
1404 return ret;
1405}
1406EXPORT_SYMBOL_GPL(wm8350_register_regulator);
1407
1408static struct platform_driver wm8350_regulator_driver = {
1409 .probe = wm8350_regulator_probe,
1410 .remove = wm8350_regulator_remove,
1411 .driver = {
1412 .name = "wm8350-regulator",
1413 },
1414};
1415
1416static int __init wm8350_regulator_init(void)
1417{
1418 return platform_driver_register(&wm8350_regulator_driver);
1419}
1420subsys_initcall(wm8350_regulator_init);
1421
1422static void __exit wm8350_regulator_exit(void)
1423{
1424 platform_driver_unregister(&wm8350_regulator_driver);
1425}
1426module_exit(wm8350_regulator_exit);
1427
1428/* Module information */
1429MODULE_AUTHOR("Liam Girdwood");
1430MODULE_DESCRIPTION("WM8350 voltage and current regulator driver");
1431MODULE_LICENSE("GPL");
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c
new file mode 100644
index 000000000000..48b372e038a8
--- /dev/null
+++ b/drivers/regulator/wm8400-regulator.c
@@ -0,0 +1,368 @@
1/*
2 * Regulator support for WM8400
3 *
4 * Copyright 2008 Wolfson Microelectronics PLC.
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
12 *
13 */
14
15#include <linux/bug.h>
16#include <linux/err.h>
17#include <linux/kernel.h>
18#include <linux/regulator/driver.h>
19#include <linux/mfd/wm8400-private.h>
20
21static int wm8400_ldo_is_enabled(struct regulator_dev *dev)
22{
23 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
24 u16 val;
25
26 val = wm8400_reg_read(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev));
27 return (val & WM8400_LDO1_ENA) != 0;
28}
29
30static int wm8400_ldo_enable(struct regulator_dev *dev)
31{
32 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
33
34 return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev),
35 WM8400_LDO1_ENA, WM8400_LDO1_ENA);
36}
37
38static int wm8400_ldo_disable(struct regulator_dev *dev)
39{
40 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
41
42 return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev),
43 WM8400_LDO1_ENA, 0);
44}
45
46static int wm8400_ldo_get_voltage(struct regulator_dev *dev)
47{
48 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
49 u16 val;
50
51 val = wm8400_reg_read(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev));
52 val &= WM8400_LDO1_VSEL_MASK;
53
54 if (val < 15)
55 return 900000 + (val * 50000);
56 else
57 return 1600000 + ((val - 14) * 100000);
58}
59
60static int wm8400_ldo_set_voltage(struct regulator_dev *dev,
61 int min_uV, int max_uV)
62{
63 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
64 u16 val;
65
66 if (min_uV < 900000 || min_uV > 3300000)
67 return -EINVAL;
68
69 if (min_uV < 1700000) {
70 /* Steps of 50mV from 900mV; */
71 val = (min_uV - 850001) / 50000;
72
73 if ((val * 50000) + 900000 > max_uV)
74 return -EINVAL;
75 BUG_ON((val * 50000) + 900000 < min_uV);
76 } else {
77 /* Steps of 100mV from 1700mV */
78 val = ((min_uV - 1600001) / 100000);
79
80 if ((val * 100000) + 1700000 > max_uV)
81 return -EINVAL;
82 BUG_ON((val * 100000) + 1700000 < min_uV);
83
84 val += 0xf;
85 }
86
87 return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev),
88 WM8400_LDO1_VSEL_MASK, val);
89}
90
91static struct regulator_ops wm8400_ldo_ops = {
92 .is_enabled = wm8400_ldo_is_enabled,
93 .enable = wm8400_ldo_enable,
94 .disable = wm8400_ldo_disable,
95 .get_voltage = wm8400_ldo_get_voltage,
96 .set_voltage = wm8400_ldo_set_voltage,
97};
98
99static int wm8400_dcdc_is_enabled(struct regulator_dev *dev)
100{
101 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
102 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
103 u16 val;
104
105 val = wm8400_reg_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset);
106 return (val & WM8400_DC1_ENA) != 0;
107}
108
109static int wm8400_dcdc_enable(struct regulator_dev *dev)
110{
111 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
112 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
113
114 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
115 WM8400_DC1_ENA, WM8400_DC1_ENA);
116}
117
118static int wm8400_dcdc_disable(struct regulator_dev *dev)
119{
120 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
121 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
122
123 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
124 WM8400_DC1_ENA, 0);
125}
126
127static int wm8400_dcdc_get_voltage(struct regulator_dev *dev)
128{
129 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
130 u16 val;
131 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
132
133 val = wm8400_reg_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset);
134 val &= WM8400_DC1_VSEL_MASK;
135
136 return 850000 + (25000 * val);
137}
138
139static int wm8400_dcdc_set_voltage(struct regulator_dev *dev,
140 int min_uV, int max_uV)
141{
142 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
143 u16 val;
144 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
145
146 if (min_uV < 850000)
147 return -EINVAL;
148
149 val = (min_uV - 825001) / 25000;
150
151 if (850000 + (25000 * val) > max_uV)
152 return -EINVAL;
153 BUG_ON(850000 + (25000 * val) < min_uV);
154
155 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
156 WM8400_DC1_VSEL_MASK, val);
157}
158
159static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev)
160{
161 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
162 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
163 u16 data[2];
164 int ret;
165
166 ret = wm8400_block_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset, 2,
167 data);
168 if (ret != 0)
169 return 0;
170
171 /* Datasheet: hibernate */
172 if (data[0] & WM8400_DC1_SLEEP)
173 return REGULATOR_MODE_STANDBY;
174
175 /* Datasheet: standby */
176 if (!(data[0] & WM8400_DC1_ACTIVE))
177 return REGULATOR_MODE_IDLE;
178
179 /* Datasheet: active with or without force PWM */
180 if (data[1] & WM8400_DC1_FRC_PWM)
181 return REGULATOR_MODE_FAST;
182 else
183 return REGULATOR_MODE_NORMAL;
184}
185
186static int wm8400_dcdc_set_mode(struct regulator_dev *dev, unsigned int mode)
187{
188 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
189 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
190 int ret;
191
192 switch (mode) {
193 case REGULATOR_MODE_FAST:
194 /* Datasheet: active with force PWM */
195 ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_2 + offset,
196 WM8400_DC1_FRC_PWM, WM8400_DC1_FRC_PWM);
197 if (ret != 0)
198 return ret;
199
200 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
201 WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP,
202 WM8400_DC1_ACTIVE);
203
204 case REGULATOR_MODE_NORMAL:
205 /* Datasheet: active */
206 ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_2 + offset,
207 WM8400_DC1_FRC_PWM, 0);
208 if (ret != 0)
209 return ret;
210
211 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
212 WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP,
213 WM8400_DC1_ACTIVE);
214
215 case REGULATOR_MODE_IDLE:
216 /* Datasheet: standby */
217 ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
218 WM8400_DC1_ACTIVE, 0);
219 if (ret != 0)
220 return ret;
221 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
222 WM8400_DC1_SLEEP, 0);
223
224 default:
225 return -EINVAL;
226 }
227}
228
229static unsigned int wm8400_dcdc_get_optimum_mode(struct regulator_dev *dev,
230 int input_uV, int output_uV,
231 int load_uA)
232{
233 return REGULATOR_MODE_NORMAL;
234}
235
236static struct regulator_ops wm8400_dcdc_ops = {
237 .is_enabled = wm8400_dcdc_is_enabled,
238 .enable = wm8400_dcdc_enable,
239 .disable = wm8400_dcdc_disable,
240 .get_voltage = wm8400_dcdc_get_voltage,
241 .set_voltage = wm8400_dcdc_set_voltage,
242 .get_mode = wm8400_dcdc_get_mode,
243 .set_mode = wm8400_dcdc_set_mode,
244 .get_optimum_mode = wm8400_dcdc_get_optimum_mode,
245};
246
247static struct regulator_desc regulators[] = {
248 {
249 .name = "LDO1",
250 .id = WM8400_LDO1,
251 .ops = &wm8400_ldo_ops,
252 .type = REGULATOR_VOLTAGE,
253 .owner = THIS_MODULE,
254 },
255 {
256 .name = "LDO2",
257 .id = WM8400_LDO2,
258 .ops = &wm8400_ldo_ops,
259 .type = REGULATOR_VOLTAGE,
260 .owner = THIS_MODULE,
261 },
262 {
263 .name = "LDO3",
264 .id = WM8400_LDO3,
265 .ops = &wm8400_ldo_ops,
266 .type = REGULATOR_VOLTAGE,
267 .owner = THIS_MODULE,
268 },
269 {
270 .name = "LDO4",
271 .id = WM8400_LDO4,
272 .ops = &wm8400_ldo_ops,
273 .type = REGULATOR_VOLTAGE,
274 .owner = THIS_MODULE,
275 },
276 {
277 .name = "DCDC1",
278 .id = WM8400_DCDC1,
279 .ops = &wm8400_dcdc_ops,
280 .type = REGULATOR_VOLTAGE,
281 .owner = THIS_MODULE,
282 },
283 {
284 .name = "DCDC2",
285 .id = WM8400_DCDC2,
286 .ops = &wm8400_dcdc_ops,
287 .type = REGULATOR_VOLTAGE,
288 .owner = THIS_MODULE,
289 },
290};
291
292static int __init wm8400_regulator_probe(struct platform_device *pdev)
293{
294 struct regulator_dev *rdev;
295
296 rdev = regulator_register(&regulators[pdev->id], &pdev->dev,
297 pdev->dev.driver_data);
298
299 if (IS_ERR(rdev))
300 return PTR_ERR(rdev);
301
302 return 0;
303}
304
305static int __devexit wm8400_regulator_remove(struct platform_device *pdev)
306{
307 struct regulator_dev *rdev = platform_get_drvdata(pdev);
308
309 regulator_unregister(rdev);
310
311 return 0;
312}
313
314static struct platform_driver wm8400_regulator_driver = {
315 .driver = {
316 .name = "wm8400-regulator",
317 },
318 .probe = wm8400_regulator_probe,
319 .remove = __devexit_p(wm8400_regulator_remove),
320};
321
322/**
323 * wm8400_register_regulator - enable software control of a WM8400 regulator
324 *
325 * This function enables software control of a WM8400 regulator via
326 * the regulator API. It is intended to be called from the
327 * platform_init() callback of the WM8400 MFD driver.
328 *
329 * @param dev The WM8400 device to operate on.
330 * @param reg The regulator to control.
331 * @param initdata Regulator initdata for the regulator.
332 */
333int wm8400_register_regulator(struct device *dev, int reg,
334 struct regulator_init_data *initdata)
335{
336 struct wm8400 *wm8400 = dev->driver_data;
337
338 if (wm8400->regulators[reg].name)
339 return -EBUSY;
340
341 initdata->driver_data = wm8400;
342
343 wm8400->regulators[reg].name = "wm8400-regulator";
344 wm8400->regulators[reg].id = reg;
345 wm8400->regulators[reg].dev.parent = dev;
346 wm8400->regulators[reg].dev.driver_data = wm8400;
347 wm8400->regulators[reg].dev.platform_data = initdata;
348
349 return platform_device_register(&wm8400->regulators[reg]);
350}
351EXPORT_SYMBOL_GPL(wm8400_register_regulator);
352
353static int __init wm8400_regulator_init(void)
354{
355 return platform_driver_register(&wm8400_regulator_driver);
356}
357module_init(wm8400_regulator_init);
358
359static void __exit wm8400_regulator_exit(void)
360{
361 platform_driver_unregister(&wm8400_regulator_driver);
362}
363module_exit(wm8400_regulator_exit);
364
365MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
366MODULE_DESCRIPTION("WM8400 regulator driver");
367MODULE_LICENSE("GPL");
368MODULE_ALIAS("platform:wm8400-regulator");