Skip to content

Commit 8735bc2

Browse files
Linus Walleijbroonie
authored andcommitted
regulator: ab3100: device tree support
This implements device tree support for the AB3100 regulators driver. The initial settings are moved out of platform data and into the driver for the device tree case, as it appears that there is no way to supply this as AUXDATA for an I2C device. The style and bindings are heavily inspired by Lee Jones' style for AB8500. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
1 parent 9b31835 commit 8735bc2

2 files changed

Lines changed: 118 additions & 6 deletions

File tree

‎drivers/mfd/ab3100-core.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ static struct mfd_cell ab3100_devs[] = {
753753
},
754754
{
755755
.name = "ab3100-regulators",
756+
.of_compatible = "stericsson,ab3100-regulators",
756757
.id = -1,
757758
},
758759
{

‎drivers/regulator/ab3100.c‎

Lines changed: 117 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <linux/regulator/driver.h>
1818
#include <linux/mfd/ab3100.h>
1919
#include <linux/mfd/abx500.h>
20+
#include <linux/of.h>
21+
#include <linux/regulator/of_regulator.h>
2022

2123
/* LDO registers and some handy masking definitions for AB3100 */
2224
#define AB3100_LDO_A 0x40
@@ -345,7 +347,11 @@ static int ab3100_get_voltage_regulator_external(struct regulator_dev *reg)
345347
{
346348
struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
347349

348-
return abreg->plfdata->external_voltage;
350+
if (abreg->plfdata)
351+
return abreg->plfdata->external_voltage;
352+
else
353+
/* TODO: encode external voltage into device tree */
354+
return 0;
349355
}
350356

351357
static struct regulator_ops regulator_ops_fixed = {
@@ -490,6 +496,8 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = {
490496

491497
static int ab3100_regulator_register(struct platform_device *pdev,
492498
struct ab3100_platform_data *plfdata,
499+
struct regulator_init_data *init_data,
500+
struct device_node *np,
493501
int id)
494502
{
495503
struct regulator_desc *desc;
@@ -518,9 +526,11 @@ static int ab3100_regulator_register(struct platform_device *pdev,
518526
*/
519527
reg->dev = &pdev->dev;
520528
if (plfdata) {
521-
/* This will be replaced by device tree data */
522529
reg->plfdata = plfdata;
523530
config.init_data = &plfdata->reg_constraints[i];
531+
} else if (np) {
532+
config.of_node = np;
533+
config.init_data = init_data;
524534
}
525535
config.dev = &pdev->dev;
526536
config.driver_data = reg;
@@ -540,15 +550,103 @@ static int ab3100_regulator_register(struct platform_device *pdev,
540550
return 0;
541551
}
542552

553+
static struct of_regulator_match ab3100_regulator_matches[] = {
554+
{ .name = "ab3100_ldo_a", .driver_data = (void *) AB3100_LDO_A, },
555+
{ .name = "ab3100_ldo_c", .driver_data = (void *) AB3100_LDO_C, },
556+
{ .name = "ab3100_ldo_d", .driver_data = (void *) AB3100_LDO_D, },
557+
{ .name = "ab3100_ldo_e", .driver_data = (void *) AB3100_LDO_E, },
558+
{ .name = "ab3100_ldo_f", .driver_data = (void *) AB3100_LDO_F },
559+
{ .name = "ab3100_ldo_g", .driver_data = (void *) AB3100_LDO_G },
560+
{ .name = "ab3100_ldo_h", .driver_data = (void *) AB3100_LDO_H },
561+
{ .name = "ab3100_ldo_k", .driver_data = (void *) AB3100_LDO_K },
562+
{ .name = "ab3100_ext", .driver_data = (void *) AB3100_LDO_EXT },
563+
{ .name = "ab3100_buck", .driver_data = (void *) AB3100_BUCK },
564+
};
565+
543566
/*
544-
* NOTE: the following functions are regulators pluralis - it is the
545-
* binding to the AB3100 core driver and the parent platform device
546-
* for all the different regulators.
567+
* Initial settings of ab3100 registers.
568+
* Common for below LDO regulator settings are that
569+
* bit 7-5 controls voltage. Bit 4 turns regulator ON(1) or OFF(0).
570+
* Bit 3-2 controls sleep enable and bit 1-0 controls sleep mode.
547571
*/
572+
/* LDO_A 0x16: 2.75V, ON, SLEEP_A, SLEEP OFF GND */
573+
#define LDO_A_SETTING 0x16
574+
/* LDO_C 0x10: 2.65V, ON, SLEEP_A or B, SLEEP full power */
575+
#define LDO_C_SETTING 0x10
576+
/* LDO_D 0x10: 2.65V, ON, sleep mode not used */
577+
#define LDO_D_SETTING 0x10
578+
/* LDO_E 0x10: 1.8V, ON, SLEEP_A or B, SLEEP full power */
579+
#define LDO_E_SETTING 0x10
580+
/* LDO_E SLEEP 0x00: 1.8V, not used, SLEEP_A or B, not used */
581+
#define LDO_E_SLEEP_SETTING 0x00
582+
/* LDO_F 0xD0: 2.5V, ON, SLEEP_A or B, SLEEP full power */
583+
#define LDO_F_SETTING 0xD0
584+
/* LDO_G 0x00: 2.85V, OFF, SLEEP_A or B, SLEEP full power */
585+
#define LDO_G_SETTING 0x00
586+
/* LDO_H 0x18: 2.75V, ON, SLEEP_B, SLEEP full power */
587+
#define LDO_H_SETTING 0x18
588+
/* LDO_K 0x00: 2.75V, OFF, SLEEP_A or B, SLEEP full power */
589+
#define LDO_K_SETTING 0x00
590+
/* LDO_EXT 0x00: Voltage not set, OFF, not used, not used */
591+
#define LDO_EXT_SETTING 0x00
592+
/* BUCK 0x7D: 1.2V, ON, SLEEP_A and B, SLEEP low power */
593+
#define BUCK_SETTING 0x7D
594+
/* BUCK SLEEP 0xAC: 1.05V, Not used, SLEEP_A and B, Not used */
595+
#define BUCK_SLEEP_SETTING 0xAC
596+
597+
static const u8 ab3100_reg_initvals[] = {
598+
LDO_A_SETTING,
599+
LDO_C_SETTING,
600+
LDO_E_SETTING,
601+
LDO_E_SLEEP_SETTING,
602+
LDO_F_SETTING,
603+
LDO_G_SETTING,
604+
LDO_H_SETTING,
605+
LDO_K_SETTING,
606+
LDO_EXT_SETTING,
607+
BUCK_SETTING,
608+
BUCK_SLEEP_SETTING,
609+
LDO_D_SETTING,
610+
};
611+
612+
static int
613+
ab3100_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
614+
{
615+
int err, i;
616+
617+
/*
618+
* Set up the regulator registers, as was previously done with
619+
* platform data.
620+
*/
621+
/* Set up regulators */
622+
for (i = 0; i < ARRAY_SIZE(ab3100_reg_init_order); i++) {
623+
err = abx500_set_register_interruptible(&pdev->dev, 0,
624+
ab3100_reg_init_order[i],
625+
ab3100_reg_initvals[i]);
626+
if (err) {
627+
dev_err(&pdev->dev, "regulator initialization failed with error %d\n",
628+
err);
629+
return err;
630+
}
631+
}
632+
633+
for (i = 0; i < ARRAY_SIZE(ab3100_regulator_matches); i++) {
634+
err = ab3100_regulator_register(
635+
pdev, NULL, ab3100_regulator_matches[i].init_data,
636+
ab3100_regulator_matches[i].of_node,
637+
(int) ab3100_regulator_matches[i].driver_data);
638+
if (err)
639+
return err;
640+
}
641+
642+
return 0;
643+
}
644+
548645

549646
static int ab3100_regulators_probe(struct platform_device *pdev)
550647
{
551648
struct ab3100_platform_data *plfdata = pdev->dev.platform_data;
649+
struct device_node *np = pdev->dev.of_node;
552650
int err = 0;
553651
u8 data;
554652
int i;
@@ -567,6 +665,18 @@ static int ab3100_regulators_probe(struct platform_device *pdev)
567665
dev_notice(&pdev->dev,
568666
"chip is in inactive mode (Cold start)\n");
569667

668+
if (np) {
669+
err = of_regulator_match(&pdev->dev, np,
670+
ab3100_regulator_matches,
671+
ARRAY_SIZE(ab3100_regulator_matches));
672+
if (err < 0) {
673+
dev_err(&pdev->dev,
674+
"Error parsing regulator init data: %d\n", err);
675+
return err;
676+
}
677+
return ab3100_regulator_of_probe(pdev, np);
678+
}
679+
570680
/* Set up regulators */
571681
for (i = 0; i < ARRAY_SIZE(ab3100_reg_init_order); i++) {
572682
err = abx500_set_register_interruptible(&pdev->dev, 0,
@@ -583,7 +693,8 @@ static int ab3100_regulators_probe(struct platform_device *pdev)
583693
for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
584694
struct regulator_desc *desc = &ab3100_regulator_desc[i];
585695

586-
err = ab3100_regulator_register(pdev, plfdata, desc->id);
696+
err = ab3100_regulator_register(pdev, plfdata, NULL, NULL,
697+
desc->id);
587698
if (err)
588699
return err;
589700
}

0 commit comments

Comments
 (0)