diff options
Diffstat (limited to 'drivers/phy/phy-core.c')
-rw-r--r-- | drivers/phy/phy-core.c | 78 |
1 files changed, 44 insertions, 34 deletions
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 493876b17f..0a2f1b0d11 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * phy-core.c -- Generic Phy framework. * @@ -5,17 +6,12 @@ * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com * * Author: Kishon Vijay Abraham I <kishon@ti.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. */ #include <common.h> #include <malloc.h> #include <linux/phy/phy.h> -#include <usb/phy.h> +#include <linux/usb/phy.h> static LIST_HEAD(phy_provider_list); static int phy_ida; @@ -28,7 +24,7 @@ static int phy_ida; * * Called to create a phy using phy framework. */ -struct phy *phy_create(struct device_d *dev, struct device_node *node, +struct phy *phy_create(struct device *dev, struct device_node *node, const struct phy_ops *ops) { int ret; @@ -47,7 +43,7 @@ struct phy *phy_create(struct device_d *dev, struct device_node *node, dev_set_name(&phy->dev, "phy"); phy->dev.id = id; phy->dev.parent = dev; - phy->dev.device_node = node ?: dev->device_node; + phy->dev.of_node = node ?: dev->of_node; phy->id = id; phy->ops = ops; @@ -83,9 +79,9 @@ free_ida: * This is used in the case of dt boot for finding the phy instance from * phy provider. */ -struct phy_provider *__of_phy_provider_register(struct device_d *dev, - struct phy * (*of_xlate)(struct device_d *dev, - struct of_phandle_args *args)) +struct phy_provider *__of_phy_provider_register(struct device *dev, + struct phy * (*of_xlate)(struct device *dev, + struct of_phandle_args *args)) { struct phy_provider *phy_provider; @@ -173,8 +169,6 @@ 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; @@ -209,6 +203,21 @@ int phy_power_off(struct phy *phy) return 0; } +int phy_set_mode_ext(struct phy *phy, enum phy_mode mode, int submode) +{ + int ret; + + if (!phy || !phy->ops->set_mode) + return 0; + + ret = phy->ops->set_mode(phy, mode, submode); + if (!ret) + phy->attrs.mode = mode; + + return ret; +} +EXPORT_SYMBOL_GPL(phy_set_mode_ext); + struct usb_phy *phy_to_usbphy(struct phy *phy) { if (!phy) @@ -224,12 +233,17 @@ static struct phy_provider *of_phy_provider_lookup(struct device_node *node) { struct phy_provider *phy_provider; struct device_node *child; + int ret; + + ret = of_device_ensure_probed(node); + if (ret) + return ERR_PTR(ret); list_for_each_entry(phy_provider, &phy_provider_list, list) { - if (phy_provider->dev->device_node == node) + if (phy_provider->dev->of_node == node) return phy_provider; - for_each_child_of_node(phy_provider->dev->device_node, child) + for_each_child_of_node(phy_provider->dev->of_node, child) if (child == node) return phy_provider; } @@ -259,10 +273,6 @@ static struct phy *_of_phy_get(struct device_node *np, int index) if (ret) return ERR_PTR(-ENODEV); - ret = of_device_ensure_probed(args.np); - if (ret) - return ERR_PTR(ret); - phy_provider = of_phy_provider_lookup(args.np); if (IS_ERR(phy_provider)) { return ERR_CAST(phy_provider); @@ -300,27 +310,27 @@ struct phy *of_phy_get(struct device_node *np, const char *con_id) * -ENODEV if there is no such phy. The caller is responsible for * calling phy_put() to release that count. */ -struct phy *of_phy_get_by_phandle(struct device_d *dev, const char *phandle, +struct phy *of_phy_get_by_phandle(struct device *dev, const char *phandle, u8 index) { struct device_node *np; struct phy_provider *phy_provider; - if (!dev->device_node) { + if (!dev->of_node) { dev_dbg(dev, "device does not have a device node entry\n"); return ERR_PTR(-EINVAL); } - np = of_parse_phandle(dev->device_node, phandle, index); + np = of_parse_phandle(dev->of_node, phandle, index); if (!np) { - dev_dbg(dev, "failed to get %s phandle in %s node\n", phandle, - dev->device_node->full_name); + dev_dbg(dev, "failed to get %s phandle in %pOF node\n", phandle, + dev->of_node); return ERR_PTR(-ENODEV); } phy_provider = of_phy_provider_lookup(np); if (IS_ERR(phy_provider)) { - return ERR_PTR(-ENODEV); + return ERR_CAST(phy_provider); } return phy_provider->of_xlate(phy_provider->dev, NULL); @@ -336,7 +346,7 @@ struct phy *of_phy_get_by_phandle(struct device_d *dev, const char *phandle, * -ENODEV if there is no such phy. The caller is responsible for * calling phy_put() to release that count. */ -struct phy *phy_get(struct device_d *dev, const char *string) +struct phy *phy_get(struct device *dev, const char *string) { int index = 0; struct phy *phy = ERR_PTR(-ENODEV); @@ -346,10 +356,10 @@ struct phy *phy_get(struct device_d *dev, const char *string) return ERR_PTR(-EINVAL); } - if (dev->device_node) { - index = of_property_match_string(dev->device_node, "phy-names", - string); - phy = _of_phy_get(dev->device_node, index); + if (dev->of_node) { + index = of_property_match_string(dev->of_node, "phy-names", + string); + phy = _of_phy_get(dev->of_node, index); } return phy; @@ -365,7 +375,7 @@ struct phy *phy_get(struct device_d *dev, const char *string) * NULL if there is no such phy. The caller is responsible for * calling phy_put() to release that count. */ -struct phy *phy_optional_get(struct device_d *dev, const char *string) +struct phy *phy_optional_get(struct device *dev, const char *string) { struct phy *phy = phy_get(dev, string); @@ -382,10 +392,10 @@ struct phy *phy_optional_get(struct device_d *dev, const char *string) * * Gets the phy using _of_phy_get() */ -struct phy *phy_get_by_index(struct device_d *dev, int index) +struct phy *phy_get_by_index(struct device *dev, int index) { - if (!dev->device_node) + if (!dev->of_node) return ERR_PTR(-ENODEV); - return _of_phy_get(dev->device_node, index); + return _of_phy_get(dev->of_node, index); } |