• Home
  • Raw
  • Download

Lines Matching full:phy

2  * phy-core.c  --  Generic Phy framework.
21 #include <linux/phy/phy.h>
34 struct phy *phy = *(struct phy **)res; in devm_phy_release() local
36 phy_put(phy); in devm_phy_release()
48 struct phy *phy = *(struct phy **)res; in devm_phy_consume() local
50 phy_destroy(phy); in devm_phy_consume()
55 struct phy **phy = res; in devm_phy_match() local
57 return *phy == match_data; in devm_phy_match()
61 * phy_create_lookup() - allocate and register PHY/device association
62 * @phy: the phy of the association
68 int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id) in phy_create_lookup() argument
72 if (!phy || !dev_id || !con_id) in phy_create_lookup()
81 pl->phy = phy; in phy_create_lookup()
92 * phy_remove_lookup() - find and remove PHY/device association
93 * @phy: the phy of the association
100 void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id) in phy_remove_lookup() argument
104 if (!phy || !dev_id || !con_id) in phy_remove_lookup()
109 if (pl->phy == phy && !strcmp(pl->dev_id, dev_id) && in phy_remove_lookup()
119 static struct phy *phy_find(struct device *dev, const char *con_id) in phy_find()
132 return pl ? pl->phy : ERR_PTR(-ENODEV); in phy_find()
152 int phy_pm_runtime_get(struct phy *phy) in phy_pm_runtime_get() argument
156 if (!phy) in phy_pm_runtime_get()
159 if (!pm_runtime_enabled(&phy->dev)) in phy_pm_runtime_get()
162 ret = pm_runtime_get(&phy->dev); in phy_pm_runtime_get()
164 pm_runtime_put_noidle(&phy->dev); in phy_pm_runtime_get()
170 int phy_pm_runtime_get_sync(struct phy *phy) in phy_pm_runtime_get_sync() argument
174 if (!phy) in phy_pm_runtime_get_sync()
177 if (!pm_runtime_enabled(&phy->dev)) in phy_pm_runtime_get_sync()
180 ret = pm_runtime_get_sync(&phy->dev); in phy_pm_runtime_get_sync()
182 pm_runtime_put_sync(&phy->dev); in phy_pm_runtime_get_sync()
188 int phy_pm_runtime_put(struct phy *phy) in phy_pm_runtime_put() argument
190 if (!phy) in phy_pm_runtime_put()
193 if (!pm_runtime_enabled(&phy->dev)) in phy_pm_runtime_put()
196 return pm_runtime_put(&phy->dev); in phy_pm_runtime_put()
200 int phy_pm_runtime_put_sync(struct phy *phy) in phy_pm_runtime_put_sync() argument
202 if (!phy) in phy_pm_runtime_put_sync()
205 if (!pm_runtime_enabled(&phy->dev)) in phy_pm_runtime_put_sync()
208 return pm_runtime_put_sync(&phy->dev); in phy_pm_runtime_put_sync()
212 void phy_pm_runtime_allow(struct phy *phy) in phy_pm_runtime_allow() argument
214 if (!phy) in phy_pm_runtime_allow()
217 if (!pm_runtime_enabled(&phy->dev)) in phy_pm_runtime_allow()
220 pm_runtime_allow(&phy->dev); in phy_pm_runtime_allow()
224 void phy_pm_runtime_forbid(struct phy *phy) in phy_pm_runtime_forbid() argument
226 if (!phy) in phy_pm_runtime_forbid()
229 if (!pm_runtime_enabled(&phy->dev)) in phy_pm_runtime_forbid()
232 pm_runtime_forbid(&phy->dev); in phy_pm_runtime_forbid()
236 int phy_init(struct phy *phy) in phy_init() argument
240 if (!phy) in phy_init()
243 ret = phy_pm_runtime_get_sync(phy); in phy_init()
248 mutex_lock(&phy->mutex); in phy_init()
249 if (phy->init_count == 0 && phy->ops->init) { in phy_init()
250 ret = phy->ops->init(phy); in phy_init()
252 dev_err(&phy->dev, "phy init failed --> %d\n", ret); in phy_init()
256 ++phy->init_count; in phy_init()
259 mutex_unlock(&phy->mutex); in phy_init()
260 phy_pm_runtime_put(phy); in phy_init()
265 int phy_exit(struct phy *phy) in phy_exit() argument
269 if (!phy) in phy_exit()
272 ret = phy_pm_runtime_get_sync(phy); in phy_exit()
277 mutex_lock(&phy->mutex); in phy_exit()
278 if (phy->init_count == 1 && phy->ops->exit) { in phy_exit()
279 ret = phy->ops->exit(phy); in phy_exit()
281 dev_err(&phy->dev, "phy exit failed --> %d\n", ret); in phy_exit()
285 --phy->init_count; in phy_exit()
288 mutex_unlock(&phy->mutex); in phy_exit()
289 phy_pm_runtime_put(phy); in phy_exit()
294 int phy_power_on(struct phy *phy) in phy_power_on() argument
298 if (!phy) in phy_power_on()
301 if (phy->pwr) { in phy_power_on()
302 ret = regulator_enable(phy->pwr); in phy_power_on()
307 ret = phy_pm_runtime_get_sync(phy); in phy_power_on()
313 mutex_lock(&phy->mutex); in phy_power_on()
314 if (phy->power_count == 0 && phy->ops->power_on) { in phy_power_on()
315 ret = phy->ops->power_on(phy); in phy_power_on()
317 dev_err(&phy->dev, "phy poweron failed --> %d\n", ret); in phy_power_on()
321 ++phy->power_count; in phy_power_on()
322 mutex_unlock(&phy->mutex); in phy_power_on()
326 mutex_unlock(&phy->mutex); in phy_power_on()
327 phy_pm_runtime_put_sync(phy); in phy_power_on()
329 if (phy->pwr) in phy_power_on()
330 regulator_disable(phy->pwr); in phy_power_on()
336 int phy_power_off(struct phy *phy) in phy_power_off() argument
340 if (!phy) in phy_power_off()
343 mutex_lock(&phy->mutex); in phy_power_off()
344 if (phy->power_count == 1 && phy->ops->power_off) { in phy_power_off()
345 ret = phy->ops->power_off(phy); in phy_power_off()
347 dev_err(&phy->dev, "phy poweroff failed --> %d\n", ret); in phy_power_off()
348 mutex_unlock(&phy->mutex); in phy_power_off()
352 --phy->power_count; in phy_power_off()
353 mutex_unlock(&phy->mutex); in phy_power_off()
354 phy_pm_runtime_put(phy); in phy_power_off()
356 if (phy->pwr) in phy_power_off()
357 regulator_disable(phy->pwr); in phy_power_off()
363 int phy_set_mode(struct phy *phy, enum phy_mode mode) in phy_set_mode() argument
367 if (!phy || !phy->ops->set_mode) in phy_set_mode()
370 mutex_lock(&phy->mutex); in phy_set_mode()
371 ret = phy->ops->set_mode(phy, mode); in phy_set_mode()
373 phy->attrs.mode = mode; in phy_set_mode()
374 mutex_unlock(&phy->mutex); in phy_set_mode()
380 int phy_reset(struct phy *phy) in phy_reset() argument
384 if (!phy || !phy->ops->reset) in phy_reset()
387 mutex_lock(&phy->mutex); in phy_reset()
388 ret = phy->ops->reset(phy); in phy_reset()
389 mutex_unlock(&phy->mutex); in phy_reset()
395 int phy_calibrate(struct phy *phy) in phy_calibrate() argument
399 if (!phy || !phy->ops->calibrate) in phy_calibrate()
402 mutex_lock(&phy->mutex); in phy_calibrate()
403 ret = phy->ops->calibrate(phy); in phy_calibrate()
404 mutex_unlock(&phy->mutex); in phy_calibrate()
411 * _of_phy_get() - lookup and obtain a reference to a phy by phandle
412 * @np: device_node for which to get the phy
413 * @index: the index of the phy
415 * Returns the phy associated with the given phandle value,
416 * after getting a refcount to it or -ENODEV if there is no such phy or
417 * -EPROBE_DEFER if there is a phandle to the phy, but the device is
419 * while registering the phy_provider to find the phy instance.
421 static struct phy *_of_phy_get(struct device_node *np, int index) in _of_phy_get()
425 struct phy *phy = NULL; in _of_phy_get() local
428 ret = of_parse_phandle_with_args(np, "phys", "#phy-cells", in _of_phy_get()
433 /* This phy type handled by the usb-phy subsystem for now */ in _of_phy_get()
440 phy = ERR_PTR(-EPROBE_DEFER); in _of_phy_get()
445 dev_warn(phy_provider->dev, "Requested PHY is disabled\n"); in _of_phy_get()
446 phy = ERR_PTR(-ENODEV); in _of_phy_get()
450 phy = phy_provider->of_xlate(phy_provider->dev, &args); in _of_phy_get()
459 return phy; in _of_phy_get()
463 * of_phy_get() - lookup and obtain a reference to a phy using a device_node.
464 * @np: device_node for which to get the phy
465 * @con_id: name of the phy from device's point of view
467 * Returns the phy driver, after getting a refcount to it; or
468 * -ENODEV if there is no such phy. The caller is responsible for
471 struct phy *of_phy_get(struct device_node *np, const char *con_id) in of_phy_get()
473 struct phy *phy = NULL; in of_phy_get() local
477 index = of_property_match_string(np, "phy-names", con_id); in of_phy_get()
479 phy = _of_phy_get(np, index); in of_phy_get()
480 if (IS_ERR(phy)) in of_phy_get()
481 return phy; in of_phy_get()
483 if (!try_module_get(phy->ops->owner)) in of_phy_get()
486 get_device(&phy->dev); in of_phy_get()
488 return phy; in of_phy_get()
493 * phy_put() - release the PHY
494 * @phy: the phy returned by phy_get()
498 void phy_put(struct phy *phy) in phy_put() argument
500 if (!phy || IS_ERR(phy)) in phy_put()
503 module_put(phy->ops->owner); in phy_put()
504 put_device(&phy->dev); in phy_put()
509 * devm_phy_put() - release the PHY
510 * @dev: device that wants to release this phy
511 * @phy: the phy returned by devm_phy_get()
513 * destroys the devres associated with this phy and invokes phy_put
514 * to release the phy.
516 void devm_phy_put(struct device *dev, struct phy *phy) in devm_phy_put() argument
520 if (!phy) in devm_phy_put()
523 r = devres_destroy(dev, devm_phy_release, devm_phy_match, phy); in devm_phy_put()
524 dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n"); in devm_phy_put()
529 * of_phy_simple_xlate() - returns the phy instance from phy provider
530 * @dev: the PHY provider device
533 * Intended to be used by phy provider for the common case where #phy-cells is
534 * 0. For other cases where #phy-cells is greater than '0', the phy provider
536 * the appropriate phy.
538 struct phy *of_phy_simple_xlate(struct device *dev, struct of_phandle_args in of_phy_simple_xlate()
541 struct phy *phy; in of_phy_simple_xlate() local
546 phy = to_phy(dev); in of_phy_simple_xlate()
547 if (args->np != phy->dev.of_node) in of_phy_simple_xlate()
551 return phy; in of_phy_simple_xlate()
560 * phy_get() - lookup and obtain a reference to a phy.
561 * @dev: device that requests this phy
562 * @string: the phy name as given in the dt data or the name of the controller
565 * Returns the phy driver, after getting a refcount to it; or
566 * -ENODEV if there is no such phy. The caller is responsible for
569 struct phy *phy_get(struct device *dev, const char *string) in phy_get()
572 struct phy *phy; in phy_get() local
580 index = of_property_match_string(dev->of_node, "phy-names", in phy_get()
582 phy = _of_phy_get(dev->of_node, index); in phy_get()
584 phy = phy_find(dev, string); in phy_get()
586 if (IS_ERR(phy)) in phy_get()
587 return phy; in phy_get()
589 if (!try_module_get(phy->ops->owner)) in phy_get()
592 get_device(&phy->dev); in phy_get()
594 return phy; in phy_get()
599 * phy_optional_get() - lookup and obtain a reference to an optional phy.
600 * @dev: device that requests this phy
601 * @string: the phy name as given in the dt data or the name of the controller
604 * Returns the phy driver, after getting a refcount to it; or
605 * NULL if there is no such phy. The caller is responsible for
608 struct phy *phy_optional_get(struct device *dev, const char *string) in phy_optional_get()
610 struct phy *phy = phy_get(dev, string); in phy_optional_get() local
612 if (IS_ERR(phy) && (PTR_ERR(phy) == -ENODEV)) in phy_optional_get()
613 phy = NULL; in phy_optional_get()
615 return phy; in phy_optional_get()
620 * devm_phy_get() - lookup and obtain a reference to a phy.
621 * @dev: device that requests this phy
622 * @string: the phy name as given in the dt data or phy device name
625 * Gets the phy using phy_get(), and associates a device with it using
629 struct phy *devm_phy_get(struct device *dev, const char *string) in devm_phy_get()
631 struct phy **ptr, *phy; in devm_phy_get() local
637 phy = phy_get(dev, string); in devm_phy_get()
638 if (!IS_ERR(phy)) { in devm_phy_get()
639 *ptr = phy; in devm_phy_get()
645 return phy; in devm_phy_get()
650 * devm_phy_optional_get() - lookup and obtain a reference to an optional phy.
651 * @dev: device that requests this phy
652 * @string: the phy name as given in the dt data or phy device name
655 * Gets the phy using phy_get(), and associates a device with it using
658 * that if the phy does not exist, it is not considered an error and
659 * -ENODEV will not be returned. Instead the NULL phy is returned,
660 * which can be passed to all other phy consumer calls.
662 struct phy *devm_phy_optional_get(struct device *dev, const char *string) in devm_phy_optional_get()
664 struct phy *phy = devm_phy_get(dev, string); in devm_phy_optional_get() local
666 if (IS_ERR(phy) && (PTR_ERR(phy) == -ENODEV)) in devm_phy_optional_get()
667 phy = NULL; in devm_phy_optional_get()
669 return phy; in devm_phy_optional_get()
674 * devm_of_phy_get() - lookup and obtain a reference to a phy.
675 * @dev: device that requests this phy
676 * @np: node containing the phy
677 * @con_id: name of the phy from device's point of view
679 * Gets the phy using of_phy_get(), and associates a device with it using
683 struct phy *devm_of_phy_get(struct device *dev, struct device_node *np, in devm_of_phy_get()
686 struct phy **ptr, *phy; in devm_of_phy_get() local
692 phy = of_phy_get(np, con_id); in devm_of_phy_get()
693 if (!IS_ERR(phy)) { in devm_of_phy_get()
694 *ptr = phy; in devm_of_phy_get()
700 return phy; in devm_of_phy_get()
705 * devm_of_phy_get_by_index() - lookup and obtain a reference to a phy by index.
706 * @dev: device that requests this phy
707 * @np: node containing the phy
708 * @index: index of the phy
710 * Gets the phy using _of_phy_get(), then gets a refcount to it,
716 struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, in devm_of_phy_get_by_index()
719 struct phy **ptr, *phy; in devm_of_phy_get_by_index() local
725 phy = _of_phy_get(np, index); in devm_of_phy_get_by_index()
726 if (IS_ERR(phy)) { in devm_of_phy_get_by_index()
728 return phy; in devm_of_phy_get_by_index()
731 if (!try_module_get(phy->ops->owner)) { in devm_of_phy_get_by_index()
736 get_device(&phy->dev); in devm_of_phy_get_by_index()
738 *ptr = phy; in devm_of_phy_get_by_index()
741 return phy; in devm_of_phy_get_by_index()
746 * phy_create() - create a new phy
747 * @dev: device that is creating the new phy
748 * @node: device node of the phy
749 * @ops: function pointers for performing phy operations
751 * Called to create a phy using phy framework.
753 struct phy *phy_create(struct device *dev, struct device_node *node, in phy_create()
758 struct phy *phy; in phy_create() local
763 phy = kzalloc(sizeof(*phy), GFP_KERNEL); in phy_create()
764 if (!phy) in phy_create()
774 device_initialize(&phy->dev); in phy_create()
775 mutex_init(&phy->mutex); in phy_create()
777 phy->dev.class = phy_class; in phy_create()
778 phy->dev.parent = dev; in phy_create()
779 phy->dev.of_node = node ?: dev->of_node; in phy_create()
780 phy->id = id; in phy_create()
781 phy->ops = ops; in phy_create()
783 ret = dev_set_name(&phy->dev, "phy-%s.%d", dev_name(dev), id); in phy_create()
787 /* phy-supply */ in phy_create()
788 phy->pwr = regulator_get_optional(&phy->dev, "phy"); in phy_create()
789 if (IS_ERR(phy->pwr)) { in phy_create()
790 ret = PTR_ERR(phy->pwr); in phy_create()
794 phy->pwr = NULL; in phy_create()
797 ret = device_add(&phy->dev); in phy_create()
802 pm_runtime_enable(&phy->dev); in phy_create()
803 pm_runtime_no_callbacks(&phy->dev); in phy_create()
806 return phy; in phy_create()
809 put_device(&phy->dev); /* calls phy_release() which frees resources */ in phy_create()
813 kfree(phy); in phy_create()
819 * devm_phy_create() - create a new phy
820 * @dev: device that is creating the new phy
821 * @node: device node of the phy
822 * @ops: function pointers for performing phy operations
824 * Creates a new PHY device adding it to the PHY class.
825 * While at that, it also associates the device with the phy using devres.
829 struct phy *devm_phy_create(struct device *dev, struct device_node *node, in devm_phy_create()
832 struct phy **ptr, *phy; in devm_phy_create() local
838 phy = phy_create(dev, node, ops); in devm_phy_create()
839 if (!IS_ERR(phy)) { in devm_phy_create()
840 *ptr = phy; in devm_phy_create()
846 return phy; in devm_phy_create()
851 * phy_destroy() - destroy the phy
852 * @phy: the phy to be destroyed
854 * Called to destroy the phy.
856 void phy_destroy(struct phy *phy) in phy_destroy() argument
858 pm_runtime_disable(&phy->dev); in phy_destroy()
859 device_unregister(&phy->dev); in phy_destroy()
864 * devm_phy_destroy() - destroy the PHY
865 * @dev: device that wants to release this phy
866 * @phy: the phy returned by devm_phy_get()
868 * destroys the devres associated with this phy and invokes phy_destroy
869 * to destroy the phy.
871 void devm_phy_destroy(struct device *dev, struct phy *phy) in devm_phy_destroy() argument
875 r = devres_destroy(dev, devm_phy_consume, devm_phy_match, phy); in devm_phy_destroy()
876 dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n"); in devm_phy_destroy()
881 * __of_phy_provider_register() - create/register phy provider with the framework
882 * @dev: struct device of the phy provider
885 * @of_xlate: function pointer to obtain phy instance from phy provider
888 * This is used in the case of dt boot for finding the phy instance from
889 * phy provider.
891 * If the PHY provider doesn't nest children directly but uses a separate
900 struct phy * (*of_xlate)(struct device *dev, in __of_phy_provider_register()
948 * __devm_of_phy_provider_register() - create/register phy provider with the
950 * @dev: struct device of the phy provider
952 * @of_xlate: function pointer to obtain phy instance from phy provider
955 * This is used in the case of dt boot for finding the phy instance from
956 * phy provider. While at that, it also associates the device with the
957 * phy provider using devres. On driver detach, release function is invoked
962 struct phy * (*of_xlate)(struct device *dev, in __devm_of_phy_provider_register()
985 * of_phy_provider_unregister() - unregister phy provider from the framework
986 * @phy_provider: phy provider returned by of_phy_provider_register()
1004 * devm_of_phy_provider_unregister() - remove phy provider from the framework
1005 * @dev: struct device of the phy provider
1007 * destroys the devres associated with this phy provider and invokes
1008 * of_phy_provider_unregister to unregister the phy provider.
1016 dev_WARN_ONCE(dev, r, "couldn't find PHY provider device resource\n"); in devm_of_phy_provider_unregister()
1021 * phy_release() - release the phy
1022 * @dev: the dev member within phy
1029 struct phy *phy; in phy_release() local
1031 phy = to_phy(dev); in phy_release()
1033 regulator_put(phy->pwr); in phy_release()
1034 ida_simple_remove(&phy_ida, phy->id); in phy_release()
1035 kfree(phy); in phy_release()
1040 phy_class = class_create(THIS_MODULE, "phy"); in phy_core_init()
1042 pr_err("failed to create phy class --> %ld\n", in phy_core_init()
1059 MODULE_DESCRIPTION("Generic PHY Framework");