Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 282166
b: refs/heads/master
c: cef4910
h: refs/heads/master
v: v3
  • Loading branch information
Rajendra Nayak authored and Mark Brown committed Nov 23, 2011
1 parent 2eae4f5 commit 4eb9f58
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 8f446e6fa1d506be2cb80f91c214f1705327c7f9
refs/heads/master: cef49102c1d6b1e7adcb3f8b706757e0731e955c
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
};
65 changes: 65 additions & 0 deletions trunk/drivers/regulator/fixed.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include <linux/gpio.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/regulator/of_regulator.h>
#include <linux/regulator/machine.h>

struct fixed_voltage_data {
struct regulator_desc desc;
Expand All @@ -38,6 +42,53 @@ struct fixed_voltage_data {
bool is_enabled;
};


/**
* of_get_fixed_voltage_config - extract fixed_voltage_config structure info
* @dev: device requesting for fixed_voltage_config
*
* Populates fixed_voltage_config structure by extracting data from device
* tree node, returns a pointer to the populated structure of NULL if memory
* alloc fails.
*/
struct fixed_voltage_config *of_get_fixed_voltage_config(struct device *dev)
{
struct fixed_voltage_config *config;
struct device_node *np = dev->of_node;
const __be32 *delay;
struct regulator_init_data *init_data;

config = devm_kzalloc(dev, sizeof(struct fixed_voltage_config),
GFP_KERNEL);
if (!config)
return NULL;

config->init_data = of_get_regulator_init_data(dev);
init_data = config->init_data;

config->supply_name = init_data->constraints.name;
if (init_data->constraints.min_uV == init_data->constraints.max_uV) {
config->microvolts = init_data->constraints.min_uV;
} else {
dev_err(dev,
"Fixed regulator specified with variable voltages\n");
return NULL;
}

if (init_data->constraints.boot_on)
config->enabled_at_boot = true;

config->gpio = of_get_named_gpio(np, "gpio", 0);
delay = of_get_property(np, "startup-delay-us", NULL);
if (delay)
config->startup_delay = be32_to_cpu(*delay);

if (of_find_property(np, "enable-active-high", NULL))
config->enable_high = true;

return config;
}

static int fixed_voltage_is_enabled(struct regulator_dev *dev)
{
struct fixed_voltage_data *data = rdev_get_drvdata(dev);
Expand Down Expand Up @@ -109,6 +160,9 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
struct fixed_voltage_data *drvdata;
int ret;

if (pdev->dev.of_node)
config = of_get_fixed_voltage_config(&pdev->dev);

drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL);
if (drvdata == NULL) {
dev_err(&pdev->dev, "Failed to allocate device data\n");
Expand Down Expand Up @@ -217,12 +271,23 @@ static int __devexit reg_fixed_voltage_remove(struct platform_device *pdev)
return 0;
}

#if defined(CONFIG_OF)
static const struct of_device_id fixed_of_match[] __devinitconst = {
{ .compatible = "regulator-fixed", },
{},
};
MODULE_DEVICE_TABLE(of, fixed_of_match);
#else
#define fixed_of_match NULL
#endif

static struct platform_driver regulator_fixed_voltage_driver = {
.probe = reg_fixed_voltage_probe,
.remove = __devexit_p(reg_fixed_voltage_remove),
.driver = {
.name = "reg-fixed-voltage",
.owner = THIS_MODULE,
.of_match_table = fixed_of_match,
},
};

Expand Down

0 comments on commit 4eb9f58

Please sign in to comment.