Skip to content

Commit

Permalink
Merge remote-tracking branch 'regulator/topic/dt' into regulator-next
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Brown committed Nov 23, 2011
2 parents 68aaa37 + 69511a4 commit 924ee2c
Show file tree
Hide file tree
Showing 46 changed files with 367 additions and 58 deletions.
29 changes: 29 additions & 0 deletions Documentation/devicetree/bindings/regulator/fixed-regulator.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Fixed Voltage regulators

Required properties:
- compatible: Must be "regulator-fixed";

Optional properties:
- gpio: gpio to use for enable control
- startup-delay-us: startup time in microseconds
- enable-active-high: Polarity of GPIO is Active high
If this property is missing, the default assumed is Active low.

Any property defined as part of the core regulator
binding, defined in regulator.txt, can also be used.
However a fixed voltage regulator is expected to have the
regulator-min-microvolt and regulator-max-microvolt
to be the same.

Example:

abc: fixedregulator@0 {
compatible = "regulator-fixed";
regulator-name = "fixed-supply";
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
gpio = <&gpio1 16 0>;
startup-delay-us = <70000>;
enable-active-high;
regulator-boot-on
};
54 changes: 54 additions & 0 deletions Documentation/devicetree/bindings/regulator/regulator.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Voltage/Current Regulators

Optional properties:
- regulator-name: A string used as a descriptive name for regulator outputs
- regulator-min-microvolt: smallest voltage consumers may set
- regulator-max-microvolt: largest voltage consumers may set
- regulator-microvolt-offset: Offset applied to voltages to compensate for voltage drops
- regulator-min-microamp: smallest current consumers may set
- regulator-max-microamp: largest current consumers may set
- regulator-always-on: boolean, regulator should never be disabled
- regulator-boot-on: bootloader/firmware enabled regulator
- <name>-supply: phandle to the parent supply/regulator node

Example:

xyzreg: regulator@0 {
regulator-min-microvolt = <1000000>;
regulator-max-microvolt = <2500000>;
regulator-always-on;
vin-supply = <&vin>;
};

Regulator Consumers:
Consumer nodes can reference one or more of its supplies/
regulators using the below bindings.

- <name>-supply: phandle to the regulator node

These are the same bindings that a regulator in the above
example used to reference its own supply, in which case
its just seen as a special case of a regulator being a
consumer itself.

Example of a consumer device node (mmc) referencing two
regulators (twl-reg1 and twl-reg2),

twl-reg1: regulator@0 {
...
...
...
};

twl-reg2: regulator@1 {
...
...
...
};

mmc: mmc@0x0 {
...
...
vmmc-supply = <&twl-reg1>;
vmmcaux-supply = <&twl-reg2>;
};
2 changes: 1 addition & 1 deletion drivers/regulator/88pm8607.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ static int __devinit pm8607_regulator_probe(struct platform_device *pdev)

/* replace driver_data with info */
info->regulator = regulator_register(&info->desc, &pdev->dev,
pdata, info);
pdata, info, NULL);
if (IS_ERR(info->regulator)) {
dev_err(&pdev->dev, "failed to register regulator %s\n",
info->desc.name);
Expand Down
1 change: 1 addition & 0 deletions drivers/regulator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


obj-$(CONFIG_REGULATOR) += core.o dummy.o
obj-$(CONFIG_OF) += of_regulator.o
obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o
obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o
Expand Down
2 changes: 1 addition & 1 deletion drivers/regulator/aat2870-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static int aat2870_regulator_probe(struct platform_device *pdev)
ri->pdev = pdev;

rdev = regulator_register(&ri->desc, &pdev->dev,
pdev->dev.platform_data, ri);
pdev->dev.platform_data, ri, NULL);
if (IS_ERR(rdev)) {
dev_err(&pdev->dev, "Failed to register regulator %s\n",
ri->desc.name);
Expand Down
2 changes: 1 addition & 1 deletion drivers/regulator/ab3100.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ static int __devinit ab3100_regulators_probe(struct platform_device *pdev)
rdev = regulator_register(&ab3100_regulator_desc[i],
&pdev->dev,
&plfdata->reg_constraints[i],
reg);
reg, NULL);

if (IS_ERR(rdev)) {
err = PTR_ERR(rdev);
Expand Down
2 changes: 1 addition & 1 deletion drivers/regulator/ab8500.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)

