Skip to content

Commit

Permalink
regulator: core: Move of_find_regulator_by_node() to of_regulator.c
Browse files Browse the repository at this point in the history
As of_find_regulator_by_node() is an of function it should be moved from
core.c to of_regulator.c. It provides better separation of device tree
functions from the core and allows other of_functions in of_regulator.c
to resolve device_node to regulator_dev. This will be useful for
implementation of parsing coupled regulators properties.

Declare of_find_regulator_by_node() function in internal.h as well as
regulator_class and dev_to_rdev(), as they are needed by
of_find_regulator_by_node().

Signed-off-by: Maciej Purski <m.purski@samsung.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Maciej Purski authored and Mark Brown committed Jan 26, 2018
1 parent 0d5c863 commit 148096a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
23 changes: 1 addition & 22 deletions drivers/regulator/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ static bool has_full_constraints;

static struct dentry *debugfs_root;

static struct class regulator_class;

/*
* struct regulator_map
*
Expand Down Expand Up @@ -112,11 +110,6 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
const char *supply_name);
static void _regulator_put(struct regulator *regulator);

static struct regulator_dev *dev_to_rdev(struct device *dev)
{
return container_of(dev, struct regulator_dev, dev);
}

static const char *rdev_get_name(struct regulator_dev *rdev)
{
if (rdev->constraints && rdev->constraints->name)
Expand Down Expand Up @@ -1417,20 +1410,6 @@ static void regulator_supply_alias(struct device **dev, const char **supply)
}
}

static int of_node_match(struct device *dev, const void *data)
{
return dev->of_node == data;
}

static struct regulator_dev *of_find_regulator_by_node(struct device_node *np)
{
struct device *dev;

dev = class_find_device(&regulator_class, NULL, np, of_node_match);

return dev ? dev_to_rdev(dev) : NULL;
}

static int regulator_match(struct device *dev, const void *data)
{
struct regulator_dev *r = dev_to_rdev(dev);
Expand Down Expand Up @@ -3918,7 +3897,7 @@ static void regulator_dev_release(struct device *dev)
kfree(rdev);
}

static struct class regulator_class = {
struct class regulator_class = {
.name = "regulator",
.dev_release = regulator_dev_release,
.dev_groups = regulator_dev_groups,
Expand Down
9 changes: 9 additions & 0 deletions drivers/regulator/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ struct regulator {
struct dentry *debugfs;
};

extern struct class regulator_class;

static inline struct regulator_dev *dev_to_rdev(struct device *dev)
{
return container_of(dev, struct regulator_dev, dev);
}

struct regulator_dev *of_find_regulator_by_node(struct device_node *np);

#ifdef CONFIG_OF
struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
const struct regulator_desc *desc,
Expand Down
14 changes: 14 additions & 0 deletions drivers/regulator/of_regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,17 @@ struct regulator_init_data *regulator_of_get_init_data(struct device *dev,

return init_data;
}

static int of_node_match(struct device *dev, const void *data)
{
return dev->of_node == data;
}

struct regulator_dev *of_find_regulator_by_node(struct device_node *np)
{
struct device *dev;

dev = class_find_device(&regulator_class, NULL, np, of_node_match);

return dev ? dev_to_rdev(dev) : NULL;
}

0 comments on commit 148096a

Please sign in to comment.