Skip to content

Commit

Permalink
Merge remote-tracking branch 'regulator/topic/dt-cb' into regulator-next
Browse files Browse the repository at this point in the history
  • Loading branch information
broonie committed Feb 8, 2015
2 parents a9877b6 + f47531b commit fca8e13
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
22 changes: 17 additions & 5 deletions drivers/regulator/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3561,28 +3561,29 @@ static void rdev_init_debugfs(struct regulator_dev *rdev)
/**
* regulator_register - register regulator
* @regulator_desc: regulator to register
* @config: runtime configuration for regulator
* @cfg: runtime configuration for regulator
*
* Called by regulator drivers to register a regulator.
* Returns a valid pointer to struct regulator_dev on success
* or an ERR_PTR() on error.
*/
struct regulator_dev *
regulator_register(const struct regulator_desc *regulator_desc,
const struct regulator_config *config)
const struct regulator_config *cfg)
{
const struct regulation_constraints *constraints = NULL;
const struct regulator_init_data *init_data;
struct regulator_config *config = NULL;
static atomic_t regulator_no = ATOMIC_INIT(-1);
struct regulator_dev *rdev;
struct device *dev;
int ret, i;
const char *supply = NULL;

if (regulator_desc == NULL || config == NULL)
if (regulator_desc == NULL || cfg == NULL)
return ERR_PTR(-EINVAL);

dev = config->dev;
dev = cfg->dev;
WARN_ON(!dev);

if (regulator_desc->name == NULL || regulator_desc->ops == NULL)
Expand Down Expand Up @@ -3612,7 +3613,17 @@ regulator_register(const struct regulator_desc *regulator_desc,
if (rdev == NULL)
return ERR_PTR(-ENOMEM);

init_data = regulator_of_get_init_data(dev, regulator_desc,
/*
* Duplicate the config so the driver could override it after
* parsing init data.
*/
config = kmemdup(cfg, sizeof(*cfg), GFP_KERNEL);
if (config == NULL) {
kfree(rdev);
return ERR_PTR(-ENOMEM);
}

init_data = regulator_of_get_init_data(dev, regulator_desc, config,
&rdev->dev.of_node);
if (!init_data) {
init_data = config->init_data;
Expand Down Expand Up @@ -3735,6 +3746,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
rdev_init_debugfs(rdev);
out:
mutex_unlock(&regulator_list_mutex);
kfree(config);
return rdev;

unset_supplies:
Expand Down
2 changes: 2 additions & 0 deletions drivers/regulator/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ struct regulator {
#ifdef CONFIG_OF
struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
const struct regulator_desc *desc,
struct regulator_config *config,
struct device_node **node);
#else
static inline struct regulator_init_data *
regulator_of_get_init_data(struct device *dev,
const struct regulator_desc *desc,
struct regulator_config *config,
struct device_node **node)
{
return NULL;
Expand Down
11 changes: 11 additions & 0 deletions drivers/regulator/of_regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ EXPORT_SYMBOL_GPL(of_regulator_match);

struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
const struct regulator_desc *desc,
struct regulator_config *config,
struct device_node **node)
{
struct device_node *search, *child;
Expand Down Expand Up @@ -307,6 +308,16 @@ struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
break;
}

if (desc->of_parse_cb) {
if (desc->of_parse_cb(child, desc, config)) {
dev_err(dev,
"driver callback failed to parse DT for regulator %s\n",
child->name);
init_data = NULL;
break;
}
}

of_node_get(child);
*node = child;
break;
Expand Down
13 changes: 13 additions & 0 deletions include/linux/regulator/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

struct regmap;
struct regulator_dev;
struct regulator_config;
struct regulator_init_data;
struct regulator_enable_gpio;

Expand Down Expand Up @@ -205,6 +206,15 @@ enum regulator_type {
* @supply_name: Identifying the regulator supply
* @of_match: Name used to identify regulator in DT.
* @regulators_node: Name of node containing regulator definitions in DT.
* @of_parse_cb: Optional callback called only if of_match is present.
* Will be called for each regulator parsed from DT, during
* init_data parsing.
* The regulator_config passed as argument to the callback will
* be a copy of config passed to regulator_register, valid only
* for this particular call. Callback may freely change the
* config but it cannot store it for later usage.
* Callback should return 0 on success or negative ERRNO
* indicating failure.
* @id: Numerical identifier for the regulator.
* @ops: Regulator operations table.
* @irq: Interrupt number for the regulator.
Expand Down Expand Up @@ -251,6 +261,9 @@ struct regulator_desc {
const char *supply_name;
const char *of_match;
const char *regulators_node;
int (*of_parse_cb)(struct device_node *,
const struct regulator_desc *,
struct regulator_config *);
int id;
bool continuous_voltage_range;
unsigned n_voltages;
Expand Down

0 comments on commit fca8e13

Please sign in to comment.