Lines Matching +full:- +full:phy
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * phy-core.c -- Generic Phy framework.
5 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
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()
69 return -EINVAL; in phy_create_lookup()
73 return -ENOMEM; in phy_create_lookup()
75 pl->dev_id = dev_id; in phy_create_lookup()
76 pl->con_id = con_id; in phy_create_lookup()
77 pl->phy = phy; in phy_create_lookup()
80 list_add_tail(&pl->node, &phys); 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()
106 !strcmp(pl->con_id, con_id)) { in phy_remove_lookup()
107 list_del(&pl->node); in phy_remove_lookup()
115 static struct phy *phy_find(struct device *dev, const char *con_id) in phy_find()
122 if (!strcmp(p->dev_id, dev_id) && !strcmp(p->con_id, con_id)) { in phy_find()
128 return pl ? pl->phy : ERR_PTR(-ENODEV); in phy_find()
137 if (phy_provider->dev->of_node == node) in of_phy_provider_lookup()
140 for_each_child_of_node(phy_provider->children, child) in of_phy_provider_lookup()
145 return ERR_PTR(-EPROBE_DEFER); in of_phy_provider_lookup()
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()
156 return -ENOTSUPP; in phy_pm_runtime_get()
158 ret = pm_runtime_get(&phy->dev); in phy_pm_runtime_get()
159 if (ret < 0 && ret != -EINPROGRESS) 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()
174 return -ENOTSUPP; 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()
190 return -ENOTSUPP; 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()
202 return -ENOTSUPP; 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()
233 * phy_init - phy internal initialization before phy operation
234 * @phy: the phy returned by phy_get()
236 * Used to allow phy's driver to perform phy internal initialization,
238 * is required by the phy to perform the start of operation.
243 int phy_init(struct phy *phy) in phy_init() argument
247 if (!phy) in phy_init()
250 ret = phy_pm_runtime_get_sync(phy); in phy_init()
251 if (ret < 0 && ret != -ENOTSUPP) in phy_init()
253 ret = 0; /* Override possible ret == -ENOTSUPP */ in phy_init()
255 mutex_lock(&phy->mutex); in phy_init()
256 if (phy->power_count > phy->init_count) in phy_init()
257 dev_warn(&phy->dev, "phy_power_on was called before phy_init\n"); in phy_init()
259 if (phy->init_count == 0 && phy->ops->init) { in phy_init()
260 ret = phy->ops->init(phy); in phy_init()
262 dev_err(&phy->dev, "phy init failed --> %d\n", ret); in phy_init()
266 ++phy->init_count; in phy_init()
269 mutex_unlock(&phy->mutex); in phy_init()
270 phy_pm_runtime_put(phy); in phy_init()
276 * phy_exit - Phy internal un-initialization
277 * @phy: the phy returned by phy_get()
283 int phy_exit(struct phy *phy) in phy_exit() argument
287 if (!phy) in phy_exit()
290 ret = phy_pm_runtime_get_sync(phy); in phy_exit()
291 if (ret < 0 && ret != -ENOTSUPP) in phy_exit()
293 ret = 0; /* Override possible ret == -ENOTSUPP */ in phy_exit()
295 mutex_lock(&phy->mutex); in phy_exit()
296 if (phy->init_count == 1 && phy->ops->exit) { in phy_exit()
297 ret = phy->ops->exit(phy); in phy_exit()
299 dev_err(&phy->dev, "phy exit failed --> %d\n", ret); in phy_exit()
303 --phy->init_count; in phy_exit()
306 mutex_unlock(&phy->mutex); in phy_exit()
307 phy_pm_runtime_put(phy); in phy_exit()
313 * phy_power_on - Enable the phy and enter proper operation
314 * @phy: the phy returned by phy_get()
320 int phy_power_on(struct phy *phy) in phy_power_on() argument
324 if (!phy) in phy_power_on()
327 if (phy->pwr) { in phy_power_on()
328 ret = regulator_enable(phy->pwr); in phy_power_on()
333 ret = phy_pm_runtime_get_sync(phy); in phy_power_on()
334 if (ret < 0 && ret != -ENOTSUPP) in phy_power_on()
337 ret = 0; /* Override possible ret == -ENOTSUPP */ in phy_power_on()
339 mutex_lock(&phy->mutex); in phy_power_on()
340 if (phy->power_count == 0 && phy->ops->power_on) { in phy_power_on()
341 ret = phy->ops->power_on(phy); in phy_power_on()
343 dev_err(&phy->dev, "phy poweron failed --> %d\n", ret); in phy_power_on()
347 ++phy->power_count; in phy_power_on()
348 mutex_unlock(&phy->mutex); in phy_power_on()
352 mutex_unlock(&phy->mutex); in phy_power_on()
353 phy_pm_runtime_put_sync(phy); in phy_power_on()
355 if (phy->pwr) in phy_power_on()
356 regulator_disable(phy->pwr); in phy_power_on()
363 * phy_power_off - Disable the phy.
364 * @phy: the phy returned by phy_get()
370 int phy_power_off(struct phy *phy) in phy_power_off() argument
374 if (!phy) in phy_power_off()
377 mutex_lock(&phy->mutex); in phy_power_off()
378 if (phy->power_count == 1 && phy->ops->power_off) { in phy_power_off()
379 ret = phy->ops->power_off(phy); in phy_power_off()
381 dev_err(&phy->dev, "phy poweroff failed --> %d\n", ret); in phy_power_off()
382 mutex_unlock(&phy->mutex); in phy_power_off()
386 --phy->power_count; in phy_power_off()
387 mutex_unlock(&phy->mutex); in phy_power_off()
388 phy_pm_runtime_put(phy); in phy_power_off()
390 if (phy->pwr) in phy_power_off()
391 regulator_disable(phy->pwr); in phy_power_off()
397 int phy_set_mode_ext(struct phy *phy, enum phy_mode mode, int submode) in phy_set_mode_ext() argument
401 if (!phy || !phy->ops->set_mode) in phy_set_mode_ext()
404 mutex_lock(&phy->mutex); in phy_set_mode_ext()
405 ret = phy->ops->set_mode(phy, mode, submode); in phy_set_mode_ext()
407 phy->attrs.mode = mode; in phy_set_mode_ext()
408 mutex_unlock(&phy->mutex); in phy_set_mode_ext()
414 int phy_set_media(struct phy *phy, enum phy_media media) in phy_set_media() argument
418 if (!phy || !phy->ops->set_media) in phy_set_media()
421 mutex_lock(&phy->mutex); in phy_set_media()
422 ret = phy->ops->set_media(phy, media); in phy_set_media()
423 mutex_unlock(&phy->mutex); in phy_set_media()
429 int phy_set_speed(struct phy *phy, int speed) in phy_set_speed() argument
433 if (!phy || !phy->ops->set_speed) in phy_set_speed()
436 mutex_lock(&phy->mutex); in phy_set_speed()
437 ret = phy->ops->set_speed(phy, speed); in phy_set_speed()
438 mutex_unlock(&phy->mutex); in phy_set_speed()
444 int phy_reset(struct phy *phy) in phy_reset() argument
448 if (!phy || !phy->ops->reset) in phy_reset()
451 ret = phy_pm_runtime_get_sync(phy); in phy_reset()
452 if (ret < 0 && ret != -ENOTSUPP) in phy_reset()
455 mutex_lock(&phy->mutex); in phy_reset()
456 ret = phy->ops->reset(phy); in phy_reset()
457 mutex_unlock(&phy->mutex); in phy_reset()
459 phy_pm_runtime_put(phy); in phy_reset()
466 * phy_calibrate() - Tunes the phy hw parameters for current configuration
467 * @phy: the phy returned by phy_get()
469 * Used to calibrate phy hardware, typically by adjusting some parameters in
475 int phy_calibrate(struct phy *phy) in phy_calibrate() argument
479 if (!phy || !phy->ops->calibrate) in phy_calibrate()
482 mutex_lock(&phy->mutex); in phy_calibrate()
483 ret = phy->ops->calibrate(phy); in phy_calibrate()
484 mutex_unlock(&phy->mutex); in phy_calibrate()
491 * phy_configure() - Changes the phy parameters
492 * @phy: the phy returned by phy_get()
495 * Used to change the PHY parameters. phy_init() must have been called
496 * on the phy. The configuration will be applied on the current phy
501 int phy_configure(struct phy *phy, union phy_configure_opts *opts) in phy_configure() argument
505 if (!phy) in phy_configure()
506 return -EINVAL; in phy_configure()
508 if (!phy->ops->configure) in phy_configure()
509 return -EOPNOTSUPP; in phy_configure()
511 mutex_lock(&phy->mutex); in phy_configure()
512 ret = phy->ops->configure(phy, opts); in phy_configure()
513 mutex_unlock(&phy->mutex); in phy_configure()
520 * phy_validate() - Checks the phy parameters
521 * @phy: the phy returned by phy_get()
523 * @submode: PHY submode the configuration is applicable to.
527 * the phy. Implementations are free to tune the parameters passed as
530 * PHY, so calling it as many times as deemed fit will have no side
535 int phy_validate(struct phy *phy, enum phy_mode mode, int submode, in phy_validate() argument
540 if (!phy) in phy_validate()
541 return -EINVAL; in phy_validate()
543 if (!phy->ops->validate) in phy_validate()
544 return -EOPNOTSUPP; in phy_validate()
546 mutex_lock(&phy->mutex); in phy_validate()
547 ret = phy->ops->validate(phy, mode, submode, opts); in phy_validate()
548 mutex_unlock(&phy->mutex); in phy_validate()
555 * _of_phy_get() - lookup and obtain a reference to a phy by phandle
556 * @np: device_node for which to get the phy
557 * @index: the index of the phy
559 * Returns the phy associated with the given phandle value,
560 * after getting a refcount to it or -ENODEV if there is no such phy or
561 * -EPROBE_DEFER if there is a phandle to the phy, but the device is
563 * while registering the phy_provider to find the phy instance.
565 static struct phy *_of_phy_get(struct device_node *np, int index) in _of_phy_get()
569 struct phy *phy = NULL; in _of_phy_get() local
572 ret = of_parse_phandle_with_args(np, "phys", "#phy-cells", in _of_phy_get()
575 return ERR_PTR(-ENODEV); in _of_phy_get()
577 /* This phy type handled by the usb-phy subsystem for now */ in _of_phy_get()
578 if (of_device_is_compatible(args.np, "usb-nop-xceiv")) in _of_phy_get()
579 return ERR_PTR(-ENODEV); in _of_phy_get()
583 if (IS_ERR(phy_provider) || !try_module_get(phy_provider->owner)) { in _of_phy_get()
584 phy = ERR_PTR(-EPROBE_DEFER); in _of_phy_get()
589 dev_warn(phy_provider->dev, "Requested PHY is disabled\n"); in _of_phy_get()
590 phy = ERR_PTR(-ENODEV); in _of_phy_get()
594 phy = phy_provider->of_xlate(phy_provider->dev, &args); in _of_phy_get()
597 module_put(phy_provider->owner); in _of_phy_get()
603 return phy; in _of_phy_get()
607 * of_phy_get() - lookup and obtain a reference to a phy using a device_node.
608 * @np: device_node for which to get the phy
609 * @con_id: name of the phy from device's point of view
611 * Returns the phy driver, after getting a refcount to it; or
612 * -ENODEV if there is no such phy. The caller is responsible for
615 struct phy *of_phy_get(struct device_node *np, const char *con_id) in of_phy_get()
617 struct phy *phy = NULL; in of_phy_get() local
621 index = of_property_match_string(np, "phy-names", con_id); in of_phy_get()
623 phy = _of_phy_get(np, index); in of_phy_get()
624 if (IS_ERR(phy)) in of_phy_get()
625 return phy; in of_phy_get()
627 if (!try_module_get(phy->ops->owner)) in of_phy_get()
628 return ERR_PTR(-EPROBE_DEFER); in of_phy_get()
630 get_device(&phy->dev); in of_phy_get()
632 return phy; in of_phy_get()
637 * of_phy_put() - release the PHY
638 * @phy: the phy returned by of_phy_get()
642 void of_phy_put(struct phy *phy) in of_phy_put() argument
644 if (!phy || IS_ERR(phy)) in of_phy_put()
647 mutex_lock(&phy->mutex); in of_phy_put()
648 if (phy->ops->release) in of_phy_put()
649 phy->ops->release(phy); in of_phy_put()
650 mutex_unlock(&phy->mutex); in of_phy_put()
652 module_put(phy->ops->owner); in of_phy_put()
653 put_device(&phy->dev); in of_phy_put()
658 * phy_put() - release the PHY
659 * @dev: device that wants to release this phy
660 * @phy: the phy returned by phy_get()
664 void phy_put(struct device *dev, struct phy *phy) in phy_put() argument
666 device_link_remove(dev, &phy->dev); in phy_put()
667 of_phy_put(phy); in phy_put()
672 * devm_phy_put() - release the PHY
673 * @dev: device that wants to release this phy
674 * @phy: the phy returned by devm_phy_get()
676 * destroys the devres associated with this phy and invokes phy_put
677 * to release the phy.
679 void devm_phy_put(struct device *dev, struct phy *phy) in devm_phy_put() argument
683 if (!phy) in devm_phy_put()
686 r = devres_destroy(dev, devm_phy_release, devm_phy_match, phy); in devm_phy_put()
687 dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n"); in devm_phy_put()
692 * of_phy_simple_xlate() - returns the phy instance from phy provider
693 * @dev: the PHY provider device
696 * Intended to be used by phy provider for the common case where #phy-cells is
697 * 0. For other cases where #phy-cells is greater than '0', the phy provider
699 * the appropriate phy.
701 struct phy *of_phy_simple_xlate(struct device *dev, struct of_phandle_args in of_phy_simple_xlate()
704 struct phy *phy; in of_phy_simple_xlate() local
709 phy = to_phy(dev); in of_phy_simple_xlate()
710 if (args->np != phy->dev.of_node) in of_phy_simple_xlate()
714 return phy; in of_phy_simple_xlate()
718 return ERR_PTR(-ENODEV); in of_phy_simple_xlate()
723 * phy_get() - lookup and obtain a reference to a phy.
724 * @dev: device that requests this phy
725 * @string: the phy name as given in the dt data or the name of the controller
726 * port for non-dt case
728 * Returns the phy driver, after getting a refcount to it; or
729 * -ENODEV if there is no such phy. The caller is responsible for
732 struct phy *phy_get(struct device *dev, const char *string) in phy_get()
735 struct phy *phy; in phy_get() local
738 if (dev->of_node) { in phy_get()
740 index = of_property_match_string(dev->of_node, "phy-names", in phy_get()
744 phy = _of_phy_get(dev->of_node, index); in phy_get()
748 return ERR_PTR(-EINVAL); in phy_get()
750 phy = phy_find(dev, string); in phy_get()
752 if (IS_ERR(phy)) in phy_get()
753 return phy; in phy_get()
755 if (!try_module_get(phy->ops->owner)) in phy_get()
756 return ERR_PTR(-EPROBE_DEFER); in phy_get()
758 get_device(&phy->dev); in phy_get()
760 link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS); in phy_get()
763 dev_name(phy->dev.parent)); in phy_get()
765 return phy; in phy_get()
770 * phy_optional_get() - lookup and obtain a reference to an optional phy.
771 * @dev: device that requests this phy
772 * @string: the phy name as given in the dt data or the name of the controller
773 * port for non-dt case
775 * Returns the phy driver, after getting a refcount to it; or
776 * NULL if there is no such phy. The caller is responsible for
779 struct phy *phy_optional_get(struct device *dev, const char *string) in phy_optional_get()
781 struct phy *phy = phy_get(dev, string); in phy_optional_get() local
783 if (PTR_ERR(phy) == -ENODEV) in phy_optional_get()
784 phy = NULL; in phy_optional_get()
786 return phy; in phy_optional_get()
791 * devm_phy_get() - lookup and obtain a reference to a phy.
792 * @dev: device that requests this phy
793 * @string: the phy name as given in the dt data or phy device name
794 * for non-dt case
796 * Gets the phy using phy_get(), and associates a device with it using
800 struct phy *devm_phy_get(struct device *dev, const char *string) in devm_phy_get()
802 struct phy **ptr, *phy; in devm_phy_get() local
806 return ERR_PTR(-ENOMEM); in devm_phy_get()
808 phy = phy_get(dev, string); in devm_phy_get()
809 if (!IS_ERR(phy)) { in devm_phy_get()
810 *ptr = phy; in devm_phy_get()
816 return phy; in devm_phy_get()
821 * devm_phy_optional_get() - lookup and obtain a reference to an optional phy.
822 * @dev: device that requests this phy
823 * @string: the phy name as given in the dt data or phy device name
824 * for non-dt case
826 * Gets the phy using phy_get(), and associates a device with it using
829 * that if the phy does not exist, it is not considered an error and
830 * -ENODEV will not be returned. Instead the NULL phy is returned,
831 * which can be passed to all other phy consumer calls.
833 struct phy *devm_phy_optional_get(struct device *dev, const char *string) in devm_phy_optional_get()
835 struct phy *phy = devm_phy_get(dev, string); in devm_phy_optional_get() local
837 if (PTR_ERR(phy) == -ENODEV) in devm_phy_optional_get()
838 phy = NULL; in devm_phy_optional_get()
840 return phy; in devm_phy_optional_get()
845 * devm_of_phy_get() - lookup and obtain a reference to a phy.
846 * @dev: device that requests this phy
847 * @np: node containing the phy
848 * @con_id: name of the phy from device's point of view
850 * Gets the phy using of_phy_get(), and associates a device with it using
854 struct phy *devm_of_phy_get(struct device *dev, struct device_node *np, in devm_of_phy_get()
857 struct phy **ptr, *phy; in devm_of_phy_get() local
862 return ERR_PTR(-ENOMEM); in devm_of_phy_get()
864 phy = of_phy_get(np, con_id); in devm_of_phy_get()
865 if (!IS_ERR(phy)) { in devm_of_phy_get()
866 *ptr = phy; in devm_of_phy_get()
870 return phy; in devm_of_phy_get()
873 link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS); in devm_of_phy_get()
876 dev_name(phy->dev.parent)); in devm_of_phy_get()
878 return phy; in devm_of_phy_get()
883 * devm_of_phy_get_by_index() - lookup and obtain a reference to a phy by index.
884 * @dev: device that requests this phy
885 * @np: node containing the phy
886 * @index: index of the phy
888 * Gets the phy using _of_phy_get(), then gets a refcount to it,
894 struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, in devm_of_phy_get_by_index()
897 struct phy **ptr, *phy; in devm_of_phy_get_by_index() local
902 return ERR_PTR(-ENOMEM); in devm_of_phy_get_by_index()
904 phy = _of_phy_get(np, index); in devm_of_phy_get_by_index()
905 if (IS_ERR(phy)) { in devm_of_phy_get_by_index()
907 return phy; in devm_of_phy_get_by_index()
910 if (!try_module_get(phy->ops->owner)) { in devm_of_phy_get_by_index()
912 return ERR_PTR(-EPROBE_DEFER); in devm_of_phy_get_by_index()
915 get_device(&phy->dev); in devm_of_phy_get_by_index()
917 *ptr = phy; in devm_of_phy_get_by_index()
920 link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS); in devm_of_phy_get_by_index()
923 dev_name(phy->dev.parent)); in devm_of_phy_get_by_index()
925 return phy; in devm_of_phy_get_by_index()
930 * phy_create() - create a new phy
931 * @dev: device that is creating the new phy
932 * @node: device node of the phy
933 * @ops: function pointers for performing phy operations
935 * Called to create a phy using phy framework.
937 struct phy *phy_create(struct device *dev, struct device_node *node, in phy_create()
942 struct phy *phy; in phy_create() local
945 return ERR_PTR(-EINVAL); in phy_create()
947 phy = kzalloc(sizeof(*phy), GFP_KERNEL); in phy_create()
948 if (!phy) in phy_create()
949 return ERR_PTR(-ENOMEM); in phy_create()
958 device_initialize(&phy->dev); in phy_create()
959 mutex_init(&phy->mutex); in phy_create()
961 phy->dev.class = phy_class; in phy_create()
962 phy->dev.parent = dev; in phy_create()
963 phy->dev.of_node = node ?: dev->of_node; in phy_create()
964 phy->id = id; in phy_create()
965 phy->ops = ops; in phy_create()
967 ret = dev_set_name(&phy->dev, "phy-%s.%d", dev_name(dev), id); in phy_create()
971 /* phy-supply */ in phy_create()
972 phy->pwr = regulator_get_optional(&phy->dev, "phy"); in phy_create()
973 if (IS_ERR(phy->pwr)) { in phy_create()
974 ret = PTR_ERR(phy->pwr); in phy_create()
975 if (ret == -EPROBE_DEFER) in phy_create()
978 phy->pwr = NULL; in phy_create()
981 ret = device_add(&phy->dev); in phy_create()
986 pm_runtime_enable(&phy->dev); in phy_create()
987 pm_runtime_no_callbacks(&phy->dev); in phy_create()
990 return phy; in phy_create()
993 put_device(&phy->dev); /* calls phy_release() which frees resources */ in phy_create()
997 kfree(phy); in phy_create()
1003 * devm_phy_create() - create a new phy
1004 * @dev: device that is creating the new phy
1005 * @node: device node of the phy
1006 * @ops: function pointers for performing phy operations
1008 * Creates a new PHY device adding it to the PHY class.
1009 * While at that, it also associates the device with the phy using devres.
1013 struct phy *devm_phy_create(struct device *dev, struct device_node *node, in devm_phy_create()
1016 struct phy **ptr, *phy; in devm_phy_create() local
1020 return ERR_PTR(-ENOMEM); in devm_phy_create()
1022 phy = phy_create(dev, node, ops); in devm_phy_create()
1023 if (!IS_ERR(phy)) { in devm_phy_create()
1024 *ptr = phy; in devm_phy_create()
1030 return phy; in devm_phy_create()
1035 * phy_destroy() - destroy the phy
1036 * @phy: the phy to be destroyed
1038 * Called to destroy the phy.
1040 void phy_destroy(struct phy *phy) in phy_destroy() argument
1042 pm_runtime_disable(&phy->dev); in phy_destroy()
1043 device_unregister(&phy->dev); in phy_destroy()
1048 * devm_phy_destroy() - destroy the PHY
1049 * @dev: device that wants to release this phy
1050 * @phy: the phy returned by devm_phy_get()
1052 * destroys the devres associated with this phy and invokes phy_destroy
1053 * to destroy the phy.
1055 void devm_phy_destroy(struct device *dev, struct phy *phy) in devm_phy_destroy() argument
1059 r = devres_destroy(dev, devm_phy_consume, devm_phy_match, phy); in devm_phy_destroy()
1060 dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n"); in devm_phy_destroy()
1065 * __of_phy_provider_register() - create/register phy provider with the framework
1066 * @dev: struct device of the phy provider
1067 * @children: device node containing children (if different from dev->of_node)
1069 * @of_xlate: function pointer to obtain phy instance from phy provider
1072 * This is used in the case of dt boot for finding the phy instance from
1073 * phy provider.
1075 * If the PHY provider doesn't nest children directly but uses a separate
1077 * can be used to override the default. If NULL, the default (dev->of_node)
1078 * will be used. If non-NULL, the device node must be a child (or further
1079 * descendant) of dev->of_node. Otherwise an ERR_PTR()-encoded -EINVAL
1084 struct phy * (*of_xlate)(struct device *dev, in __of_phy_provider_register()
1098 if (parent == dev->of_node) in __of_phy_provider_register()
1107 return ERR_PTR(-EINVAL); in __of_phy_provider_register()
1111 children = dev->of_node; in __of_phy_provider_register()
1116 return ERR_PTR(-ENOMEM); in __of_phy_provider_register()
1118 phy_provider->dev = dev; in __of_phy_provider_register()
1119 phy_provider->children = of_node_get(children); in __of_phy_provider_register()
1120 phy_provider->owner = owner; in __of_phy_provider_register()
1121 phy_provider->of_xlate = of_xlate; in __of_phy_provider_register()
1124 list_add_tail(&phy_provider->list, &phy_provider_list); in __of_phy_provider_register()
1132 * __devm_of_phy_provider_register() - create/register phy provider with the
1134 * @dev: struct device of the phy provider
1135 * @children: device node containing children (if different from dev->of_node)
1137 * @of_xlate: function pointer to obtain phy instance from phy provider
1140 * This is used in the case of dt boot for finding the phy instance from
1141 * phy provider. While at that, it also associates the device with the
1142 * phy provider using devres. On driver detach, release function is invoked
1147 struct phy * (*of_xlate)(struct device *dev, in __devm_of_phy_provider_register()
1154 return ERR_PTR(-ENOMEM); in __devm_of_phy_provider_register()
1170 * of_phy_provider_unregister() - unregister phy provider from the framework
1171 * @phy_provider: phy provider returned by of_phy_provider_register()
1181 list_del(&phy_provider->list); in of_phy_provider_unregister()
1182 of_node_put(phy_provider->children); in of_phy_provider_unregister()
1189 * devm_of_phy_provider_unregister() - remove phy provider from the framework
1190 * @dev: struct device of the phy provider
1191 * @phy_provider: phy provider returned by of_phy_provider_register()
1193 * destroys the devres associated with this phy provider and invokes
1194 * of_phy_provider_unregister to unregister the phy provider.
1203 dev_WARN_ONCE(dev, r, "couldn't find PHY provider device resource\n"); in devm_of_phy_provider_unregister()
1208 * phy_release() - release the phy
1209 * @dev: the dev member within phy
1216 struct phy *phy; in phy_release() local
1218 phy = to_phy(dev); in phy_release()
1220 regulator_put(phy->pwr); in phy_release()
1221 ida_simple_remove(&phy_ida, phy->id); in phy_release()
1222 kfree(phy); in phy_release()
1227 phy_class = class_create(THIS_MODULE, "phy"); in phy_core_init()
1229 pr_err("failed to create phy class --> %ld\n", in phy_core_init()
1234 phy_class->dev_release = phy_release; in phy_core_init()