Merge tag 'backport/v3.14.24-ltsi-rc1/phy-rcar-gen2-usb-to-v3.15' into backport/v3...
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / phy / phy-core.c
index 5f5b0f4..176c443 100644 (file)
@@ -64,6 +64,9 @@ static struct phy *phy_lookup(struct device *device, const char *port)
        class_dev_iter_init(&iter, phy_class, NULL, NULL);
        while ((dev = class_dev_iter_next(&iter))) {
                phy = to_phy(dev);
+
+               if (!phy->init_data)
+                       continue;
                count = phy->init_data->num_consumers;
                consumers = phy->init_data->consumers;
                while (count--) {
@@ -83,10 +86,15 @@ static struct phy *phy_lookup(struct device *device, const char *port)
 static struct phy_provider *of_phy_provider_lookup(struct device_node *node)
 {
        struct phy_provider *phy_provider;
+       struct device_node *child;
 
        list_for_each_entry(phy_provider, &phy_provider_list, list) {
                if (phy_provider->dev->of_node == node)
                        return phy_provider;
+
+               for_each_child_of_node(phy_provider->dev->of_node, child)
+                       if (child == node)
+                               return phy_provider;
        }
 
        return ERR_PTR(-EPROBE_DEFER);
@@ -176,6 +184,8 @@ int phy_init(struct phy *phy)
                        dev_err(&phy->dev, "phy init failed --> %d\n", ret);
                        goto out;
                }
+       } else {
+               ret = 0; /* Override possible ret == -ENOTSUPP */
        }
        ++phy->init_count;
 
@@ -232,6 +242,8 @@ int phy_power_on(struct phy *phy)
                        dev_err(&phy->dev, "phy poweron failed --> %d\n", ret);
                        goto out;
                }
+       } else {
+               ret = 0; /* Override possible ret == -ENOTSUPP */
        }
        ++phy->power_count;
        mutex_unlock(&phy->mutex);
@@ -364,13 +376,20 @@ struct phy *of_phy_simple_xlate(struct device *dev, struct of_phandle_args
        struct phy *phy;
        struct class_dev_iter iter;
        struct device_node *node = dev->of_node;
+       struct device_node *child;
 
        class_dev_iter_init(&iter, phy_class, NULL, NULL);
        while ((dev = class_dev_iter_next(&iter))) {
                phy = to_phy(dev);
-               if (node != phy->dev.of_node)
+               if (node != phy->dev.of_node) {
+                       for_each_child_of_node(node, child) {
+                               if (child == phy->dev.of_node)
+                                       goto phy_found;
+                       }
                        continue;
+               }
 
+phy_found:
                class_dev_iter_exit(&iter);
                return phy;
        }
@@ -404,17 +423,11 @@ struct phy *phy_get(struct device *dev, const char *string)
                index = of_property_match_string(dev->of_node, "phy-names",
                        string);
                phy = of_phy_get(dev, index);
-               if (IS_ERR(phy)) {
-                       dev_err(dev, "unable to find phy\n");
-                       return phy;
-               }
        } else {
                phy = phy_lookup(dev, string);
-               if (IS_ERR(phy)) {
-                       dev_err(dev, "unable to find phy\n");
-                       return phy;
-               }
        }
+       if (IS_ERR(phy))
+               return phy;
 
        if (!try_module_get(phy->ops->owner))
                return ERR_PTR(-EPROBE_DEFER);
@@ -503,13 +516,15 @@ EXPORT_SYMBOL_GPL(devm_phy_optional_get);
 /**
  * phy_create() - create a new phy
  * @dev: device that is creating the new phy
+ * @node: device node of the phy
  * @ops: function pointers for performing phy operations
  * @init_data: contains the list of PHY consumers or NULL
  *
  * Called to create a phy using phy framework.
  */
-struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
-       struct phy_init_data *init_data)
+struct phy *phy_create(struct device *dev, struct device_node *node,
+                      const struct phy_ops *ops,
+                      struct phy_init_data *init_data)
 {
        int ret;
        int id;
@@ -534,7 +549,7 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
 
        phy->dev.class = phy_class;
        phy->dev.parent = dev;
-       phy->dev.of_node = dev->of_node;
+       phy->dev.of_node = node ?: dev->of_node;
        phy->id = id;
        phy->ops = ops;
        phy->init_data = init_data;
@@ -555,8 +570,9 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
        return phy;
 
 put_dev:
-       put_device(&phy->dev);
-       ida_remove(&phy_ida, phy->id);
+       put_device(&phy->dev);  /* calls phy_release() which frees resources */
+       return ERR_PTR(ret);
+
 free_phy:
        kfree(phy);
        return ERR_PTR(ret);
@@ -566,6 +582,7 @@ EXPORT_SYMBOL_GPL(phy_create);
 /**
  * devm_phy_create() - create a new phy
  * @dev: device that is creating the new phy
+ * @node: device node of the phy
  * @ops: function pointers for performing phy operations
  * @init_data: contains the list of PHY consumers or NULL
  *
@@ -574,8 +591,9 @@ EXPORT_SYMBOL_GPL(phy_create);
  * On driver detach, release function is invoked on the devres data,
  * then, devres data is freed.
  */
-struct phy *devm_phy_create(struct device *dev, const struct phy_ops *ops,
-       struct phy_init_data *init_data)
+struct phy *devm_phy_create(struct device *dev, struct device_node *node,
+                           const struct phy_ops *ops,
+                           struct phy_init_data *init_data)
 {
        struct phy **ptr, *phy;
 
@@ -583,7 +601,7 @@ struct phy *devm_phy_create(struct device *dev, const struct phy_ops *ops,
        if (!ptr)
                return ERR_PTR(-ENOMEM);
 
-       phy = phy_create(dev, ops, init_data);
+       phy = phy_create(dev, node, ops, init_data);
        if (!IS_ERR(phy)) {
                *ptr = phy;
                devres_add(dev, ptr);
@@ -740,7 +758,7 @@ static void phy_release(struct device *dev)
 
        phy = to_phy(dev);
        dev_vdbg(dev, "releasing '%s'\n", dev_name(dev));
-       ida_remove(&phy_ida, phy->id);
+       ida_simple_remove(&phy_ida, phy->id);
        kfree(phy);
 }