Lines Matching refs:phy

3  * phy-core.c  --  Generic Phy framework.
17 #include <linux/phy/phy.h>
30 struct phy *phy = *(struct phy **)res;
32 phy_put(dev, phy);
44 struct phy *phy = *(struct phy **)res;
46 phy_destroy(phy);
51 struct phy **phy = res;
53 return *phy == match_data;
58 * @phy: the phy of the association
64 int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id)
68 if (!phy || !dev_id || !con_id)
77 pl->phy = phy;
89 * @phy: the phy of the association
96 void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id)
100 if (!phy || !dev_id || !con_id)
105 if (pl->phy == phy && !strcmp(pl->dev_id, dev_id) &&
115 static struct phy *phy_find(struct device *dev, const char *con_id)
128 return pl ? pl->phy : ERR_PTR(-ENODEV);
148 int phy_pm_runtime_get(struct phy *phy)
152 if (!phy)
155 if (!pm_runtime_enabled(&phy->dev))
158 ret = pm_runtime_get(&phy->dev);
160 pm_runtime_put_noidle(&phy->dev);
166 int phy_pm_runtime_get_sync(struct phy *phy)
170 if (!phy)
173 if (!pm_runtime_enabled(&phy->dev))
176 ret = pm_runtime_get_sync(&phy->dev);
178 pm_runtime_put_sync(&phy->dev);
184 int phy_pm_runtime_put(struct phy *phy)
186 if (!phy)
189 if (!pm_runtime_enabled(&phy->dev))
192 return pm_runtime_put(&phy->dev);
196 int phy_pm_runtime_put_sync(struct phy *phy)
198 if (!phy)
201 if (!pm_runtime_enabled(&phy->dev))
204 return pm_runtime_put_sync(&phy->dev);
208 void phy_pm_runtime_allow(struct phy *phy)
210 if (!phy)
213 if (!pm_runtime_enabled(&phy->dev))
216 pm_runtime_allow(&phy->dev);
220 void phy_pm_runtime_forbid(struct phy *phy)
222 if (!phy)
225 if (!pm_runtime_enabled(&phy->dev))
228 pm_runtime_forbid(&phy->dev);
232 int phy_init(struct phy *phy)
236 if (!phy)
239 ret = phy_pm_runtime_get_sync(phy);
244 mutex_lock(&phy->mutex);
245 if (phy->init_count == 0 && phy->ops->init) {
246 ret = phy->ops->init(phy);
248 dev_err(&phy->dev, "phy init failed --> %d\n", ret);
252 ++phy->init_count;
255 mutex_unlock(&phy->mutex);
256 phy_pm_runtime_put(phy);
261 int phy_exit(struct phy *phy)
265 if (!phy)
268 ret = phy_pm_runtime_get_sync(phy);
273 mutex_lock(&phy->mutex);
274 if (phy->init_count == 1 && phy->ops->exit) {
275 ret = phy->ops->exit(phy);
277 dev_err(&phy->dev, "phy exit failed --> %d\n", ret);
281 --phy->init_count;
284 mutex_unlock(&phy->mutex);
285 phy_pm_runtime_put(phy);
290 int phy_power_on(struct phy *phy)
294 if (!phy)
297 if (phy->pwr) {
298 ret = regulator_enable(phy->pwr);
303 ret = phy_pm_runtime_get_sync(phy);
309 mutex_lock(&phy->mutex);
310 if (phy->power_count == 0 && phy->ops->power_on) {
311 ret = phy->ops->power_on(phy);
313 dev_err(&phy->dev, "phy poweron failed --> %d\n", ret);
317 ++phy->power_count;
318 mutex_unlock(&phy->mutex);
322 mutex_unlock(&phy->mutex);
323 phy_pm_runtime_put_sync(phy);
325 if (phy->pwr)
326 regulator_disable(phy->pwr);
332 int phy_power_off(struct phy *phy)
336 if (!phy)
339 mutex_lock(&phy->mutex);
340 if (phy->power_count == 1 && phy->ops->power_off) {
341 ret = phy->ops->power_off(phy);
343 dev_err(&phy->dev, "phy poweroff failed --> %d\n", ret);
344 mutex_unlock(&phy->mutex);
348 --phy->power_count;
349 mutex_unlock(&phy->mutex);
350 phy_pm_runtime_put(phy);
352 if (phy->pwr)
353 regulator_disable(phy->pwr);
359 int phy_set_mode_ext(struct phy *phy, enum phy_mode mode, int submode)
363 if (!phy || !phy->ops->set_mode)
366 mutex_lock(&phy->mutex);
367 ret = phy->ops->set_mode(phy, mode, submode);
369 phy->attrs.mode = mode;
370 mutex_unlock(&phy->mutex);
376 int phy_reset(struct phy *phy)
380 if (!phy || !phy->ops->reset)
383 ret = phy_pm_runtime_get_sync(phy);
387 mutex_lock(&phy->mutex);
388 ret = phy->ops->reset(phy);
389 mutex_unlock(&phy->mutex);
391 phy_pm_runtime_put(phy);
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)
411 if (!phy || !phy->ops->calibrate)
414 mutex_lock(&phy->mutex);
415 ret = phy->ops->calibrate(phy);
416 mutex_unlock(&phy->mutex);
423 * phy_configure() - Changes the phy parameters
424 * @phy: the phy returned by phy_get()
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)
437 if (!phy)
440 if (!phy->ops->configure)
443 mutex_lock(&phy->mutex);
444 ret = phy->ops->configure(phy, opts);
445 mutex_unlock(&phy->mutex);
452 * phy_validate() - Checks the phy parameters
453 * @phy: the phy returned by phy_get()
459 * the phy. Implementations are free to tune the parameters passed as
467 int phy_validate(struct phy *phy, enum phy_mode mode, int submode,
472 if (!phy)
475 if (!phy->ops->validate)
478 mutex_lock(&phy->mutex);
479 ret = phy->ops->validate(phy, mode, submode, opts);
480 mutex_unlock(&phy->mutex);
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)
501 struct phy *phy = NULL;
504 ret = of_parse_phandle_with_args(np, "phys", "#phy-cells",
509 /* This phy type handled by the usb-phy subsystem for now */
516 phy = ERR_PTR(-EPROBE_DEFER);
522 phy = ERR_PTR(-ENODEV);
526 phy = phy_provider->of_xlate(phy_provider->dev, &args);
535 return phy;
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)
549 struct phy *phy = NULL;
553 index = of_property_match_string(np, "phy-names", con_id);
555 phy = _of_phy_get(np, index);
556 if (IS_ERR(phy))
557 return phy;
559 if (!try_module_get(phy->ops->owner))
562 get_device(&phy->dev);
564 return phy;
570 * @phy: the phy returned by of_phy_get()
574 void of_phy_put(struct phy *phy)
576 if (!phy || IS_ERR(phy))
579 mutex_lock(&phy->mutex);
580 if (phy->ops->release)
581 phy->ops->release(phy);
582 mutex_unlock(&phy->mutex);
584 module_put(phy->ops->owner);
585 put_device(&phy->dev);
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)
598 device_link_remove(dev, &phy->dev);
599 of_phy_put(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)
615 if (!phy)
618 r = devres_destroy(dev, devm_phy_release, devm_phy_match, phy);
624 * of_phy_simple_xlate() - returns the phy instance from phy provider
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
636 struct phy *phy;
641 phy = to_phy(dev);
642 if (args->np != phy->dev.of_node)
646 return phy;
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)
667 struct phy *phy;
676 index = of_property_match_string(dev->of_node, "phy-names",
678 phy = _of_phy_get(dev->of_node, index);
680 phy = phy_find(dev, string);
682 if (IS_ERR(phy))
683 return phy;
685 if (!try_module_get(phy->ops->owner))
688 get_device(&phy->dev);
690 link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS);
693 dev_name(phy->dev.parent));
695 return phy;
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)
711 struct phy *phy = phy_get(dev, string);
713 if (PTR_ERR(phy) == -ENODEV)
714 phy = NULL;
716 return phy;
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)
732 struct phy **ptr, *phy;
738 phy = phy_get(dev, string);
739 if (!IS_ERR(phy)) {
740 *ptr = phy;
746 return phy;
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)
765 struct phy *phy = devm_phy_get(dev, string);
767 if (PTR_ERR(phy) == -ENODEV)
768 phy = NULL;
770 return phy;
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,
787 struct phy **ptr, *phy;
794 phy = of_phy_get(np, con_id);
795 if (!IS_ERR(phy)) {
796 *ptr = phy;
800 return phy;
803 link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS);
806 dev_name(phy->dev.parent));
808 return phy;
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,
827 struct phy **ptr, *phy;
834 phy = _of_phy_get(np, index);
835 if (IS_ERR(phy)) {
837 return phy;
840 if (!try_module_get(phy->ops->owner)) {
845 get_device(&phy->dev);
847 *ptr = phy;
850 link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS);
853 dev_name(phy->dev.parent));
855 return phy;
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,
872 struct phy *phy;
877 phy = kzalloc(sizeof(*phy), GFP_KERNEL);
878 if (!phy)
888 device_initialize(&phy->dev);
889 mutex_init(&phy->mutex);
891 phy->dev.class = phy_class;
892 phy->dev.parent = dev;
893 phy->dev.of_node = node ?: dev->of_node;
894 phy->id = id;
895 phy->ops = ops;
897 ret = dev_set_name(&phy->dev, "phy-%s.%d", dev_name(dev), id);
901 /* phy-supply */
902 phy->pwr = regulator_get_optional(&phy->dev, "phy");
903 if (IS_ERR(phy->pwr)) {
904 ret = PTR_ERR(phy->pwr);
908 phy->pwr = NULL;
911 ret = device_add(&phy->dev);
916 pm_runtime_enable(&phy->dev);
917 pm_runtime_no_callbacks(&phy->dev);
920 return phy;
923 put_device(&phy->dev); /* calls phy_release() which frees resources */
927 kfree(phy);
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
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,
946 struct phy **ptr, *phy;
952 phy = phy_create(dev, node, ops);
953 if (!IS_ERR(phy)) {
954 *ptr = phy;
960 return phy;
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)
972 pm_runtime_disable(&phy->dev);
973 device_unregister(&phy->dev);
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)
989 r = devres_destroy(dev, devm_phy_consume, devm_phy_match, phy);
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.
1014 struct phy * (*of_xlate)(struct device *dev,
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,
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.
1138 * phy_release() - release the phy
1139 * @dev: the dev member within phy
1146 struct phy *phy;
1148 phy = to_phy(dev);
1150 regulator_put(phy->pwr);
1151 ida_simple_remove(&phy_ida, phy->id);
1152 kfree(phy);
1157 phy_class = class_create(THIS_MODULE, "phy");
1159 pr_err("failed to create phy class --> %ld\n",