aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaciej Purski <m.purski@samsung.com>2018-01-22 09:30:06 -0500
committerMark Brown <broonie@kernel.org>2018-01-26 10:48:07 -0500
commit148096af0bf381c78afe253c07ef1c77778f0e68 (patch)
treea2522e27df842dde1d6afc18f73ab9f415eb05de
parent0d5c8633b173dd64f0005bba83501c8462463e65 (diff)
regulator: core: Move of_find_regulator_by_node() to of_regulator.c
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>
-rw-r--r--drivers/regulator/core.c23
-rw-r--r--drivers/regulator/internal.h9
-rw-r--r--drivers/regulator/of_regulator.c14
3 files changed, 24 insertions, 22 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 365b32e3f505..5f7678292cef 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -58,8 +58,6 @@ static bool has_full_constraints;
58 58
59static struct dentry *debugfs_root; 59static struct dentry *debugfs_root;
60 60
61static struct class regulator_class;
62
63/* 61/*
64 * struct regulator_map 62 * struct regulator_map
65 * 63 *
@@ -112,11 +110,6 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
112 const char *supply_name); 110 const char *supply_name);
113static void _regulator_put(struct regulator *regulator); 111static void _regulator_put(struct regulator *regulator);
114 112
115static struct regulator_dev *dev_to_rdev(struct device *dev)
116{
117 return container_of(dev, struct regulator_dev, dev);
118}
119
120static const char *rdev_get_name(struct regulator_dev *rdev) 113static const char *rdev_get_name(struct regulator_dev *rdev)
121{ 114{
122 if (rdev->constraints && rdev->constraints->name) 115 if (rdev->constraints && rdev->constraints->name)
@@ -1417,20 +1410,6 @@ static void regulator_supply_alias(struct device **dev, const char **supply)
1417 } 1410 }
1418} 1411}
1419 1412
1420static int of_node_match(struct device *dev, const void *data)
1421{
1422 return dev->of_node == data;
1423}
1424
1425static struct regulator_dev *of_find_regulator_by_node(struct device_node *np)
1426{
1427 struct device *dev;
1428
1429 dev = class_find_device(&regulator_class, NULL, np, of_node_match);
1430
1431 return dev ? dev_to_rdev(dev) : NULL;
1432}
1433
1434static int regulator_match(struct device *dev, const void *data) 1413static int regulator_match(struct device *dev, const void *data)
1435{ 1414{
1436 struct regulator_dev *r = dev_to_rdev(dev); 1415 struct regulator_dev *r = dev_to_rdev(dev);
@@ -3918,7 +3897,7 @@ static void regulator_dev_release(struct device *dev)
3918 kfree(rdev); 3897 kfree(rdev);
3919} 3898}
3920 3899
3921static struct class regulator_class = { 3900struct class regulator_class = {
3922 .name = "regulator", 3901 .name = "regulator",
3923 .dev_release = regulator_dev_release, 3902 .dev_release = regulator_dev_release,
3924 .dev_groups = regulator_dev_groups, 3903 .dev_groups = regulator_dev_groups,
diff --git a/drivers/regulator/internal.h b/drivers/regulator/internal.h
index 66a8ea0c8386..2f3218be5b8d 100644
--- a/drivers/regulator/internal.h
+++ b/drivers/regulator/internal.h
@@ -35,6 +35,15 @@ struct regulator {
35 struct dentry *debugfs; 35 struct dentry *debugfs;
36}; 36};
37 37
38extern struct class regulator_class;
39
40static inline struct regulator_dev *dev_to_rdev(struct device *dev)
41{
42 return container_of(dev, struct regulator_dev, dev);
43}
44
45struct regulator_dev *of_find_regulator_by_node(struct device_node *np);
46
38#ifdef CONFIG_OF 47#ifdef CONFIG_OF
39struct regulator_init_data *regulator_of_get_init_data(struct device *dev, 48struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
40 const struct regulator_desc *desc, 49 const struct regulator_desc *desc,
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 14637a01ba2d..54e810ae93d6 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -376,3 +376,17 @@ struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
376 376
377 return init_data; 377 return init_data;
378} 378}
379
380static int of_node_match(struct device *dev, const void *data)
381{
382 return dev->of_node == data;
383}
384
385struct regulator_dev *of_find_regulator_by_node(struct device_node *np)
386{
387 struct device *dev;
388
389 dev = class_find_device(&regulator_class, NULL, np, of_node_match);
390
391 return dev ? dev_to_rdev(dev) : NULL;
392}