/* register regulator with framework */
info->regulator = regulator_register(&info->desc, &pdev->dev,
&pdata->regulator[i], info);
&pdata->regulator[i], info, NULL);
if (IS_ERR(info->regulator)) {
err = PTR_ERR(info->regulator);
dev_err(&pdev->dev, "failed to register regulator %s\n",
Expand Down
2 changes: 1 addition & 1 deletion drivers/regulator/ad5398.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ static int __devinit ad5398_probe(struct i2c_client *client,
chip->current_mask = (chip->current_level - 1) << chip->current_offset;

chip->rdev = regulator_register(&ad5398_reg, &client->dev,
init_data, chip);
init_data, chip, NULL);
if (IS_ERR(chip->rdev)) {
ret = PTR_ERR(chip->rdev);
dev_err(&client->dev, "failed to register %s %s\n",
Expand Down
2 changes: 1 addition & 1 deletion drivers/regulator/bq24022.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static int __init bq24022_probe(struct platform_device *pdev)
ret = gpio_direction_output(pdata->gpio_nce, 1);

bq24022 = regulator_register(&bq24022_desc, &pdev->dev,
pdata->init_data, pdata);
pdata->init_data, pdata, NULL);
if (IS_ERR(bq24022)) {
dev_dbg(&pdev->dev, "couldn't register regulator\n");
ret = PTR_ERR(bq24022);
Expand Down
82 changes: 69 additions & 13 deletions drivers/regulator/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <linux/mutex.h>
#include <linux/suspend.h>
#include <linux/delay.h>
#include <linux/of.h>
#include <linux/regulator/of_regulator.h>
#include <linux/regulator/consumer.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
Expand Down Expand Up @@ -132,6 +134,33 @@ static struct regulator *get_device_regulator(struct device *dev)
return NULL;
}

/**
* of_get_regulator - get a regulator device node based on supply name
* @dev: Device pointer for the consumer (of regulator) device
* @supply: regulator supply name
*
* Extract the regulator device node corresponding to the supply name.
* retruns the device node corresponding to the regulator if found, else
* returns NULL.
*/
static struct device_node *of_get_regulator(struct device *dev, const char *supply)
{
struct device_node *regnode = NULL;
char prop_name[32]; /* 32 is max size of property name */

dev_dbg(dev, "Looking up %s-supply from device tree\n", supply);

snprintf(prop_name, 32, "%s-supply", supply);
regnode = of_parse_phandle(dev->of_node, prop_name, 0);

if (!regnode) {
dev_warn(dev, "%s property in node %s references invalid phandle",
prop_name, dev->of_node->full_name);
return NULL;
}
return regnode;
}

/* Platform voltage constraint check */
static int regulator_check_voltage(struct regulator_dev *rdev,
int *min_uV, int *max_uV)
Expand Down Expand Up @@ -1148,6 +1177,30 @@ static int _regulator_get_enable_time(struct regulator_dev *rdev)
return rdev->desc->ops->enable_time(rdev);
}

static struct regulator_dev *regulator_dev_lookup(struct device *dev,
const char *supply)
{
struct regulator_dev *r;
struct device_node *node;

/* first do a dt based lookup */
if (dev && dev->of_node) {
node = of_get_regulator(dev, supply);
if (node)
list_for_each_entry(r, &regulator_list, list)
if (r->dev.parent &&
node == r->dev.of_node)
return r;
}

/* if not found, try doing it non-dt way */
list_for_each_entry(r, &regulator_list, list)
if (strcmp(rdev_get_name(r), supply) == 0)
return r;

return NULL;
}

/* Internal regulator request function */
static struct regulator *_regulator_get(struct device *dev, const char *id,
int exclusive)
Expand All @@ -1168,6 +1221,10 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,

mutex_lock(&regulator_list_mutex);

rdev = regulator_dev_lookup(dev, id);
if (rdev)
goto found;

list_for_each_entry(map, &regulator_map_list, list) {
/* If the mapping has a device set up it must match */
if (map->dev_name &&
Expand Down Expand Up @@ -2638,11 +2695,12 @@ static void rdev_init_debugfs(struct regulator_dev *rdev)
*/
struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
struct device *dev, const struct regulator_init_data *init_data,
void *driver_data)
void *driver_data, struct device_node *of_node)
{
static atomic_t regulator_no = ATOMIC_INIT(0);
struct regulator_dev *rdev;
int ret, i;
const char *supply = NULL;

if (regulator_desc == NULL)
return ERR_PTR(-EINVAL);
Expand Down Expand Up @@ -2697,6 +2755,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,

/* register with sysfs */
rdev->dev.class = &regulator_class;
rdev->dev.of_node = of_node;
rdev->dev.parent = dev;
dev_set_name(&rdev->dev, "regulator.%d",
atomic_inc_return(&regulator_no) - 1);
Expand All @@ -2718,21 +2777,18 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
if (ret < 0)
goto scrub;

if (init_data->supply_regulator) {
if (init_data->supply_regulator)
supply = init_data->supply_regulator;
else if (regulator_desc->supply_name)
supply = regulator_desc->supply_name;

if (supply) {
struct regulator_dev *r;
int found = 0;

list_for_each_entry(r, &regulator_list, list) {
if (strcmp(rdev_get_name(r),
init_data->supply_regulator) == 0) {
found = 1;
break;
}
}
r = regulator_dev_lookup(dev, supply);

if (!found) {
dev_err(dev, "Failed to find supply %s\n",
init_data->supply_regulator);
if (!r) {
dev_err(dev, "Failed to find supply %s\n", supply);
ret = -ENODEV;
goto scrub;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/regulator/da903x.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ static int __devinit da903x_regulator_probe(struct platform_device *pdev)
ri->desc.ops = &da9030_regulator_ldo1_15_ops;

rdev = regulator_register(&ri->desc, &pdev->dev,
pdev->dev.platform_data, ri);
pdev->dev.platform_data, ri, NULL);
if (IS_ERR(rdev)) {
dev_err(&pdev->dev, "failed to register regulator %s\n",
ri->desc.name);
Expand Down
2 changes: 1 addition & 1 deletion drivers/regulator/db8500-prcmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ static int __devinit db8500_regulator_probe(struct platform_device *pdev)

/* register with the regulator framework */
info->rdev = regulator_register(&info->desc, &pdev->dev,
init_data, info);
init_data, info, NULL);
if (IS_ERR(info->rdev)) {
err = PTR_ERR(info->rdev);
dev_err(&pdev->dev, "failed to register %s: err %i\n",
Expand Down
2 changes: 1 addition & 1 deletion drivers/regulator/dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static int __devinit dummy_regulator_probe(struct platform_device *pdev)
int ret;

dummy_regulator_rdev = regulator_register(&dummy_desc, NULL,
&dummy_initdata, NULL);
&dummy_initdata, NULL, NULL);
if (IS_ERR(dummy_regulator_rdev)) {
ret = PTR_ERR(dummy_regulator_rdev);
pr_err("Failed to register regulator: %d\n", ret);
Expand Down
Loading

0 comments on commit 924ee2c

Please sign in to comment.