Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 312602
b: refs/heads/master
c: 65f7350
h: refs/heads/master
v: v3
  • Loading branch information
Mark Brown committed Jul 3, 2012
1 parent d7ef824 commit 275065c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 5c5659d0a22ec4f947ef4faa3055767572f15e74
refs/heads/master: 65f735082de35aa4d44e8d0afe862798d0e09e29
35 changes: 34 additions & 1 deletion trunk/drivers/regulator/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <linux/mutex.h>
#include <linux/suspend.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/of.h>
#include <linux/regmap.h>
#include <linux/regulator/of_regulator.h>
Expand Down Expand Up @@ -1491,7 +1492,11 @@ static int _regulator_do_enable(struct regulator_dev *rdev)

trace_regulator_enable(rdev_get_name(rdev));

if (rdev->desc->ops->enable) {
if (rdev->ena_gpio) {
gpio_set_value_cansleep(rdev->ena_gpio,
!rdev->ena_gpio_invert);
rdev->ena_gpio_state = 1;
} else if (rdev->desc->ops->enable) {
ret = rdev->desc->ops->enable(rdev);
if (ret < 0)
return ret;
Expand Down Expand Up @@ -1846,6 +1851,10 @@ EXPORT_SYMBOL_GPL(regulator_disable_regmap);

static int _regulator_is_enabled(struct regulator_dev *rdev)
{
/* A GPIO control always takes precedence */
if (rdev->ena_gpio)
return rdev->ena_gpio_state;

/* If we don't know then assume that the regulator is always on */
if (!rdev->desc->ops->is_enabled)
return 1;
Expand Down Expand Up @@ -3243,6 +3252,26 @@ regulator_register(const struct regulator_desc *regulator_desc,

dev_set_drvdata(&rdev->dev, rdev);

if (config->ena_gpio) {
ret = gpio_request_one(config->ena_gpio,
GPIOF_DIR_OUT | config->ena_gpio_flags,
rdev_get_name(rdev));
if (ret != 0) {
rdev_err(rdev, "Failed to request enable GPIO%d: %d\n",
config->ena_gpio, ret);
goto clean;
}

rdev->ena_gpio = config->ena_gpio;
rdev->ena_gpio_invert = config->ena_gpio_invert;

if (config->ena_gpio_flags & GPIOF_OUT_INIT_HIGH)
rdev->ena_gpio_state = 1;

if (rdev->ena_gpio_invert)
rdev->ena_gpio_state = !rdev->ena_gpio_state;
}

/* set regulator constraints */
if (init_data)
constraints = &init_data->constraints;
Expand Down Expand Up @@ -3311,6 +3340,8 @@ regulator_register(const struct regulator_desc *regulator_desc,
scrub:
if (rdev->supply)
regulator_put(rdev->supply);
if (rdev->ena_gpio)
gpio_free(rdev->ena_gpio);
kfree(rdev->constraints);
device_unregister(&rdev->dev);
/* device core frees rdev */
Expand Down Expand Up @@ -3344,6 +3375,8 @@ void regulator_unregister(struct regulator_dev *rdev)
unset_regulator_supplies(rdev);
list_del(&rdev->list);
kfree(rdev->constraints);
if (rdev->ena_gpio)
gpio_free(rdev->ena_gpio);
device_unregister(&rdev->dev);
mutex_unlock(&regulator_list_mutex);
}
Expand Down
11 changes: 11 additions & 0 deletions trunk/include/linux/regulator/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,20 @@ struct regulator_desc {
* @of_node: OpenFirmware node to parse for device tree bindings (may be
* NULL).
* @regmap: regmap to use for core regmap helpers
* @ena_gpio: GPIO controlling regulator enable.
* @ena_gpio_invert: Sense for GPIO enable control.
* @ena_gpio_flags: Flags to use when calling gpio_request_one()
*/
struct regulator_config {
struct device *dev;
const struct regulator_init_data *init_data;
void *driver_data;
struct device_node *of_node;
struct regmap *regmap;

int ena_gpio;
unsigned int ena_gpio_invert:1;
unsigned int ena_gpio_flags;
};

/*
Expand Down Expand Up @@ -265,6 +272,10 @@ struct regulator_dev {
void *reg_data; /* regulator_dev data */

struct dentry *debugfs;

int ena_gpio;
unsigned int ena_gpio_invert:1;
unsigned int ena_gpio_state:1;
};

struct regulator_dev *
Expand Down

0 comments on commit 275065c

Please sign in to comment.