regulator: mc13xxx: Add warning of incorrect names of regulators
authorAlexander Shiyan <shc_work@mail.ru>
Sat, 27 Apr 2013 06:29:24 +0000 (10:29 +0400)
committerMark Brown <broonie@sirena.org.uk>
Sun, 28 Apr 2013 01:10:00 +0000 (02:10 +0100)
This patch adds a warning about incorrect regulators instead of
printing the names of non-information message about the wrong amount.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Mark Brown <broonie@sirena.org.uk>
drivers/regulator/mc13892-regulator.c
drivers/regulator/mc13xxx-regulator-core.c
drivers/regulator/mc13xxx.h

index 9891aec47b57a02bcb17871e4c0caa57a152c1f7..364ddd1c8591a8dcc71e4609da8d148b1ce8796d 100644 (file)
@@ -535,7 +535,7 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
        struct mc13xxx_regulator_init_data *mc13xxx_data;
        struct regulator_config config = { };
        int i, ret;
-       int num_regulators = 0, num_parsed;
+       int num_regulators = 0;
        u32 val;
 
        num_regulators = mc13xxx_get_num_regulators_dt(pdev);
@@ -545,8 +545,6 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
        if (num_regulators <= 0)
                return -EINVAL;
 
-       num_parsed = num_regulators;
-
        priv = devm_kzalloc(&pdev->dev, sizeof(*priv) +
                num_regulators * sizeof(priv->regulators[0]),
                GFP_KERNEL);
@@ -589,40 +587,9 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
                = mc13892_vcam_get_mode;
 
        mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
-                                       ARRAY_SIZE(mc13892_regulators),
-                                       &num_parsed);
-
-       /*
-        * Perform a little sanity check on the regulator tree - if we found
-        * a number of regulators from mc13xxx_get_num_regulators_dt and
-        * then parsed a smaller number in mc13xxx_parse_regulators_dt then
-        * there is a regulator defined in the regulators node which has
-        * not matched any usable regulator in the driver. In this case,
-        * there is one missing and what will happen is the first regulator
-        * will get registered again.
-        *
-        * Fix this by basically making our number of registerable regulators
-        * equal to the number of regulators we parsed. We are allocating
-        * too much memory for priv, but this is unavoidable at this point.
-        *
-        * As an example of how this can happen, try making a typo in your
-        * regulators node (vviohi {} instead of viohi {}) so that the name
-        * does not match..
-        *
-        * The check will basically pass for platform data (non-DT) because
-        * mc13xxx_parse_regulators_dt for !CONFIG_OF will not touch num_parsed.
-        *
-        */
-       if (num_parsed != num_regulators) {
-               dev_warn(&pdev->dev,
-               "parsed %d != regulators %d - check your device tree!\n",
-                       num_parsed, num_regulators);
-
-               num_regulators = num_parsed;
-               priv->num_regulators = num_regulators;
-       }
+                                       ARRAY_SIZE(mc13892_regulators));
 
-       for (i = 0; i < num_regulators; i++) {
+       for (i = 0; i < priv->num_regulators; i++) {
                struct regulator_init_data *init_data;
                struct regulator_desc *desc;
                struct device_node *node = NULL;
index 23cf9f9c383b557b7cb7119576c5618356addfc8..da48592823020af8a10b025816a74aaea0226758 100644 (file)
@@ -180,15 +180,13 @@ EXPORT_SYMBOL_GPL(mc13xxx_get_num_regulators_dt);
 
 struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
        struct platform_device *pdev, struct mc13xxx_regulator *regulators,
-       int num_regulators, int *num_parsed)
+       int num_regulators)
 {
        struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev);
        struct mc13xxx_regulator_init_data *data, *p;
        struct device_node *parent, *child;
        int i, parsed = 0;
 
-       *num_parsed = 0;
-
        of_node_get(pdev->dev.parent->of_node);
        parent = of_find_node_by_name(pdev->dev.parent->of_node, "regulators");
        if (!parent)
@@ -204,10 +202,13 @@ struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
        p = data;
 
        for_each_child_of_node(parent, child) {
+               int found = 0;
+
                for (i = 0; i < num_regulators; i++) {
+                       if (!regulators[i].desc.name)
+                               continue;
                        if (!of_node_cmp(child->name,
                                         regulators[i].desc.name)) {
-
                                p->id = i;
                                p->init_data = of_get_regulator_init_data(
                                                        &pdev->dev, child);
@@ -215,13 +216,19 @@ struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
                                p++;
 
                                parsed++;
+                               found = 1;
                                break;
                        }
                }
+
+               if (!found)
+                       dev_warn(&pdev->dev,
+                                "Unknown regulator: %s\n", child->name);
        }
        of_node_put(parent);
 
-       *num_parsed = parsed;
+       priv->num_regulators = parsed;
+
        return data;
 }
 EXPORT_SYMBOL_GPL(mc13xxx_parse_regulators_dt);
index 007f83387fd6a6a0c209ceba25046144d6c80ce8..06c8903f182a680e7c0bb8464f227f3945cbc11f 100644 (file)
@@ -39,7 +39,7 @@ extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev,
 extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev);
 extern struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
        struct platform_device *pdev, struct mc13xxx_regulator *regulators,
-       int num_regulators, int *num_parsed);
+       int num_regulators);
 #else
 static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev)
 {
@@ -48,7 +48,7 @@ static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev)
 
 static inline struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
        struct platform_device *pdev, struct mc13xxx_regulator *regulators,
-       int num_regulators, int *num_parsed)
+       int num_regulators)
 {
        return NULL;
 }