diff options
author | Kamil Debski <k.debski@samsung.com> | 2014-03-06 06:16:46 -0500 |
---|---|---|
committer | Kishon Vijay Abraham I <kishon@ti.com> | 2014-03-08 02:09:42 -0500 |
commit | 0b3f3b2c777a2f7d20c9826a190ffd5bbd288f8f (patch) | |
tree | 213999b4bc559b470a3e02da6a899c67a03e2b4a /drivers/phy | |
parent | 6284be23db6b32e17ef34d082386967350d10d1a (diff) |
phy: core: Add an exported of_phy_get function
Previously the of_phy_get function took a struct device * and
was declared static. It was impossible to call it from
another driver and thus it was impossible to get phy defined
for a given node. The old function was renamed to _of_phy_get
and was left for internal use. of_phy_get function was added
and it was exported. The function enables to get a phy for
a given device tree node.
Signed-off-by: Kamil Debski <k.debski@samsung.com>
Reviewed-by: Tomasz Figa <t.figa@samsung.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Diffstat (limited to 'drivers/phy')
-rw-r--r-- | drivers/phy/phy-core.c | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 6c738376daff..7c1b0e14a235 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c | |||
@@ -274,8 +274,8 @@ int phy_power_off(struct phy *phy) | |||
274 | EXPORT_SYMBOL_GPL(phy_power_off); | 274 | EXPORT_SYMBOL_GPL(phy_power_off); |
275 | 275 | ||
276 | /** | 276 | /** |
277 | * of_phy_get() - lookup and obtain a reference to a phy by phandle | 277 | * _of_phy_get() - lookup and obtain a reference to a phy by phandle |
278 | * @dev: device that requests this phy | 278 | * @np: device_node for which to get the phy |
279 | * @index: the index of the phy | 279 | * @index: the index of the phy |
280 | * | 280 | * |
281 | * Returns the phy associated with the given phandle value, | 281 | * Returns the phy associated with the given phandle value, |
@@ -284,20 +284,17 @@ EXPORT_SYMBOL_GPL(phy_power_off); | |||
284 | * not yet loaded. This function uses of_xlate call back function provided | 284 | * not yet loaded. This function uses of_xlate call back function provided |
285 | * while registering the phy_provider to find the phy instance. | 285 | * while registering the phy_provider to find the phy instance. |
286 | */ | 286 | */ |
287 | static struct phy *of_phy_get(struct device *dev, int index) | 287 | static struct phy *_of_phy_get(struct device_node *np, int index) |
288 | { | 288 | { |
289 | int ret; | 289 | int ret; |
290 | struct phy_provider *phy_provider; | 290 | struct phy_provider *phy_provider; |
291 | struct phy *phy = NULL; | 291 | struct phy *phy = NULL; |
292 | struct of_phandle_args args; | 292 | struct of_phandle_args args; |
293 | 293 | ||
294 | ret = of_parse_phandle_with_args(dev->of_node, "phys", "#phy-cells", | 294 | ret = of_parse_phandle_with_args(np, "phys", "#phy-cells", |
295 | index, &args); | 295 | index, &args); |
296 | if (ret) { | 296 | if (ret) |
297 | dev_dbg(dev, "failed to get phy in %s node\n", | ||
298 | dev->of_node->full_name); | ||
299 | return ERR_PTR(-ENODEV); | 297 | return ERR_PTR(-ENODEV); |
300 | } | ||
301 | 298 | ||
302 | mutex_lock(&phy_provider_mutex); | 299 | mutex_lock(&phy_provider_mutex); |
303 | phy_provider = of_phy_provider_lookup(args.np); | 300 | phy_provider = of_phy_provider_lookup(args.np); |
@@ -317,6 +314,36 @@ err0: | |||
317 | } | 314 | } |
318 | 315 | ||
319 | /** | 316 | /** |
317 | * of_phy_get() - lookup and obtain a reference to a phy using a device_node. | ||
318 | * @np: device_node for which to get the phy | ||
319 | * @con_id: name of the phy from device's point of view | ||
320 | * | ||
321 | * Returns the phy driver, after getting a refcount to it; or | ||
322 | * -ENODEV if there is no such phy. The caller is responsible for | ||
323 | * calling phy_put() to release that count. | ||
324 | */ | ||
325 | struct phy *of_phy_get(struct device_node *np, const char *con_id) | ||
326 | { | ||
327 | struct phy *phy = NULL; | ||
328 | int index = 0; | ||
329 | |||
330 | if (con_id) | ||
331 | index = of_property_match_string(np, "phy-names", con_id); | ||
332 | |||
333 | phy = _of_phy_get(np, index); | ||
334 | if (IS_ERR(phy)) | ||
335 | return phy; | ||
336 | |||
337 | if (!try_module_get(phy->ops->owner)) | ||
338 | return ERR_PTR(-EPROBE_DEFER); | ||
339 | |||
340 | get_device(&phy->dev); | ||
341 | |||
342 | return phy; | ||
343 | } | ||
344 | EXPORT_SYMBOL_GPL(of_phy_get); | ||
345 | |||
346 | /** | ||
320 | * phy_put() - release the PHY | 347 | * phy_put() - release the PHY |
321 | * @phy: the phy returned by phy_get() | 348 | * @phy: the phy returned by phy_get() |
322 | * | 349 | * |
@@ -407,7 +434,7 @@ struct phy *phy_get(struct device *dev, const char *string) | |||
407 | if (dev->of_node) { | 434 | if (dev->of_node) { |
408 | index = of_property_match_string(dev->of_node, "phy-names", | 435 | index = of_property_match_string(dev->of_node, "phy-names", |
409 | string); | 436 | string); |
410 | phy = of_phy_get(dev, index); | 437 | phy = _of_phy_get(dev->of_node, index); |
411 | } else { | 438 | } else { |
412 | phy = phy_lookup(dev, string); | 439 | phy = phy_lookup(dev, string); |
413 | } | 440 | } |