• Home
  • Raw
  • Download

Lines Matching full:phy

3  * phy-core.c  --  Generic Phy framework.
17 #include <linux/phy/phy.h>
30 struct phy *phy = *(struct phy **)res; in devm_phy_release() local
32 phy_put(dev, phy); in devm_phy_release()
44 struct phy *phy = *(struct phy **)res; in devm_phy_consume() local
46 phy_destroy(phy); in devm_phy_consume()
51 struct phy **phy = res; in devm_phy_match() local
53 return *phy == match_data; in devm_phy_match()
57 * phy_create_lookup() - allocate and register PHY/device association
58 * @phy: the phy of the association
64 int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id) in phy_create_lookup() argument
68 if (!phy || !dev_id || !con_id) in phy_create_lookup()
77 pl->phy = phy; in phy_create_lookup()
88 * phy_remove_lookup() - find and remove PHY/device association
89 * @phy: the phy of the association
96 void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id) in phy_remove_lookup() argument
100 if (!phy || !dev_id || !con_id) in phy_remove_lookup()
105 if (pl->phy == phy && !strcmp(pl->dev_id, dev_id) && in phy_remove_lookup()
115 static struct phy *phy_find(struct device *dev, const char *con_id) in phy_find()
128 return pl ? pl->phy : ERR_PTR(-ENODEV); in phy_find()
148 int phy_pm_runtime_get(struct phy *phy) in phy_pm_runtime_get() argument
152 if (!phy) in phy_pm_runtime_get()
155 if (!pm_runtime_enabled(&phy->dev)) in phy_pm_runtime_get()
158 ret = pm_runtime_get(&phy->dev); in phy_pm_runtime_get()
160 pm_runtime_put_noidle(&phy->dev); in phy_pm_runtime_get()
166 int phy_pm_runtime_get_sync(struct phy *phy) in phy_pm_runtime_get_sync() argument
170 if (!phy) in phy_pm_runtime_get_sync()
173 if (!pm_runtime_enabled(&phy->dev)) in phy_pm_runtime_get_sync()
176 ret = pm_runtime_get_sync(&phy->dev); in phy_pm_runtime_get_sync()
178 pm_runtime_put_sync(&phy->dev); in phy_pm_runtime_get_sync()
184 int phy_pm_runtime_put(struct phy *phy) in phy_pm_runtime_put() argument
186 if (!phy) in phy_pm_runtime_put()
189 if (!pm_runtime_enabled(&phy->dev)) in phy_pm_runtime_put()
192 return pm_runtime_put(&phy->dev); in phy_pm_runtime_put()
196 int phy_pm_runtime_put_sync(struct phy *phy) in phy_pm_runtime_put_sync() argument
198 if (!phy) in phy_pm_runtime_put_sync()
201 if (!pm_runtime_enabled(&phy->dev)) in phy_pm_runtime_put_sync()
204 return pm_runtime_put_sync(&phy->dev); in phy_pm_runtime_put_sync()
208 void phy_pm_runtime_allow(struct phy *phy) in phy_pm_runtime_allow() argument
210 if (!phy) in phy_pm_runtime_allow()
213 if (!pm_runtime_enabled(&phy->dev)) in phy_pm_runtime_allow()
216 pm_runtime_allow(&phy->dev); in phy_pm_runtime_allow()
220 void phy_pm_runtime_forbid(struct phy *phy) in phy_pm_runtime_forbid() argument
222 if (!phy) in phy_pm_runtime_forbid()
225 if (!pm_runtime_enabled(&phy->dev)) in phy_pm_runtime_forbid()
228 pm_runtime_forbid(&phy->dev); in phy_pm_runtime_forbid()
232 int phy_init(struct phy *phy) in phy_init() argument
236 if (!phy) in phy_init()
239 ret = phy_pm_runtime_get_sync(phy); in phy_init()
244 mutex_lock(&phy->mutex); in phy_init()
245 if (phy->init_count == 0 && phy->ops->init) { in phy_init()
246 ret = phy->ops->init(phy); in phy_init()
248 dev_err(&phy->dev, "phy init failed --> %d\n", ret); in phy_init()
252 ++phy->init_count; in phy_init()
255 mutex_unlock(&phy->mutex); in phy_init()
256 phy_pm_runtime_put(phy); in phy_init()
261 int phy_exit(struct phy *phy) in phy_exit() argument
265 if (!phy) in phy_exit()
268 ret = phy_pm_runtime_get_sync(phy); in phy_exit()
273 mutex_lock(&phy->mutex); in phy_exit()
274 if (phy->init_count == 1 && phy->ops->exit) { in phy_exit()
275 ret = phy->ops->exit(phy); in phy_exit()
277 dev_err(&phy->dev, "phy exit failed --> %d\n", ret); in phy_exit()
281 --phy->init_count; in phy_exit()
284 mutex_unlock(&phy->mutex); in phy_exit()
285 phy_pm_runtime_put(phy); in phy_exit()
290 int phy_power_on(struct phy *phy) in phy_power_on() argument
294 if (!phy) in phy_power_on()
297 if (phy->pwr) { in phy_power_on()
298 ret = regulator_enable(phy->pwr); in phy_power_on()
303 ret = phy_pm_runtime_get_sync(phy); in phy_power_on()
309 mutex_lock(&phy->mutex); in phy_power_on()
310 if (phy->power_count == 0 && phy->ops->power_on) { in phy_power_on()
311 ret = phy->ops->power_on(phy); in phy_power_on()
313 dev_err(&phy->dev, "phy poweron failed --> %d\n", ret); in phy_power_on()
317 ++phy->power_count; in phy_power_on()
318 mutex_unlock(&phy->mutex); in phy_power_on()
322 mutex_unlock(&phy->mutex); in phy_power_on()
323 phy_pm_runtime_put_sync(phy); in phy_power_on()
325 if (phy->pwr) in phy_power_on()
326 regulator_disable(phy->pwr); in phy_power_on()
332 int phy_power_off(struct phy *phy) in phy_power_off() argument
336 if (!phy) in phy_power_off()
339 mutex_lock(&phy->mutex); in phy_power_off()
340 if (phy->power_count == 1 && phy->ops->power_off) { in phy_power_off()
341 ret = phy->ops->power_off(phy); in phy_power_off()
343 dev_err(&phy->dev, "phy poweroff failed --> %d\n", ret); in phy_power_off()
344 mutex_unlock(&phy->mutex); in phy_power_off()
348 --phy->power_count; in phy_power_off()
349 mutex_unlock(&phy->mutex); in phy_power_off()
350 phy_pm_runtime_put(phy); in phy_power_off()
352 if (phy->pwr) in phy_power_off()
353 regulator_disable(phy->pwr); in phy_power_off()
359 int phy_set_mode_ext(struct phy *phy, enum phy_mode mode, int submode) in phy_set_mode_ext() argument
363 if (!phy || !phy->ops->set_mode) in phy_set_mode_ext()
366 mutex_lock(&phy->mutex); in phy_set_mode_ext()
367 ret = phy->ops->set_mode(phy, mode, submode); in phy_set_mode_ext()
369 phy->attrs.mode = mode; in phy_set_mode_ext()
370 mutex_unlock(&phy->mutex); in phy_set_mode_ext()
376 int phy_reset(struct phy *phy) in phy_reset() argument
380 if (!phy || !phy->ops->reset) in phy_reset()
383 ret = phy_pm_runtime_get_sync(phy); 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()
391 phy_pm_runtime_put(phy); in phy_reset()
398 * phy_calibrate() - Tunes the phy hw parameters for current configuration
399 * @phy: the phy returned by phy_get()
401 * Used to calibrate phy hardware, typically by adjusting some parameters in
407 int phy_calibrate(struct phy *phy) in phy_calibrate() argument
411 if (!phy || !phy->ops->calibrate) in phy_calibrate()
414 mutex_lock(&phy->mutex); in phy_calibrate()
415 ret = phy->ops->calibrate(phy); in phy_calibrate()
416 mutex_unlock(&phy->mutex); in phy_calibrate()
423 * phy_configure() - Changes the phy parameters
424 * @phy: the phy returned by phy_get()
427 * Used to change the PHY parameters. phy_init() must have been called
428 * on the phy. The configuration will be applied on the current phy
433 int phy_configure(struct phy *phy, union phy_configure_opts *opts) in phy_configure() argument
437 if (!phy) in phy_configure()
440 if (!phy->ops->configure) in phy_configure()
443 mutex_lock(&phy->mutex); in phy_configure()
444 ret = phy->ops->configure(phy, opts); in phy_configure()
445 mutex_unlock(&phy->mutex); in phy_configure()
452 * phy_validate() - Checks the phy parameters
453 * @phy: the phy returned by phy_get()
455 * @submode: PHY submode the configuration is applicable to.
459 * the phy. Implementations are free to tune the parameters passed as
462 * PHY, so calling it as many times as deemed fit will have no side
467 int phy_validate(struct phy *phy, enum phy_mode mode, int submode, in phy_validate() argument
472 if (!phy) in phy_validate()
475 if (!phy->ops->validate) in phy_validate()
478 mutex_lock(&phy->mutex); in phy_validate()
479 ret = phy->ops->validate(phy, mode, submode, opts); in phy_validate()
480 mutex_unlock(&phy->mutex); in phy_validate()
487 * _of_phy_get() - lookup and obtain a reference to a phy by phandle
488 * @np: device_node for which to get the phy
489 * @index: the index of the phy
491 * Returns the phy associated with the given phandle value,
492 * after getting a refcount to it or -ENODEV if there is no such phy or
493 * -EPROBE_DEFER if there is a phandle to the phy, but the device is
495 * while registering the phy_provider to find the phy instance.
497 static struct phy *_of_phy_get(struct device_node *np, int index) in _of_phy_get()
501 struct phy *phy = NULL; in _of_phy_get() local
504 ret = of_parse_phandle_with_args(np, "phys", "#phy-cells", in _of_phy_get()
509 /* This phy type handled by the usb-phy subsystem for now */ in _of_phy_get()
516 phy = ERR_PTR(-EPROBE_DEFER); in _of_phy_get()
521 dev_warn(phy_provider->dev, "Requested PHY is disabled\n"); in _of_phy_get()
522 phy = ERR_PTR(-ENODEV); in _of_phy_get()
526 phy = phy_provider->of_xlate(phy_provider->dev, &args); in _of_phy_get()
535 return phy; in _of_phy_get()
539 * of_phy_get() - lookup and obtain a reference to a phy using a device_node.
540 * @np: device_node for which to get the phy
541 * @con_id: name of the phy from device's point of view
543 * Returns the phy driver, after getting a refcount to it; or
544 * -ENODEV if there is no such phy. The caller is responsible for
547 struct phy *of_phy_get(struct device_node *np, const char *con_id) in of_phy_get()
549 struct phy *phy = NULL; in of_phy_get() local
553 index = of_property_match_string(np, "phy-names", con_id); in of_phy_get()
555 phy = _of_phy_get(np, index); in of_phy_get()
556 if (IS_ERR(phy)) in of_phy_get()
557 return phy; in of_phy_get()
559 if (!try_module_get(phy->ops->owner)) in of_phy_get()
562 get_device(&phy->dev); in of_phy_get()
564 return phy; in of_phy_get()
569 * of_phy_put() - release the PHY
570 * @phy: the phy returned by of_phy_get()
574 void of_phy_put(struct phy *phy) in of_phy_put() argument
576 if (!phy || IS_ERR(phy)) in of_phy_put()
579 mutex_lock(&phy->mutex); in of_phy_put()
580 if (phy->ops->release) in of_phy_put()
581 phy->ops->release(phy); in of_phy_put()
582 mutex_unlock(&phy->mutex); in of_phy_put()
584 module_put(phy->ops->owner); in of_phy_put()
585 put_device(&phy->dev); in of_phy_put()
590 * phy_put() - release the PHY
591 * @dev: device that wants to release this phy
592 * @phy: the phy returned by phy_get()
596 void phy_put(struct device *dev, struct phy *phy) in phy_put() argument
598 device_link_remove(dev, &phy->dev); in phy_put()
599 of_phy_put(phy); in phy_put()
604 * devm_phy_put() - release the PHY
605 * @dev: device that wants to release this phy
606 * @phy: the phy returned by devm_phy_get()
608 * destroys the devres associated with this phy and invokes phy_put
609 * to release the phy.
611 void devm_phy_put(struct device *dev, struct phy *phy) in devm_phy_put() argument
615 if (!phy) in devm_phy_put()
618 r = devres_destroy(dev, devm_phy_release, devm_phy_match, phy); in devm_phy_put()
619 dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n"); in devm_phy_put()
624 * of_phy_simple_xlate() - returns the phy instance from phy provider
625 * @dev: the PHY provider device
628 * Intended to be used by phy provider for the common case where #phy-cells is
629 * 0. For other cases where #phy-cells is greater than '0', the phy provider
631 * the appropriate phy.
633 struct phy *of_phy_simple_xlate(struct device *dev, struct of_phandle_args in of_phy_simple_xlate()
636 struct phy *phy; in of_phy_simple_xlate() local
641 phy = to_phy(dev); in of_phy_simple_xlate()
642 if (args->np != phy->dev.of_node) in of_phy_simple_xlate()
646 return phy; in of_phy_simple_xlate()
655 * phy_get() - lookup and obtain a reference to a phy.
656 * @dev: device that requests this phy
657 * @string: the phy name as given in the dt data or the name of the controller
660 * Returns the phy driver, after getting a refcount to it; or
661 * -ENODEV if there is no such phy. The caller is responsible for
664 struct phy *phy_get(struct device *dev, const char *string) in phy_get()
667 struct phy *phy; in phy_get() local
676 index = of_property_match_string(dev->of_node, "phy-names", in phy_get()
678 phy = _of_phy_get(dev->of_node, index); in phy_get()
680 phy = phy_find(dev, string); in phy_get()
682 if (IS_ERR(phy)) in phy_get()
683 return phy; in phy_get()
685 if (!try_module_get(phy->ops->owner)) in phy_get()
688 get_device(&phy->dev); in phy_get()
690 link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS); in phy_get()
693 dev_name(phy->dev.parent)); in phy_get()
695 return phy; in phy_get()
700 * phy_optional_get() - lookup and obtain a reference to an optional phy.
701 * @dev: device that requests this phy
702 * @string: the phy name as given in the dt data or the name of the controller
705 * Returns the phy driver, after getting a refcount to it; or
706 * NULL if there is no such phy. The caller is responsible for
709 struct phy *phy_optional_get(struct device *dev, const char *string) in phy_optional_get()
711 struct phy *phy = phy_get(dev, string); in phy_optional_get() local
713 if (PTR_ERR(phy) == -ENODEV) in phy_optional_get()
714 phy = NULL; in phy_optional_get()
716 return phy; in phy_optional_get()
721 * devm_phy_get() - lookup and obtain a reference to a phy.
722 * @dev: device that requests this phy
723 * @string: the phy name as given in the dt data or phy device name
726 * Gets the phy using phy_get(), and associates a device with it using
730 struct phy *devm_phy_get(struct device *dev, const char *string) in devm_phy_get()
732 struct phy **ptr, *phy; in devm_phy_get() local
738 phy = phy_get(dev, string); in devm_phy_get()
739 if (!IS_ERR(phy)) { in devm_phy_get()
740 *ptr = phy; in devm_phy_get()
746 return phy; in devm_phy_get()
751 * devm_phy_optional_get() - lookup and obtain a reference to an optional phy.
752 * @dev: device that requests this phy
753 * @string: the phy name as given in the dt data or phy device name
756 * Gets the phy using phy_get(), and associates a device with it using
759 * that if the phy does not exist, it is not considered an error and
760 * -ENODEV will not be returned. Instead the NULL phy is returned,
761 * which can be passed to all other phy consumer calls.
763 struct phy *devm_phy_optional_get(struct device *dev, const char *string) in devm_phy_optional_get()
765 struct phy *phy = devm_phy_get(dev, string); in devm_phy_optional_get() local
767 if (PTR_ERR(phy) == -ENODEV) in devm_phy_optional_get()
768 phy = NULL; in devm_phy_optional_get()
770 return phy; in devm_phy_optional_get()
775 * devm_of_phy_get() - lookup and obtain a reference to a phy.
776 * @dev: device that requests this phy
777 * @np: node containing the phy
778 * @con_id: name of the phy from device's point of view
780 * Gets the phy using of_phy_get(), and associates a device with it using
784 struct phy *devm_of_phy_get(struct device *dev, struct device_node *np, in devm_of_phy_get()
787 struct phy **ptr, *phy; in devm_of_phy_get() local
794 phy = of_phy_get(np, con_id); in devm_of_phy_get()
795 if (!IS_ERR(phy)) { in devm_of_phy_get()
796 *ptr = phy; in devm_of_phy_get()
800 return phy; in devm_of_phy_get()
803 link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS); in devm_of_phy_get()
806 dev_name(phy->dev.parent)); in devm_of_phy_get()
808 return phy; in devm_of_phy_get()
813 * devm_of_phy_get_by_index() - lookup and obtain a reference to a phy by index.
814 * @dev: device that requests this phy
815 * @np: node containing the phy
816 * @index: index of the phy
818 * Gets the phy using _of_phy_get(), then gets a refcount to it,
824 struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, in devm_of_phy_get_by_index()
827 struct phy **ptr, *phy; in devm_of_phy_get_by_index() local
834 phy = _of_phy_get(np, index); in devm_of_phy_get_by_index()
835 if (IS_ERR(phy)) { in devm_of_phy_get_by_index()
837 return phy; in devm_of_phy_get_by_index()
840 if (!try_module_get(phy->ops->owner)) { in devm_of_phy_get_by_index()
845 get_device(&phy->dev); in devm_of_phy_get_by_index()
847 *ptr = phy; in devm_of_phy_get_by_index()
850 link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS); in devm_of_phy_get_by_index()
853 dev_name(phy->dev.parent)); in devm_of_phy_get_by_index()
855 return phy; in devm_of_phy_get_by_index()
860 * phy_create() - create a new phy
861 * @dev: device that is creating the new phy
862 * @node: device node of the phy
863 * @ops: function pointers for performing phy operations
865 * Called to create a phy using phy framework.
867 struct phy *phy_create(struct device *dev, struct device_node *node, in phy_create()
872 struct phy *phy; in phy_create() local
877 phy = kzalloc(sizeof(*phy), GFP_KERNEL); in phy_create()
878 if (!phy) in phy_create()
888 device_initialize(&phy->dev); in phy_create()
889 mutex_init(&phy->mutex); in phy_create()
891 phy->dev.class = phy_class; in phy_create()
892 phy->dev.parent = dev; in phy_create()
893 phy->dev.of_node = node ?: dev->of_node; in phy_create()
894 phy->id = id; in phy_create()
895 phy->ops = ops; in phy_create()
897 ret = dev_set_name(&phy->dev, "phy-%s.%d", dev_name(dev), id); in phy_create()
901 /* phy-supply */ in phy_create()
902 phy->pwr = regulator_get_optional(&phy->dev, "phy"); in phy_create()
903 if (IS_ERR(phy->pwr)) { in phy_create()
904 ret = PTR_ERR(phy->pwr); in phy_create()
908 phy->pwr = NULL; in phy_create()
911 ret = device_add(&phy->dev); in phy_create()
916 pm_runtime_enable(&phy->dev); in phy_create()
917 pm_runtime_no_callbacks(&phy->dev); in phy_create()
920 return phy; in phy_create()
923 put_device(&phy->dev); /* calls phy_release() which frees resources */ in phy_create()
927 kfree(phy); in phy_create()
933 * devm_phy_create() - create a new phy
934 * @dev: device that is creating the new phy
935 * @node: device node of the phy
936 * @ops: function pointers for performing phy operations
938 * Creates a new PHY device adding it to the PHY class.
939 * While at that, it also associates the device with the phy using devres.
943 struct phy *devm_phy_create(struct device *dev, struct device_node *node, in devm_phy_create()
946 struct phy **ptr, *phy; in devm_phy_create() local
952 phy = phy_create(dev, node, ops); in devm_phy_create()
953 if (!IS_ERR(phy)) { in devm_phy_create()
954 *ptr = phy; in devm_phy_create()
960 return phy; in devm_phy_create()
965 * phy_destroy() - destroy the phy
966 * @phy: the phy to be destroyed
968 * Called to destroy the phy.
970 void phy_destroy(struct phy *phy) in phy_destroy() argument
972 pm_runtime_disable(&phy->dev); in phy_destroy()
973 device_unregister(&phy->dev); in phy_destroy()
978 * devm_phy_destroy() - destroy the PHY
979 * @dev: device that wants to release this phy
980 * @phy: the phy returned by devm_phy_get()
982 * destroys the devres associated with this phy and invokes phy_destroy
983 * to destroy the phy.
985 void devm_phy_destroy(struct device *dev, struct phy *phy) in devm_phy_destroy() argument
989 r = devres_destroy(dev, devm_phy_consume, devm_phy_match, phy); in devm_phy_destroy()
990 dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n"); in devm_phy_destroy()
995 * __of_phy_provider_register() - create/register phy provider with the framework
996 * @dev: struct device of the phy provider
999 * @of_xlate: function pointer to obtain phy instance from phy provider
1002 * This is used in the case of dt boot for finding the phy instance from
1003 * phy provider.
1005 * If the PHY provider doesn't nest children directly but uses a separate
1014 struct phy * (*of_xlate)(struct device *dev, in __of_phy_provider_register()
1062 * __devm_of_phy_provider_register() - create/register phy provider with the
1064 * @dev: struct device of the phy provider
1067 * @of_xlate: function pointer to obtain phy instance from phy provider
1070 * This is used in the case of dt boot for finding the phy instance from
1071 * phy provider. While at that, it also associates the device with the
1072 * phy provider using devres. On driver detach, release function is invoked
1077 struct phy * (*of_xlate)(struct device *dev, in __devm_of_phy_provider_register()
1100 * of_phy_provider_unregister() - unregister phy provider from the framework
1101 * @phy_provider: phy provider returned by of_phy_provider_register()
1119 * devm_of_phy_provider_unregister() - remove phy provider from the framework
1120 * @dev: struct device of the phy provider
1121 * @phy_provider: phy provider returned by of_phy_provider_register()
1123 * destroys the devres associated with this phy provider and invokes
1124 * of_phy_provider_unregister to unregister the phy provider.
1133 dev_WARN_ONCE(dev, r, "couldn't find PHY provider device resource\n"); in devm_of_phy_provider_unregister()
1138 * phy_release() - release the phy
1139 * @dev: the dev member within phy
1146 struct phy *phy; in phy_release() local
1148 phy = to_phy(dev); in phy_release()
1150 regulator_put(phy->pwr); in phy_release()
1151 ida_simple_remove(&phy_ida, phy->id); in phy_release()
1152 kfree(phy); in phy_release()
1157 phy_class = class_create(THIS_MODULE, "phy"); in phy_core_init()
1159 pr_err("failed to create phy class --> %ld\n", in phy_core_init()